Board index » delphi » Still having problems with ADOConnection - Advanced users

Still having problems with ADOConnection - Advanced users

I'm creating dynamicaly an ADOConection in a DLL. In a common application it
works, but in the DLL a message appears saying that CoInitialize was not
called. I've debuged the .pas that creates the connection and the problem
(not the exception) appears to be in the line

  Status := CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IUnknown, Result);
because the value of "Status" is tasted later and then the exception is
raised. The function that tests Status is

function Succeeded(Res: HResult): Boolean;
begin
  Result := Res and $80000000 = 0;
end;

where "Res" is the "Status" variable.

Here is the Status type:

  {$EXTERNALSYM HRESULT}
  HRESULT = type Longint;  { from WTYPES.H }

{$EXTERNALSYM IUnknown}
{$EXTERNALSYM IDispatch}

  PGUID = ^TGUID;
  TGUID = packed record
    D1: LongWord;
    D2: Word;
    D3: Word;
    D4: array[0..7] of Byte;
  end;

Please help me in this one.

 

Re:Still having problems with ADOConnection - Advanced users


  When creating COM objects from threads other than the main thread, from
services, and from DLLs, you need to call CoInitialize(nil), and call
CoUninitialize after you're done.
-Howard

Re:Still having problems with ADOConnection - Advanced users


Is this done by Application.Initialize  ?????

Re:Still having problems with ADOConnection - Advanced users


Call it directly
it is define in the ActiveX unit so you have to add it to your uses segment

David

Quote
 <moi...@rech.com.br> wrote in message news:3a6600d3_2@dnews...
> Is this done by Application.Initialize  ?????

Re:Still having problems with ADOConnection - Advanced users


Quote
"Moises" <moi...@rech.com.br> wrote in message news:3a65f39c_1@dnews...
> I'm creating dynamicaly an ADOConection in a DLL. In a common application
it
> works, but in the DLL a message appears saying that CoInitialize was not
> called. I've debuged the .pas that creates the connection and the problem
> (not the exception) appears to be in the line

>   Status := CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or
>     CLSCTX_LOCAL_SERVER, IUnknown, Result);

I gave you the solution the first time you posted this problem:

begin
CoInitialize(nil);
...
CoUninitialize;
end.

--

Quidquid latine dictum sit, altum viditur.

Re:Still having problems with ADOConnection - Advanced users


  Call those on entry and exit to your exported function(s).  Don't worry if
it gets called twice (i.e., if one exported function calls another and they
both have that code)...as long as the calls balance, you're okay.
-Howard
Quote
"Moises" <moi...@rech.com.br> wrote in message news:3a6600d3_2@dnews...
> Is this done by Application.Initialize  ?????

Other Threads