2015/06/04

C++ get DNS name of computer



程式碼:
#include "stdafx.h"
#include <atlstr.h>
#include <WinBase.h>

#pragma comment(lib, "Kernel32.lib")


int _tmain(int argc, _TCHAR* argv[])
{

 TCHAR dnsName[256] = TEXT("");
 DWORD dnsSize = sizeof(dnsName);
 GetComputerNameEx(ComputerNameDnsDomain, dnsName, &dnsSize);

 _tprintf(TEXT("%s\n"), dnsName);


 ZeroMemory(dnsName, dnsSize);
 system("pause");
 return 0;
}

執行結果:

參考資料:
https://msdn.microsoft.com/zh-tw/library/windows/desktop/ms724301%28v=vs.85%29.aspx

沒有留言:

張貼留言