Get PC username and PC name #377
-
I don't understand how to get username and PC name. Tried like this:
VS Code shows that there are no errors, but when compiling it gives this:: Error: Expected type 'Utf16' to be a valid and instantiated subtype of 'NativeType'.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's correct. final buffer = calloc<Uint16>(256).cast<Utf16>(); To make it easier, win32 offers a helper method that takes care of these details for you: final buffer = wsalloc(256); Saving you a lot of trouble, this example shows how to get the username and machine name: |
Beta Was this translation helpful? Give feedback.
That's correct.
Utf16
is not a type that can be allocated (it's an opaque type that exists primarily to enable extension methods to convert back to a string). Instead you allocate a native type likeUint16
(which represents 2 bytes of storage, enough for a single Unicode character) and then cast it to aUtf16
. And of course, you need enough of them for your buffer (use the optional parameter). For example:To make it easier, win32 offers a helper method that takes care of these details for you:
Saving you a lot of trouble, this example shows how to get the username and machine name:
https://github.com/timsneath…