C与DELPHI的一点小转换(20分)

  • 主题发起人 主题发起人 3h
  • 开始时间 开始时间
3

3h

Unregistered / Unconfirmed
GUEST, unregistred user!
我对以下函数:<br>DWORD GetFullPathName(<br>&nbsp; &nbsp; LPCTSTR lpFileName, // address of name of file to find path for <br>&nbsp; &nbsp; DWORD nBufferLength, // size, in characters, of path buffer <br>&nbsp; &nbsp; LPTSTR lpBuffer, // address of path buffer <br>&nbsp; &nbsp; LPTSTR *lpFilePart // address of filename in path <br>&nbsp; &nbsp;); <br>最后一个参数在DELPHI中的定义不明白,请大家给我解释则个。
 
LPTSTR-&gt;Pointer
 
定义一个变量:<br>PP : Pointer<br>放在最后那里不行。看以下:<br>Var<br>&nbsp; &nbsp;FN,BU : String;<br>&nbsp; &nbsp;J : Integer;<br>&nbsp; &nbsp;PP : Pointer;<br>...<br>&nbsp; &nbsp;J := 0;<br>&nbsp; &nbsp;J := GetFullName(PChar(FN), J, PChar(BU), PP); &nbsp; // **<br>...<br>还是有类型不兼容的错误。
 
LPTSTR is PChar;
 
PCHAR类型的变量放进去也不行的。
 
Perhaps the param is a pointer to PChar?<br>But PChar itself is a pointer...<br>Willy nilly...
 
我编了一段程序,运行通过了,返回码也对,但不知结果是否是你期望的。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; i: Integer;<br>&nbsp; s: PChar;<br>&nbsp; Buffer: Array[1..128] of Char;<br>begin<br>&nbsp; i := GetFullPathName('delphi32.exe', sizeof(Buffer), @Buffer, s);<br>&nbsp; Label1.Caption := s;<br>&nbsp; Label2.Caption := IntToStr(i);<br>end;<br><br>在Label1.Caption := s;处设置断点,可看到Buffer的值。<br>
 
另外,还可以:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; i: Integer;<br>&nbsp; s1, s2: PChar;<br>begin<br>&nbsp; new(s1); &nbsp;// 必须<br>&nbsp; new(s2); &nbsp;// 可以不要<br>&nbsp; i := GetFullPathName('delphi32.exe', 128, s1, s2);<br>&nbsp; Label1.Caption := s1;<br>&nbsp; Label2.Caption := IntToStr(i);<br>end;<br>
 
GetFullPathName在delphi中重写了的<br>查看单元shellapi
 
&nbsp; LPTSTR *lpFilePart &nbsp;// address of filename in path <br>lpFilePart应为AscIIZ串,用PChar来存储,用该指针来引用。
 
原来是PCHAR!:)<br>多谢大家!
 
后退
顶部