给你粘一个: 1。静态调用 function TestDll(i:integer):integer;stdcall; external ’Delphi.dll’; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text:=IntToStr(TestDll(1)); end; 2。动态调用 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;
我是在pwm单元中引入的链接库,然后在别的单元文件中调用,可编译都不通过。如下是pwm单元的代码。 unit pwm; interface implementation function Min(X, Y: Integer): Integer;stdcall; external 'testDDL.ddl'; end.请赐教! 小弟才开始搞DELPHI,比较菜!
last1990(枫子) ,这位兄弟能不能留个MSN或QQ什么的?小弟想请教一下!
是不是我DLL文件写错了呀? 我是这么定义的 library testDdl; function Min(X, Y: Integer): Integer; export; begin if X < Y then Min := X else Min := Y; end; function Max(X, Y: Integer): Integer; export; begin if X > Y then Max := X else Max := Y; end; exports Min index 1, Max index 2; begin end.
1.dll中 exports要分开写: exports Min; exports Max ; 2.调用方法不对: function Min(X, Y: Integer): Integer;far; external 'e:\DllTest.dll';
1。静态调用
function TestDll(i:integer):integer;stdcall;
external ’Delphi.dll’; procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=IntToStr(TestDll(1));
end;
2。动态调用
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;
unit pwm;
interface
implementation
function Min(X, Y: Integer): Integer;stdcall; external 'testDDL.ddl';
end.请赐教! 小弟才开始搞DELPHI,比较菜!
我是这么定义的
library testDdl;
function Min(X, Y: Integer): Integer; export;
begin
if X < Y then Min := X else Min := Y;
end;
function Max(X, Y: Integer): Integer; export;
begin
if X > Y then Max := X else Max := Y;
end;
exports
Min index 1,
Max index 2;
begin
end.
exports Min;
exports Max ;
2.调用方法不对:
function Min(X, Y: Integer): Integer;far; external 'e:\DllTest.dll';