bpl调用 ( 积分: 100 )

  • 主题发起人 主题发起人 sky1000
  • 开始时间 开始时间
S

sky1000

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TStrFunction = Function(FileName:String):String;stdcall;

const
DllName = 'rkdtsttoxml.bpl';

var
Form1: TForm1;

implementation
uses ShareMem;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
H:HModule;
FileName,Slh:String;
TPointer:TFarproc;
StrFunc:TStrFunction;
begin
if not OpenDialog1.Execute then
exit;
FileName:=OpenDialog1.FileName;
H:=0;
H:=LoadPackage(DllName);
try
if H>0 then
begin
TPointer:=GetProcAddress(H,PChar('GetSlh'));//GetSlh是读取一个xml文件,把slh值取出来.但是IPointer是值是空值,不知为什么,有知道的指点一下,头一次调用*.bpl,
if not (TPointer=nil) then
begin
StrFunc:=TStrFunction(TPointer);
Slh:=StrFunc(FileName);

end;
end;
finally
if H<>0 then
begin
UnLoadPackage(H);
H:=0;
end;
ShowMessage(Slh);
end;
end;
 
type
TStrFunction = Function(FileName:String):String;stdcall;

const
DllName = 'rkdtsttoxml.bpl';

var
Form1: TForm1;

implementation
uses ShareMem;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
H:HModule;
FileName,Slh:String;
TPointer:TFarproc;
StrFunc:TStrFunction;
begin
if not OpenDialog1.Execute then
exit;
FileName:=OpenDialog1.FileName;
H:=0;
H:=LoadPackage(DllName);
try
if H>0 then
begin
TPointer:=GetProcAddress(H,PChar('GetSlh'));//GetSlh是读取一个xml文件,把slh值取出来.但是IPointer是值是空值,不知为什么,有知道的指点一下,头一次调用*.bpl,
if not (TPointer=nil) then
begin
StrFunc:=TStrFunction(TPointer);
Slh:=StrFunc(FileName);

end;
end;
finally
if H<>0 then
begin
UnLoadPackage(H);
H:=0;
end;
ShowMessage(Slh);
end;
end;
 
一个例子
type
//signature of the "ExecuteChild" procedure from the Package
TExecuteChild = function(InStr:String):string;
var
PackageModule: HModule;
ExecuteChild: TExecuteChild;

procedure TMainForm.PackageLoad;
begin
//try loading tzhe package (let's say it's in the same folder, where the main app. exe is)
PackageModule := LoadPackage('MDIPackage.bpl');

//if loaded, try locating the ExecuteChild procedure
if PackageModule <> 0 then
try
@ExecuteChild := GetProcAddress(PackageModule, 'ExecuteChild');
except
//display an error message if we fail
ShowMessage('Package not found');
end;
end;
 
bpl里面的调用规则不是stdcall的把?你把声明部分这个去掉试试。
 
后退
顶部