#1 2020-12-09 16:06:25

leus
Member
Registered: 2012-09-05
Posts: 79

CoInitialize has not been called

I'm using a `TSQLRestServerFullMemory` object, and a service that will internally use MSXML. I'm getting this error:

Debug Output:
onecore\com\combase\objact\objact.cxx(827)\combase.dll!767FF2A9: (caller: 767FE1DB) ReturnHr(20) tid(3664) 800401F0 CoInitialize has not been called.

Where should I call CoInitialize / CoUnitialize methods in my server?

Offline

#2 2020-12-09 16:19:49

leus
Member
Registered: 2012-09-05
Posts: 79

Re: CoInitialize has not been called

By the way, I just called CoInitialize() in the service method itself, as repeated calls in the same thread should not do anything extra, according to some guy on the internet. Is this right?

Offline

#3 2020-12-09 16:47:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: CoInitialize has not been called

You need to call it from the BeginCurrentThread/EndCurrentThread methods.

And don't forget to call CoUninitialize too.

Offline

#4 2020-12-09 16:57:18

leus
Member
Registered: 2012-09-05
Posts: 79

Re: CoInitialize has not been called

Do you mean, overloading those methods in a descendant class?


TMyRestServer = class(TSQLRestServerFullMemory)
protected
  procedure BeginCurrentThread(Sender: TThread); override;
  procedure EndCurrentThread(Sender: TThread); override;
end;

procedure TMyRestServer.BeginCurrentThread(Sender: TThread);
begin
  inherited;
  CoInitialize(nil);
end;

procedure TMyRestServer.EndCurrentThread(Sender: TThread);
begin
  CoUninitialize;
  inherited;
end;

Last edited by leus (2020-12-09 17:08:43)

Offline

#5 2020-12-09 17:28:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: CoInitialize has not been called

YEs, this should do the trick.

Offline

Board footer

Powered by FluxBB