Re: Ole / Com madness

Giganews Newsgroups
Subject: Re: Ole / Com madness
Posted by:  Remy Lebeau (TeamB) (
Date: Mon, 25 Sep 2006

"Tom Peters" <tom_vip…> wrote in message

> If I use:
> I do not get a messagebox.  The CoInitialize fails.

You are not taking into account that CoInitialize() can return S_FALSE if it
has already been called earlier on the calling thread.  The COM library can
be loaded into a given thread only once at a time.  Subsequent calls will
increase the reference count for the library.  S_FALSE is not a failure.
You should never be testing for S_OK specifically anyway.  Always check for
>= 0 instead.  All positive values (S_FALSE is 1) are successes, and all
negative values are failures, ie:

    if CoInitialize(nil) >= 0 then
        // succeeded...
        // failed...

Better, always use SUCCEEDED() and FAILED() instead:

    if SUCCEEDED(CoInitialize(nil)) then
        // succeeded...
        // failed...

    if FAILED(CoInitialize(nil)) begin
        // failed...
        // succeeded...




In response to

Ole / Com madness posted by Tom Peters on Sat, 23 Sep 2006