DLL 文件library mydll;uses
SysUtils, Classes, Dialogs, windows;
function Triple(N:Integer):integer;stdcall;
begin
result:=N+3;
end;function Double(N:Integer):integer;stdcall;
begin
result:=N+2;
end;function Triple1(N:Integer):integer;stdcall;
begin
showmessage('计算N+3, 其中N=' + IntToStr(N));
result:=N+3;
end;function Double1(N:Integer):integer;stdcall;
begin
messagebox(0,'计算N+2','计算N+2',mb_ok);
result:=N+2;
end;exportsTriple name 'Tr',
Double name 'Do',
Triple1 name 'TrM',
Double1 name 'DoM',
setaaa name 'sa',
getaaa name 'ga';{$R *.RES}
begin
end.*************************************
编译后声称 DLL文件动态调入文件unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyFun = function(N:integer):integer;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
h: THandle;
ts: TMyFun;
begin
h:=LoadLibrary('d:\mydll.dll');
try
if h=0 then
Raise Exception.Create('faild load library');
@ts := GetProcAddress(h, 'TrM');
if @ts <> nil then
showmessage(IntToStr(ts(10)))
else
showmessage('function ......');
finally
FreeLibrary(h);
end;
end;end.*************************************
DLL文件中 Triple1 接收到的数值不是我传给他的,是一个很大的数,这是怎么回事?如何解决,谢谢?
补充一句静态调入时没有为题
SysUtils, Classes, Dialogs, windows;
function Triple(N:Integer):integer;stdcall;
begin
result:=N+3;
end;function Double(N:Integer):integer;stdcall;
begin
result:=N+2;
end;function Triple1(N:Integer):integer;stdcall;
begin
showmessage('计算N+3, 其中N=' + IntToStr(N));
result:=N+3;
end;function Double1(N:Integer):integer;stdcall;
begin
messagebox(0,'计算N+2','计算N+2',mb_ok);
result:=N+2;
end;exportsTriple name 'Tr',
Double name 'Do',
Triple1 name 'TrM',
Double1 name 'DoM',
setaaa name 'sa',
getaaa name 'ga';{$R *.RES}
begin
end.*************************************
编译后声称 DLL文件动态调入文件unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyFun = function(N:integer):integer;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
h: THandle;
ts: TMyFun;
begin
h:=LoadLibrary('d:\mydll.dll');
try
if h=0 then
Raise Exception.Create('faild load library');
@ts := GetProcAddress(h, 'TrM');
if @ts <> nil then
showmessage(IntToStr(ts(10)))
else
showmessage('function ......');
finally
FreeLibrary(h);
end;
end;end.*************************************
DLL文件中 Triple1 接收到的数值不是我传给他的,是一个很大的数,这是怎么回事?如何解决,谢谢?
补充一句静态调入时没有为题
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货