如何使用getlogicaldrivestrings函数?(50分)

  • 主题发起人 主题发起人 xuxincheng
  • 开始时间 开始时间
X

xuxincheng

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>buffer:pchar;<br>begin<br>getlogicaldrivestrings(sizeof(buffer),buffer);<br>label1.caption:=strpas(buffer);<br>end;<br><br>这段代码工作不正常,错在哪儿?
 
GetLogicalDriveStrings<br>The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system. <br><br>DWORD GetLogicalDriveStrings(<br>&nbsp; DWORD nBufferLength, &nbsp;// size of buffer<br>&nbsp; LPTSTR lpBuffer &nbsp; &nbsp; &nbsp; // drive strings buffer<br>);<br>Parameters<br>nBufferLength <br>[in] Specifies the maximum size, in characters, of the buffer pointed to by lpBuffer. This size does not include the terminating null character. <br>lpBuffer <br>[out] Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with &lt;null&gt; representing the terminating null character. <br>c:/&lt;null&gt;d:/&lt;null&gt;&lt;null&gt; <br>Return Values<br>If the function succeeds, the return value is the length, in characters, of the strings copied to the buffer, not including the terminating null character. Note that an ANSI-ASCII null character uses one byte, but a Unicode null character uses two bytes. <br><br>If the buffer is not large enough, the return value is greater than nBufferLength. It is the size of the buffer required to hold the drive strings. <br><br>If the function fails, the return value is zero. To get extended error information, use the GetLastError function. <br><br>Remarks<br>Each string in the buffer may be used wherever a root directory is required, such as for the GetDriveType and GetDiskFreeSpace functions. <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>File I/O Overview, File I/O Functions, GetDriveType, GetDiskFreeSpace, GetLogicalDrives <br><br>Built on Wednesday, July 19, 2000
 
GetLogicalDriveStrings是干什么用的自己要先弄清楚。<br>然后在搞清楚返回值和参数的约定。<br><br>下面是一个测试代码:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; nsize,i : integer;<br>&nbsp; szDrive : pchar;<br>&nbsp; DriveList : array of string;<br>&nbsp; strTemp : string;<br>&nbsp; IsNull : boolean;<br>begin<br>&nbsp; nsize := MAX_PATH;<br>&nbsp; GetMem(szDrive,nsize);<br>&nbsp; nSize := GetLogicalDriveStrings(nsize,szDrive);<br>&nbsp; isNull := True;<br>&nbsp; strTemp := '';<br>&nbsp; for i := 1 to nSize do<br>&nbsp; begin<br>&nbsp; &nbsp; if isNull then<br>&nbsp; &nbsp; &nbsp; setlength(DriveList,length(DriveList)+1);<br>&nbsp; &nbsp; if szDrive[i-1]&lt;&gt;#0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; strTemp := strTemp + szDrive[i-1];<br>&nbsp; &nbsp; &nbsp; IsNull := False;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; DriveList[high(DriveList)] := strTemp;<br>&nbsp; &nbsp; &nbsp; strTemp := '';<br>&nbsp; &nbsp; &nbsp; IsNull := True;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; // show drive list in a listbox <br>&nbsp; for i := low(DriveList) to high(DriveList) do<br>&nbsp; &nbsp; Listbox1.Items.Add(DriveList);<br>end;
 
感谢热心的 lyywy。<br>接受答案了。
 

Similar threads

I
回复
0
查看
484
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部