Hello,
I tried the code as follows:
Code:
#include <windows.h>
#include <stdio.h>
#include <Lmcons.h>
#include <string>
#include <iostream>
int main()
{
char username[UNLEN +1];
DWORD username_len = UNLEN + 1;
GetUserName((LPWSTR)username, &username_len);
for each(auto test in username)
{
cout << test ;
}
}
Which shows me that I indeed have chars inside username.
Now I try to do the following as described here on the answer also but it doesn't work.
The problem by the compiler is on that line and specifically on variable username:
Code:
GetUserName(username, &username_len);
Error says: Argument of type "Char*" is incompatible with parameter of type LPWSTR.
So I change my code to this:
Code:
char username[UNLEN + 1];
DWORD username_len = UNLEN + 1;
GetUserName((LPWSTR)username, &username_len);
And when I print it, I only get the first letter. Why?
Thanks in advance!