C++ GetComputerName()
关于函数“GetComputerName()”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx
关于“Computer Names”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724220(v=vs.85).aspx
代码摘自“Getting System Information”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724426(v=vs.85).aspx
关于“Windows Data Types”,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
IDE: Code::Blocks
操作系统:Windows 7 x64
1 #include <stdio.h> 2 #include <tchar.h> 3 #include <windows.h> 4 5 #define INFO_BUFFER_SIZE (MAX_COMPUTERNAME_LENGTH + 1) 6 7 int main() 8 { 9 CHAR infoBuf[INFO_BUFFER_SIZE]; 10 DWORD bufCharCount = INFO_BUFFER_SIZE; 11 12 // Get and display the name of the computer. 13 if( GetComputerName( infoBuf, &bufCharCount ) ) { 14 _tprintf( "The NetBIOS name of the local computer is %s \n", infoBuf ); 15 } 16 else { 17 _tprintf( "Get NetBIOS name of the local computer failed with error %lu \n", GetLastError() ); 18 } 19 20 return 0; 21 }