M
mally
Unregistered / Unconfirmed
GUEST, unregistred user!
我制作了一个DLL A,其接口函数如下:
uses
ShareMem,
.......;
{$R *.res}
function ShowWeatherForm(ConnectionStr :string;AHandle:THandle):integer;
var
SaveDllAppHandle: THandle;
begin
SaveDllAppHandle := Application.Handle;
Application.Handle := AHandle;
result := -1;
Form1 := TForm1.Create(mainForm);
try
Form1.ADOConnection1.Connected := False;
Form1.ADOConnection1.ConnectionString := ConnectionStr;
Form1.ADOConnection1.Connected := true;
Form1.ShowModal;
finally
Form1.Free;
Form1 := nil;
Application.Handle := SaveDllAppHandle;
end;
end;
exports
ShowWeatherForm;
我在程序中直接动态调用A,调用语句如下:
type TShowWeatherForm = function(ConnectionStr :string;MainForm:TForm):integer;
.........
procedure TfrmSingleBowl.rzbtbtn1Click(Sender: TObject);
var
ShowWeatherForm : TShowWeatherForm;
LibHandle : THandle;
begin
if not fileexists(extractfiledir(application.ExeName)+'/WeatherDll.dll') then
begin
showmessage('找不到文件:WeatherDll.dll');
exit;
end;
LibHandle := Loadlibrary(pchar(extractfiledir(application.ExeName)+'/WeatherDll.dll'));
try
if LibHandle = 0 then
begin
showmessage('导入动态链接库WeatherDll.dll错误');
exit;
end;
@ShowWeatherForm := GetProcAddress(LibHandle,'ShowWeatherForm');
if @ShowWeatherForm = nil then
begin
showmessage('导入动态链接库WeatherDll.dll错误');
exit;
end;
ShowWeatherForm(ADOConnection1.ConnectionString,application.MainForm);
finally
FreeLibrary(LibHandle);
end;
end;
一切都运行正常。但是我有一个DLL B,接口函数和A的一样,也是输出一个模式窗体,只是在B中的窗体中有一个按钮,点击按钮就动态调用DLL A,调用代码和上面一样,这个时候就经常出现内存地址访问错误的提示,但是偶尔是好的。我调试了几天了,就是不知道为什么在程序中直接调用DLL A是好好的,用DLL B调用DLL A的时候就出问题了。
uses
ShareMem,
.......;
{$R *.res}
function ShowWeatherForm(ConnectionStr :string;AHandle:THandle):integer;
var
SaveDllAppHandle: THandle;
begin
SaveDllAppHandle := Application.Handle;
Application.Handle := AHandle;
result := -1;
Form1 := TForm1.Create(mainForm);
try
Form1.ADOConnection1.Connected := False;
Form1.ADOConnection1.ConnectionString := ConnectionStr;
Form1.ADOConnection1.Connected := true;
Form1.ShowModal;
finally
Form1.Free;
Form1 := nil;
Application.Handle := SaveDllAppHandle;
end;
end;
exports
ShowWeatherForm;
我在程序中直接动态调用A,调用语句如下:
type TShowWeatherForm = function(ConnectionStr :string;MainForm:TForm):integer;
.........
procedure TfrmSingleBowl.rzbtbtn1Click(Sender: TObject);
var
ShowWeatherForm : TShowWeatherForm;
LibHandle : THandle;
begin
if not fileexists(extractfiledir(application.ExeName)+'/WeatherDll.dll') then
begin
showmessage('找不到文件:WeatherDll.dll');
exit;
end;
LibHandle := Loadlibrary(pchar(extractfiledir(application.ExeName)+'/WeatherDll.dll'));
try
if LibHandle = 0 then
begin
showmessage('导入动态链接库WeatherDll.dll错误');
exit;
end;
@ShowWeatherForm := GetProcAddress(LibHandle,'ShowWeatherForm');
if @ShowWeatherForm = nil then
begin
showmessage('导入动态链接库WeatherDll.dll错误');
exit;
end;
ShowWeatherForm(ADOConnection1.ConnectionString,application.MainForm);
finally
FreeLibrary(LibHandle);
end;
end;
一切都运行正常。但是我有一个DLL B,接口函数和A的一样,也是输出一个模式窗体,只是在B中的窗体中有一个按钮,点击按钮就动态调用DLL A,调用代码和上面一样,这个时候就经常出现内存地址访问错误的提示,但是偶尔是好的。我调试了几天了,就是不知道为什么在程序中直接调用DLL A是好好的,用DLL B调用DLL A的时候就出问题了。