EOleException::CoInitialize has not been called

EOleException::CoInitialize has not been called

Post by Jon Jacob » Sat, 28 Oct 2006 07:06:44


When I used the same PreTLMod in a non-service app, and called Init from a
button, it worked fine. But when I call it in a service, I get CoInitialize
has not been called. What do I need to do to make this work in my service
app?

Thanks,
Jon

program PreTLSvc;

uses
SvcMgr,
XCeedZipAPI in '..\3rdParty\XCeedZip\XCeedZipAPI.pas',
PreTLSvc1 in 'PreTLSvc1.pas' {SendSomething: TService},
PreTLDM in 'PreTLDM.pas' {PreTLMod: TDataModule};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TPreTLMod, PreTLMod);
Application.CreateForm(TSendSomething, SendSomething);
Application.Run;
end.


procedure TSendSomething.ServiceExecute(Sender: TService);
begin
PreTLMod.Init;
while not Terminated do
begin
ServiceThread.ProcessRequests(True);
end;
end;

procedure TPreTLMod.Init;
var
SL: TStringList;
S: string;
begin
S := Conn1.ConnectionString;
SL := TStringList.Create;
try
SL.LoadFromFile(Path+FileNm+'.stu');
S := Format(S, [SL.Values['Database'], SL.Values['Server'] ]);
finally
SL.Free;
end;
Log(S);
Conn1.ConnectionString := S;
Log('Before qryCreate.ExecSQL');
try
qryCreate.ExecSQL;
except
On E:Exception do
Log(E.ClassName +'::'+ E.Message);
end;
Log('After qryCreate.ExecSQL');

.

Before qryCreate.ExecSQL 2006/10/26 14:46:23.463
EOleException::CoInitialize has not been called 2006/10/26 14:46:23.463
After qryCreate.ExecSQL 2006/10/26 14:46:23.463
 
 
 

EOleException::CoInitialize has not been called

Post by Marc Rohlo » Sat, 28 Oct 2006 07:30:34


The error is a bit misleading. CoInitialize must be called from every
thread that is using COM. Delphi does it for the main thread but you
will have to do it for the other threads.

Don't forget to call CoUninitialize when you are done with each
thread.

--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com

 
 
 

EOleException::CoInitialize has not been called

Post by Jon Jacob » Sat, 28 Oct 2006 09:19:56

> The error is a bit misleading. CoInitialize must be called from every

Aha! is a Service app automatically using Com? I'm certainly not using it on
purpose.

Thanks,
Jon
 
 
 

EOleException::CoInitialize has not been called

Post by Steve Trox » Sat, 28 Oct 2006 09:29:26


If your query is a TADOQuery, you're using COM.

Steve Troxell
 
 
 

EOleException::CoInitialize has not been called

Post by Jon Jacob » Sun, 29 Oct 2006 09:08:45

> If your query is a TADOQuery, you're using COM.
That's it!

Now I know where I need CoInitialize. Now it works.

Thanks,

Jon