Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1248476
  • 博文数量: 788
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 7005
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-19 15:52
文章存档

2017年(81)

2011年(1)

2009年(369)

2008年(337)

分类:

2008-11-27 21:17:38



我在动态调用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方式?

搞定被我说中了,  
  为了好用啊,要不然一人写一个,那别人怎么调用我写的东西啊!  
 

结贴,把分都给你吧

阅读(267) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~