BPL调用函数、过程问题 ( 积分: 50 )

  • 主题发起人 mailmanb
  • 开始时间
M

mailmanb

Unregistered / Unconfirmed
GUEST, unregistred user!
BPL调用函数、过程时,我遇到以下问题,希望各位大虾伸出缓手。
BPL源程序:
type
SubForm=TSubForm;
procedure StrToMSG(s:string);stdcall;
procedure MSG;stdcall;
function GetValue(i:integer):integer;stdcall;
exports
StrToMSG,MSG,GetValue;
implementation
{$R *.dfm}
procedure StrToMSG(s:string);stdcall;
begin
showmessage(s);
end;

procedure MSG;stdcall;
begin
showmessage('调用成功!');
end;

function GetValue(i:integer):integer;stdcall;
begin
result:=1;
end;
……
initialization
RegisterClass(TSubForm);

finalization
UnRegisterClass(TSubForm);
end.
 
调用BPL的代码:
type
MainForm=TMainForm;
...
TStrToMSG=procedure(s:string);stdcall;
TMSG=procedure;stdcall;
TGetValue=function(i:integer);stdcall;
...
procedure TMainForm.ButtonClick(Send:TObject);
var
i_handle:THandle;
i_Proc:TStrToMSG;
begin
i_handle:= LoadPackage('FSubForm.bpl');
try
try
@i_Proc:=GetProcAddress(i_handle,'StrToMSG');
if @i_Proc<>nil then
i_Proc('加载完成!');
except
On E:Exception with
showmessage(E.Message);
end;
finally
UnloadPackage(hModule);
end;
end;
...
另外两个函数定义同上
 
问题:
MSG调用没有问题,StrToMSG调用系统报错。
GetValue返回一个错的值,例如,我传3,按照函数,应该返回3,但返回的是1262640。
我曾试过在GetValue里设置一个showmessage来显示传过去的值,结果如上。
 
但我用DLL就完全无以上问题!
 
把参数变量类型改一下:procedure StrToMSG(s:pAnsiChar);stdcall;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
806
import
I
I
回复
0
查看
974
import
I
I
回复
0
查看
629
import
I
顶部