有獲取計算機名的過程﹐但不知道它是具體怎么實現的﹗高手幫我解釋一下吧﹗(10分)

  • 主题发起人 主题发起人 胡圖崇
  • 开始时间 开始时间

胡圖崇

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; var CnameBuffer:PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp;fl_loaded:Boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp;Clen:Dword;<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;GetMem(CnameBuffer,255);<br>&nbsp; &nbsp; &nbsp;Clen:=255;<br>&nbsp; &nbsp; &nbsp;fl_loaded:=GetComputerName(CnameBuffer,Clen);<br>&nbsp; &nbsp;end;<br>這几行代碼﹕<br>&nbsp; &nbsp; &nbsp;GetMem(CnameBuffer,255);<br>&nbsp; &nbsp; &nbsp;Clen:=255;<br>&nbsp; &nbsp; &nbsp;fl_loaded:=GetComputerName(CnameBuffer,Clen);<br>是怎么實現獲取計算機名的呢﹖<br>這個GetMem是分配內存地址吧﹖而這個GetComputerName是個windows API函數不知道它的用法是怎么樣的﹖<br>
 
&nbsp;<br>&nbsp; Platform SDK: Windows System Information <br>GetComputerName<br>The GetComputerName function retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry. <br><br>If the local computer is a node in a cluster, GetComputerName returns the name of the node. <br><br>Windows 2000: GetComputerName retrieves only the NetBIOS name of the local computer. To retrieve the DNS host name, DNS domain name, or the fully qualified DNS name, call the GetComputerNameEx function.<br><br>Windows 2000: Additional information is provided by the IADsADSystemInfo interface. <br><br>BOOL GetComputerName(<br>&nbsp; LPTSTR lpBuffer, &nbsp;// computer name<br>&nbsp; LPDWORD lpnSize &nbsp; // size of name buffer<br>);<br>Parameters<br>lpBuffer <br>[out] Pointer to a buffer that receives a null-terminated string containing the computer name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters. <br>lpnSize <br>[in/out] On input, specifies the size, in TCHARs, of the buffer. On output, receives the number of TCHARs copied to the destination buffer, not including the terminating null character. <br>If the buffer is too small, the function fails and GetLastError returns ERROR_BUFFER_OVERFLOW. <br><br>Windows 95/98: GetComputerName fails if the input size is less than MAX_COMPUTERNAME_LENGTH + 1. <br><br>Return Values<br>If the function succeeds, the return value is a nonzero value. <br><br>If the function fails, the return value is zero. To get extended error information, call GetLastError. <br><br>Remarks<br>The GetComputerName function retrieves the NetBIOS name established at system startup. Name changes made by the SetComputerName or SetComputerNameEx functions do not take effect until the user restarts the computer.<br><br>Requirements <br>&nbsp; Windows NT/2000: Requires Windows NT 3.1 or later.<br>&nbsp; Windows 95/98: Requires Windows 95 or later.<br>&nbsp; Header: Declared in Winbase.h; include Windows.h.<br>&nbsp; Library: Use Kernel32.lib.<br>&nbsp; Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.<br><br>See Also<br>System Information Overview, System Information Functions, GetComputerNameEx, SetComputerName, SetComputerNameEx <br><br>Built on Thursday, May 11, 2000Requirements <br>&nbsp; Windows NT/2000: Requires Windows NT 3.1 or later.<br>&nbsp; Windows 95/98: Requires Windows 95 or later.<br>&nbsp; Header: Declared in Winbase.h; include Windows.h.<br>&nbsp; Library: Use Kernel32.lib.<br>&nbsp; Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.<br>See Also<br>System Information Overview, System Information Functions, GetComputerNameEx, SetComputerName, SetComputerNameEx <br>1.CnameBuffer就是計算機名稱保存的地址。<br>2.是的。是的,第一個參數是計算機名稱將要保存地址,第二個是字符長度。
 
哦﹐知道了﹐TKS!
 
后退
顶部