程式碼:
#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