procedure TForm1.Button3Click(Sender: TObject); type Tf=procedure(var s:pchar);stdcall; var fh:thandle; tp:tfarproc; s:pchar; begin fh:=loadlibrary('Project2.dll'); if fh>0 then begin try tp:=getprocaddress(fh,pchar('getstringfromdll')); if tp<>nil then begin //s:=stralloc(80); //s:=strpcopy(s,'ok'); tf(tp)(s); self.Caption:=string(s); end; finally freelibrary(fh);//到这步才出错 end; end; end;
type
Tf=procedure(var s:pchar);stdcall;
var
fh:thandle;
tp:tfarproc;
s:pchar;
begin
fh:=loadlibrary('Project2.dll');
if fh>0 then
begin
try
tp:=getprocaddress(fh,pchar('getstringfromdll'));
if tp<>nil then
begin
//s:=stralloc(80);
//s:=strpcopy(s,'ok');
tf(tp)(s);
self.Caption:=string(s);
end;
finally
freelibrary(fh);//到这步才出错
end;
end;
end;
s:=stralloc(80);