VC获取本机计算机名

来源:互联网 发布:快递不送货上门 知乎 编辑:程序博客网 时间:2024/05/01 03:35

#include "stdafx.h"
#include "windows.h"
#include "string"

using namespace std;


     wstring myComputerName(   )
{
   TCHAR szHostName[200];
   DWORD dwSize   =   200;
   GetComputerName(   szHostName,   &dwSize   );
   return wstring( szHostName);
}
int _tmain(int argc, _TCHAR* argv[])
{

setlocale(LC_ALL ,"chs");
    wstring w = myComputerName();
wprintf( L"%s/n", w.c_str());
getchar();

return 0;
}