GetComputerName声明如下:
WINBASEAPI
BOOL
WINAPI
GetComputerNameA (
__out_ecount_part(*nSize, *nSize + 1) LPSTR lpBuffer,
__inout LPDWORD nSize
);
WINBASEAPI
BOOL
WINAPI
GetComputerNameW (
__out_ecount_part(*nSize, *nSize + 1) LPWSTR lpBuffer,
__inout LPDWORD nSize
);
#def UNICODE
# GetComputerName GetComputerNameW
#
# GetComputerName GetComputerNameA
#end // !UNICODE
lpBuffer是获取电脑名称缓冲区
nSize是输入缓冲区大小和输出电脑名称大小
例子如下:
#001 //
#002 //获取当前计算机名称
#003 //蔡军生 2007/11/12 QQ:9073204 深圳
#004 void GetPCName(void)
#005 {
#006 //
#007 const nBufSize = MAX_COMPUTERNAME_LENGTH + 1;
#008 TCHAR chBuf[nBufSize];
#009 ZeroMemory(chBuf,nBufSize);
#010
#011 //获取当前计算机名称
#012 DWORD dwRet = nBufSize;
#013 (GetComputerName(chBuf,&dwRet))
#014 {
#015 //
#016 OutputDebugString(chBuf);
#017 }
#018
#019 {
#020 OutputDebugString(_T("获取计算名称出错!"));
#021 }
#022
#023 OutputDebugString(_T("\r\n"));
#024
#025 }
#026
#027
最新评论