Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling CoInitialize in a service application

62 views
Skip to first unread message

John Lambe

unread,
Dec 6, 2000, 3:00:00 AM12/6/00
to
I'm using ADO from a service application.
When I call CoInitialize (because ADO uses COM), it returns E_INVALIDARG.
(If I try to connect a TADOConnection without calling CoInitialise or after
it failed, I get an EOleSysError with the message "CoInitialize has not been
called").

I'm calling CoInitialize in the project source of the service application.

This is my code (project source of the service application):

program Serv_ADO;

uses
SvcMgr,
Serv_ADO1 in 'Serv_ADO1.pas' {Service1: TService},
Dialogs, Sysutils;

{$R *.RES}

function CoInitialize(p: Pointer): HRESULT; external 'ole32.dll';
procedure CoUninitialize; external 'ole32.dll';

const
S_OK = 0;
S_FALSE = 1;
E_OUTOFMEMORY = $8007000E;
E_INVALIDARG = $80070057;
E_UNEXPECTED = $8000FFFF;

var n : Integer;
begin
n := CoInitialize(nil);
if n=S_OK then
begin
Application.Initialize;
Application.CreateForm(TService1, Service1);
Application.Run;
end;
CoUninitialize;
end.


The Win32 Programmer's Reference says that the argument of CoInitialize must
be NULL.


I tried calling it in the OnServiceStart event but it gave the same result.
Where should you call CoInitialize?

Does anyone know why this doesn't work? What am I doing wrong?


(In the Win32 Programmer's Reference help file which comes with Delphi, the
link from the index entry for CoInitialize points to the wrong page. I'm
using an earlier copy).


0 new messages