您当前的位置:delphi教程 > Delphi系统相关 > Delphi编写的dll在C++Builder中的调用问题!

Delphi编写的dll在C++Builder中的调用问题!

Delphi编写的dll源码如下:  
  library   FSearch;  
   
  uses  
      SysUtils,   Classes,   FastSearch,   DB,   ADODB;  
   
  var  
          FastSearch1:   TFastSearch;  
   
  {$R   *.res}  
  function   FastSearch(ADOQuery1:   TADOQuery):String;stdcall;  
  var   strSQL:String;  
  begin  
      strSQL:='';  
      FastSearch1.DataSet:=ADOQuery1;  
      if   FastSearch1.Search()   then  
      begin  
          strSQL:=FastSearch1.QueryCondition;  
      end;  
      Result:=strSQL;  
  end;  
   
  exports  
      FastSearch;  
   
  begin  
  end.  
   
  C++Builder中调用如下:  
  typedef   AnsiString   (GetValue)(TADOQuery*);  
  __declspec(dllimport)   AnsiString   __stdcall   FastSearch(TADOQuery   *adoQuery);  
  //---------------------------------------------------------------------------  
  void   __fastcall   TForm1::Button1Click(TObject   *Sender)  
  {  
          HINSTANCE   nDLL;  
          GetValue   *theValue;  
          nDLL   =   LoadLibrary("FSearch.dll");  
          if(nDLL   !=   NULL)  
          {  
                  theValue   =   (GetValue*)GetProcAddress(nDLL,   "FastSearch");  
                  if(theValue   !=   NULL)  
                          Edit1->Text   =   (*theValue)(ADOQuery1);  
          }  
          FreeLibrary(nDLL);  
  }  
  //---------------------------------------------------------------------------  
  跟踪运行到Edit1->Text   =   (*theValue)(ADOQuery1);报错,也就是说调用Dll函数出错,请指教!


点击进入 查看回复

关于我们 | 网站地图 | 广告刊登 | 友情链接
Copyright ©2008 - 2010  Delphi2007.net  ,All Rights Reserved  粤ICP备09038647号
业务联系:allceoad#gmail.com QQ:20008835 最佳分辨率 1024×768