我在动态调用dll时老出现如下错误
Project' 'raise too many consecutive exceptions 'access violation at 0X00000000:read of address 0X0000000' 调用代码:重要是在Log.dll中包含窗体,通过LoadSearchForm调出窗体
unit dlltest;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TLoadSearchForm=procedure (Handle:Thandle);stdcall;
var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var
handle:Thandle;
LoadSearchForm:TLoadSearchForm;
begin
handle:=Loadlibrary(pchar('Log.dll'));
try
if handle<>0 then
@LoadSearchForm:=GetProcAddress(handle,pchar('LoadSearchForm'));
if Assigned(@LoadSearchForm) then
begin
LoadSearchForm(Application.Handle);
end
else
RaiseLastOSError;
finally
FreeLibrary(handle);
end;
end;end.
Project' 'raise too many consecutive exceptions 'access violation at 0X00000000:read of address 0X0000000' 调用代码:重要是在Log.dll中包含窗体,通过LoadSearchForm调出窗体
unit dlltest;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TLoadSearchForm=procedure (Handle:Thandle);stdcall;
var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var
handle:Thandle;
LoadSearchForm:TLoadSearchForm;
begin
handle:=Loadlibrary(pchar('Log.dll'));
try
if handle<>0 then
@LoadSearchForm:=GetProcAddress(handle,pchar('LoadSearchForm'));
if Assigned(@LoadSearchForm) then
begin
LoadSearchForm(Application.Handle);
end
else
RaiseLastOSError;
finally
FreeLibrary(handle);
end;
end;end.
if handle<>0 then
LoadSearchForm:=GetProcAddress(handle,pchar('LoadSearchForm'));//不用加@
if Assigned(LoadSearchForm) then //不用加@
...2.贴一下你dll中LoadSearchForm的代码,看看有什么问题
Application.Handle:=Handle;
Form1:=TForm1.Create(nil);
try
Form1.ShowModal;
finally
Form1.Close;
end;
end;我在窗体中加了个按钮,写了form.close,
是不是写了这个后,点击按钮就不用在调用单元写freelibrary(handle);了