先要申明一下 比如 procedure TForm1.Button1Click(Sender: TObject); type TIntFunc=function(i:integer):integer;stdcall; var Th:Thandle; Tf:TIntFunc; Tp:TFarProc; begin Th:=LoadLibrary(’Cpp.dll’); {装载DLL} if Th>0 then try Tp:=GetProcAddress(Th,PChar(’TestC’)); if Tp<>nil then begin Tf:=TIntFunc(Tp); Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数} end else ShowMessage(’TestC函数没有找到’); finally FreeLibrary(Th); {释放DLL} end else ShowMessage(’Cpp.dll没有找到’); end;
比如
procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc=function(i:integer):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary(’Cpp.dll’); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar(’TestC’));
if Tp<>nil then begin
Tf:=TIntFunc(Tp);
Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数}
end
else
ShowMessage(’TestC函数没有找到’);
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage(’Cpp.dll没有找到’);
end;