Re: Ole / Com madness

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

"Tom Peters" <tom_vip…@msn.com> wrote in message
news:4514df63$…@newsgroups.borland.com...

> If I use:
<snip>
> 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...
    else
        // failed...

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

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

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

Gambit

Replies

None

In response to

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