dll动态调用出错了

dll动态调用出错了 Delphi / Windows SDK/API
http://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方式?

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

结贴,把分都给你吧

转载于:https://www.cnblogs.com/delphi2007/archive/2008/11/27/1342630.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值