Page 1 of 1

UniDac Components within DLL

Posted: Tue 13 Mar 2012 16:04
by Bluebits
Hello,

we need to connect to on of our DB2 Databases from within an DLL.
Because this DLL should be universal it is no option for us to share an database-connection with the main programm - as shown in unidac dll sample.
I tried now to include unidac connection in dll and connect from within the dll.
But I get an exception as soon as mainprogram is closed.
The mainprogram I used is a new (empty) vcl application wich only imports one function of the dll (static loading) and calls it.
If the dll function is not called, no exception is thrown.
The same if i just create the unidac-connection but not connect to the database.

Unidac-Version is 4.1.4 Trial
OS: XP SP3
IDE: BDS 2006

Code in DLL looks as following:

uses
ActiveX,
uni,
db2uniprovider;

function GetRights : integer;stdCall;export;
var
myUni:TUniConnection;
begin
//CoInitialize(nil);
myUni:=TUniConnection.Create(nil);
try
result:=0;
myUni.Database:='Test';
myUni.Server:='TestServer';
myUni.Port:=50000;
myUni.ProviderName:='DB2';
myUni.Username:='user';
myUni.Password:='pass';
myUni.Open;
myUni.Close;
finally
myUni.Free;
myUni:=nil;
//CoUninitialize;
end;
end;

Code in mainprogram:

function GETRIGHTS : integer; stdCall external 'C:\Test-Workfolder\sandbox\PrueferLogin\UnidacTest\Test\MAIN.DLL';

implementation

{$R *.dfm}

procedure TForm4.Button1Click(Sender: TObject);
begin
Showmessage(IntToStr(GETRIGHTS));
end;


if I comment out myUni.Open, no exception is thrown.
Is there something in code I missed?
As you can see in code I already tried CoInitialize/CoUninitialize but with no success.

Posted: Wed 14 Mar 2012 12:52
by AlexP
Hello,

We checked the problem you have described in several Delphi versions (7, 2006, XE), and the error appears only in Delphi 2006 when closing the application. Delphi 2006 may unload static libraries incorrectly, since such problem doesn't occur even in Delphi 2006 when dynamic loading of the same library. The dynamic loading of the DLL may help you