GetComputerName和GetUserName获取不到正确的数据,调试后发现修改成如下即可
#include <stdio.h>
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf(" VC++得到计算机名称和用户名称 \n");
const int nBufSize = MAX_COMPUTERNAME_LENGTH + 1;
TCHAR chBuf[nBufSize];
ZeroMemory(chBuf,nBufSize);
DWORD dwRet = nBufSize;
if (GetComputerNameA((LPSTR)chBuf,&dwRet))
{
printf("计算机名字: %s\n", chBuf);
}
dwRet = nBufSize;
if (GetUserNameA((LPSTR)chBuf, &dwRet))
{
printf("当前用户: %s \n", chBuf);
}
return 0;
}
本文解决使用C++获取计算机名称和用户名称时遇到的问题,通过修改代码实现正确获取。
432

被折叠的 条评论
为什么被折叠?



