Skip to content

Get PC username and PC name #377

Answered by timsneath
AppetiteTeam asked this question in Q&A
Discussion options

You must be logged in to vote

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 like Uint16 (which represents 2 bytes of storage, enough for a single Unicode character) and then cast it to a Utf16. And of course, you need enough of them for your buffer (use the optional parameter). For example:

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:
https://github.com/timsneath…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AppetiteTeam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #376 on March 19, 2022 02:28.