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函数出错,请指教!