Windows API一日一练(71)GetComputerName函数
来源:互联网 发布:女巫是真的么 知乎 编辑:程序博客网 时间:2024/05/16 14:09
当你在一个大公司里面,当一个网络管理员时,发现成千上万个电脑需要你去管理时,怎么去区分这些电脑呢?那肯定是通过计算机的名称。而这个网络管理员又需要你开发一套软件,它可以把所有电脑的名称自动地上报给他。面对这样的需求,就可以使用下面的函数GetComputerName来获取计算机的名称,并通过网络传送给管理员。
函数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
);
#ifdef UNICODE
#define GetComputerName GetComputerNameW
#else
#define GetComputerName GetComputerNameA
#endif // !UNICODE
lpBuffer是获取电脑名称的缓冲区。
nSize是输入缓冲区的大小和输出电脑名称的大小。
调用函数的例子如下:
#001 //
#002 //获取当前计算机的名称。
#003 //蔡军生 2007/11/12 QQ:9073204 深圳
#004 void GetPCName(void)
#005 {
#006 //
#007 const int nBufSize = MAX_COMPUTERNAME_LENGTH + 1;
#008 TCHAR chBuf[nBufSize];
#009 ZeroMemory(chBuf,nBufSize);
#010
#011 //获取当前计算机的名称
#012 DWORD dwRet = nBufSize;
#013 if (GetComputerName(chBuf,&dwRet))
#014 {
#015 //
#016 OutputDebugString(chBuf);
#017 }
#018 else
#019 {
#020 OutputDebugString(_T("获取计算名称出错!"));
#021 }
#022
#023 OutputDebugString(_T("/r/n"));
#024
#025 }
#026
#027
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(71)GetComputerName函数
- 出差见闻(二)--温州的房价:250000
- 使用hxcomp.exe反编译MSDN文档
- Windows API一日一练(74)GetSystemInfo函数
- Windows API一日一练(73)GetVersionEx函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(71)GetComputerName函数
- 出差见闻(一)--温州的出租车:起步价15元
- 关于DRM打包时的错误
- Windows API一日一练(70)GetSystemTime和GetLocalTime函数
- 信息化故事--温州的传奇(11)从“进城务工”看“温州新版自闭症”
- Windows API一日一练(69)GetTickCount函数
- FreeBSD查看即时网络流量
- Windows API一日一练(68)QueryPerformanceCounter函数
- ERP系统应用的“打江山与坐江山”