Windows API一日一练(71)GetComputerName函数
来源:互联网 发布:2g网络定位有误差吗 编辑:程序博客网 时间:2024/05/22 00:20
当你在一个大公司里面,当一个网络管理员时,发现成千上万个电脑需要你去管理时,怎么去区分这些电脑呢?那肯定是通过计算机的名称。而这个网络管理员又需要你开发一套软件,它可以把所有电脑的名称自动地上报给他。面对这样的需求,就可以使用下面的函数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函数
- 书评--提升软件质量的必经之路
- 再谈Delphi vs VC++(非常精彩)
- 看一个比较各种语言的帖子的一点看法
- 书评 -- Microsoft SQL Server 2005 Integration Services
- 从诚恳出发,迈向自我实现
- Windows API一日一练(71)GetComputerName函数
- DataTable,DataView和DataGrid中一些容易混淆的概念
- (五)Java游戏部署在Windows Mobile平台仿真器(Microsoft)
- 微软收购网络广告公司aQuantive(转)
- 书评 -- Professional SQL Server 2005 Reporting Services
- 如何实现Asp与Asp.Net共享Session
- (四)Java游戏部署在BlackBerry仿真器上(RIM)
- xmlhttp存在最大并发数,ajax设计应有所斟酌[zz]
- 胡百敬老师谈SQL Server 2005