Windows API一日一练(71)GetComputerName函数
来源:互联网 发布:mac安装vmware fusion 编辑:程序博客网 时间:2024/05/22 01:50
当你在一个大公司里面,当一个网络管理员时,发现成千上万个电脑需要你去管理时,怎么去区分这些电脑呢?那肯定是通过计算机的名称。而这个网络管理员又需要你开发一套软件,它可以把所有电脑的名称自动地上报给他。面对这样的需求,就可以使用下面的函数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函数
- Windows API一日一练(72)GetUserName函数
- Windows API一日一练(76)GlobalAlloc函数
- 从历史学习的 8 堂架构课
- 经典手机短信笑话
- (四)Java游戏部署在BlackBerry仿真器上(RIM)
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(75)SystemParametersInfo函数
- .Net Remoting中Remote Server的Port占用/释放问题
- (三)Java游戏部署在Symbian平台仿真器上(Nokia)
- 多核编程中的锁竞争难题
- Windows API一日一练(70)GetSystemTime和GetLocalTime函数
- Windows API一日一练(74)GetSystemInfo函数
- Guru of the Week 条款21:代码的复杂性(第二部分)
- (二)Java游戏部署在Linux平台仿真器上(Motorola)