dll和应用程序中都有一个DataModule,里面有ADOConnection。应用程序中的ADOConnection已配置并连接上数据库,dll中的ADOConnection未配置,由应用程序将其中的ADOConnection传给dll中的ADOConnection,总是出现“无效的授权说明”,但是将dll中ADOConnection配置好,就没有问题了是什么原因?本人刚开始使用Delphi,望高手指点,谢谢!
主要的程序代码如下:
Dll中的exports函数有:
//GetForm用来查找dll中的窗体
function GetForm(ClassName :PChar):TFormClass;stdCall;
begin
Result := TFormClass(FindClass(ClassName));
end;//InitDll函数用来初始化dll
procedure InitDll(H:THandle;cnn:TADOConnection);stdCall;
begin
Application.Handle:=H;
DataModule1 :=TDataModule1.Create(Application);
DataModule1.ADOConnection1 := cnn;
end;应用程序中主要调用代码如下:
//初始化dll,将应用程序中的Application和ADOConnection1传递给Dll
DllHandle := LoadLibrary('dll\CustManager.dll');
if DllHandle<>0 then
begin
FarProc := GetProcAddress(DllHandle,'InitDll');
if Assigned(FarProc) then
begin
InitDll := TInitDll(FarProc);
InitDll(Application.Handle,DataModule1.ADOConnection1);
end;
end; //查找Dll中的窗体,找到创建窗体并显示,
//该窗体中的ADOQuery1用到ADOConnection1,
//一旦调用ADOQuery1.Open就出现上面说的错误
if DllHandle<>0 then
begin
FarProc := GetProcAddress(DllHandle,'GetForm');
if Assigned(FarProc) then
begin
GetForm := TGetForm(FarProc);
Form := GetForm('TCustSeekForm').Create(Application);
Form.Show;
end;
end;各位高手看看什么问题,请给予指点,在此深表感谢!
主要的程序代码如下:
Dll中的exports函数有:
//GetForm用来查找dll中的窗体
function GetForm(ClassName :PChar):TFormClass;stdCall;
begin
Result := TFormClass(FindClass(ClassName));
end;//InitDll函数用来初始化dll
procedure InitDll(H:THandle;cnn:TADOConnection);stdCall;
begin
Application.Handle:=H;
DataModule1 :=TDataModule1.Create(Application);
DataModule1.ADOConnection1 := cnn;
end;应用程序中主要调用代码如下:
//初始化dll,将应用程序中的Application和ADOConnection1传递给Dll
DllHandle := LoadLibrary('dll\CustManager.dll');
if DllHandle<>0 then
begin
FarProc := GetProcAddress(DllHandle,'InitDll');
if Assigned(FarProc) then
begin
InitDll := TInitDll(FarProc);
InitDll(Application.Handle,DataModule1.ADOConnection1);
end;
end; //查找Dll中的窗体,找到创建窗体并显示,
//该窗体中的ADOQuery1用到ADOConnection1,
//一旦调用ADOQuery1.Open就出现上面说的错误
if DllHandle<>0 then
begin
FarProc := GetProcAddress(DllHandle,'GetForm');
if Assigned(FarProc) then
begin
GetForm := TGetForm(FarProc);
Form := GetForm('TCustSeekForm').Create(Application);
Form.Show;
end;
end;各位高手看看什么问题,请给予指点,在此深表感谢!
你只能使用ADO的原生对象来解决问题,如_Connection、_Recordset、_Command等.能不能说的具体点,谢谢!