C++ GetUserName()

关于函数“GetUserName()”,参见:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx

IDE: Code::Blocks

操作系统:Windows 7 x64

 1 #include <windows.h>
 2 #include <stdio.h>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     CHAR cUserNameBuffer[256];
 9     DWORD dwUserNameSize = 256;
10 
11     /* Retrieves the name of the user associated with the current thread. */
12     if(GetUserName(cUserNameBuffer, &dwUserNameSize)) {
13         printf("The user name is %s 
", cUserNameBuffer);
14     }
15     else {
16         printf("Get user name failed with error: %lu 
", GetLastError());
17     }
18 
19     return 0;
20 }
原文地址:https://www.cnblogs.com/Satu/p/8182948.html