Can't figure out how to work with all these "wide unicode strings". Can anyone tell me what am i doing wrong? I Just want to get all local user groups, so i do:
LPBYTE buffer;
DWORD entries, total_entries;
NetUserGetLocalGroups(NULL, L"rovnyart", 0, LG_INCLUDE_INDIRECT, &buffer, MAX_PREFERRED_SIZE, &entries, &total_entries);
LOCALGROUP_USERS_INFO_0 *groups = (LOCALGROUP_USERS_INFO_0 *) buffer;
unsigned int i;
for (i=0; i<entries;i++)
wprintf(L"%s\n", groups[i].lgrui0_name);
And this is what i get:
t
╝4╝<╝8╝=╝8╝A╝B╝@╝0╝B╝>╝@╝K╝
╝>╝;╝L╝7╝>╝2╝0╝B╝5╝;╝8╝
Process finished with exit code 0
My windows language is Russian, but i created one group called "testgroup1", and as you can see it doesn't display correct too.
i tried wprintf()
- result was the same :(
What am i doing wrong?
UPD:
Ok, I changed the code to fit your advices. I created a group called "test" which is non-cyrillic and put my user there.
Here's my code:
LPBYTE pBuf = NULL;
NET_API_STATUS nStatus;
DWORD entries, total_entries;
nStatus = NetUserGetLocalGroups(NULL, L"rovnyart", 0, LG_INCLUDE_INDIRECT, &pBuf, MAX_PREFERRED_LENGTH, &entries, &total_entries);
LOCALGROUP_USERS_INFO_0 *groups = (LOCALGROUP_USERS_INFO_0 *) pBuf;
if (nStatus == 0) {
unsigned int i;
for (i = 0; i < entries; i++)
wprintf(L"%s\n", groups[i].lgrui0_name);
NetApiBufferFree(pBuf);
}
Here is the output:
t
╝4╝<╝8╝=╝8╝A╝B╝@╝0╝B╝>╝@╝K╝
╝>╝;╝L╝7╝>╝2╝0╝B╝5╝;╝8╝
Process finished with exit code 0