【发布时间】:2010-10-01 11:21:20
【问题描述】:
我在使用带参数的 Dll 过程发送时遇到问题,我不允许在我的测试项目中向 dll 方法的调用添加参数。
我正在尝试调用这个 dll 方法:
procedure Transfer(sMessage: PChar); stdcall;
begin
MainForm.ShowThis(sMessage);
end;
exports
Transfer;
TestProj 使用这个:
procedure TForm1.Button1Click(Sender: TObject);
var
DLLHandle : THandle;
begin
DLLHandle := LoadLibrary ('C:\Program Files\Borland\Delphi5\Projects\Dll\MyLink.dll');
if DLLHandle >= 32 then
try
@Trans := GetProcAddress (DLLHandle, 'Transfer');
if @Trans <> nil then
Trans //Would like to say something like: Trans('Hello')
else
Showmessage('Could not load method address');
finally
FreeLibrary(DLLHandle);
end
else
Showmessage('Could not load the dll');
end;
如果我使用“Trans('Hello')”,我得到的编译错误是: [错误] Unit1.pas(51): 实际参数太多。
我可以在没有参数的情况下运行它,但我只会在我的显示消息框中得到 jiberish 和崩溃,因为我不发送任何消息。
所以问题是我如何将字符串作为参数发送到 dll 中?我究竟做错了什么 ?
【问题讨论】: