dll动态调用出错了 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiAPI/html/delphi_20061120120653194.html
我在动态调用dll时老出现如下错误
Project' 'raise too many consecutive exceptions 'access violation at 0X00000000:read of address 0X0000000'
调用代码:重要是在Log.dll中包含窗体,通过LoadSearchForm调出窗体
unit dlltest;
interface
uses
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.
1.改一下你的代码
...
if handle<>0 then
LoadSearchForm:=GetProcAddress(handle,pchar('LoadSearchForm'));//不用加@
if Assigned(LoadSearchForm) then //不用加@
...
2.贴一下你dll中LoadSearchForm的代码,看看有什么问题
procedure LoadSearchForm(Handle:THandle);
begin
Application.Handle:=Handle;
Form1:=TForm1.Create(nil);
try
Form1.ShowModal;
finally
Form1.Close;
end;
end;
我在窗体中加了个按钮,写了form.close,
是不是写了这个后,点击按钮就不用在调用单元写freelibrary(handle);了
搞不懂,怎么这么多人喜欢把窗体或DELPHI控件的调用写成DLL方式?
搞定被我说中了,
为了好用啊,要不然一人写一个,那别人怎么调用我写的东西啊!
结贴,把分都给你吧
文章来源:
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120120653194.html