UniDac Components within DLL

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Bluebits
Posts: 1
Joined: Tue 13 Mar 2012 15:35

UniDac Components within DLL

Post by Bluebits » Tue 13 Mar 2012 16:04

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.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 14 Mar 2012 12:52

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

Post Reply