Windows API一日一练(71)GetComputerName函数
来源:互联网 发布:mysql如何清空数据库 编辑:程序博客网 时间:2024/05/21 18:54
当你在一个大公司里面,当一个网络管理员时,发现成千上万个电脑需要你去管理时,怎么去区分这些电脑呢?那肯定是通过计算机的名称。而这个网络管理员又需要你开发一套软件,它可以把所有电脑的名称自动地上报给他。面对这样的需求,就可以使用下面的函数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函数
- 观察:硅谷小公司挑战Google将成唐吉诃德
- Developing ASP.NET Custom Control With C# Builder铪
- Windows API一日一练(72)GetUserName函数
- 修復VS.NET 2005
- 10位表现最差企业家
- Windows API一日一练(71)GetComputerName函数
- .NET Framework Security Code Access Security-應用程式篇
- LINQ
- 软件设计模式的非软件例子(一)
- 质量管理新理念——以员工为中心
- Windows API一日一练(70)GetSystemTime和GetLocalTime函数
- Windows API一日一练(69)GetTickCount函数
- 第30回 总结
- Windows API一日一练(68)QueryPerformanceCounter函数