楼上,我这样返回,不行(太菜了,没用过指针):<br> function MXX_ComputerName
ointer;stdcall;external DLL;<br>implementation<br>{$R *.dfm}<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> ShowMessage(PChar(MXX_ComputerName)^);//这里<br>end;<br>返回乱字符.<br>原来的DLL里的代码类似这样的:<br>library SYS;<br>uses unit2, Windows, Messages, SysUtils, Classes, ExtCtrls,winsock;<br><br>var<br> returnstrhandle:Thandle;//字符串的返回值句柄<br>{$R *.res}<br><br>function M_GetComputerName:Thandle;stdcall;<br>var<br> CNameBuffer,P_returnstr: PChar;<br> returnstr:string;<br> fl_loaded : Boolean;<br> CLen : ^DWord;<br>begin<br> GetMem(CNameBuffer,255);<br> returnstrhandle:=globalalloc(GHND,8192); <br> P_returnstr:=globallock(returnstrhandle);<br> New(CLen);<br> CLen^:= 255;<br> fl_loaded := GetComputerName(CNameBuffer,CLen^);<br> if fl_loaded then<br> returnstr:=StrPas(CNameBuffer)<br> else<br> returnstr:='I Do not known!';<br> FreeMem(CNameBuffer,255);<br> Dispose(CLen);<br> strpcopy(P_returnstr,returnstr);<br> globalunlock(returnstrhandle);<br> result:=returnstrhandle;//就这里返回的<br>end;<br>end.<br>当然,我实际用时,要是知道了Delphi源码,当然不会非要在DLL里返回Handle,可以返回PChar,但是现在是调用别人的其他功能的.谢谢.