【发布时间】:2010-04-20 08:29:05
【问题描述】:
使用显式链接时,我的 dll 无法正常工作。使用隐式链接可以正常工作。有人会谷歌我的解决方案吗? :) 不,开个玩笑,这是我的代码:
这段代码运行良好:
function CountChars(_s: Pchar): integer; StdCall; external 'sample_dll.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(CountChars('Hello world')));
end;
此代码不起作用(我遇到访问冲突):
procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle: HMODULE;
CountChars: function(_s: PChar): integer;
begin
LibHandle := LoadLibrary('sample_dll.dll');
ShowMessage(IntToStr(CountChars('Hello world'))); // Access violation
FreeLibrary(LibHandle);
end;
这是 DLL 代码:
library sample_dll;
uses
FastMM4, FastMM4Messages, SysUtils, Classes;
{$R *.res}
function CountChars(_s: PChar): integer; stdcall;
begin
Result := Length(_s);
end;
exports
CountChars;
begin
end.
【问题讨论】: