` Printed Icetips Article

Icetips Article



COM: Uninitalizing COM objects 1
2004-01-17 -- Carl Barnes
 
Newsgroups: softvelocity.public.clarion6


MSDN on CoInitilize says the following:

"Typically, the COM library is initialized on a thread only once. Subsequent
calls to CoInitialize or CoInitializeEx on the same thread will succeed, as
long as they do not attempt to change the concurrency model, but will return
S_FALSE. To close the COM library gracefully, each successful call to
CoInitialize or CoInitializeEx, including those that return S_FALSE, must be
balanced by a corresponding call to CoUninitialize."

When I looked an the CComInitter Destruct method it does not appear to call
CoUNinit if S_False was returned for the CoInit.

Also does CoInit really need to be called per thread? MSDN clearly says it
does, but the book "Inside COM" says per Process.

CCOMIniter.Construct procedure

  code
    self.hr = CoInitialize()
    if self.hr = S_FALSE
      self.fAlreadyInitialised = true
      self.hr = S_OK
    end
    if self.hr = S_OK
      if ~self.fAlreadyInitialised
        self.fInitialised = true.
    end


CCOMIniter.Destruct procedure

  code
    if self.fInitialised
      if ~self.fAlreadyInitialised
        CoUninitialize().
      self.fInitialised = false
    end



Printed December 11, 2024, 3:18 pm
This article has been viewed/printed 35391 times.
Google search has resulted in 29 hits on this article since January 25, 2004.