🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2680

Re: CoInitialize issues

#2680
From: Remy Lebeau (TeamB)
Date: Thu, 01 Feb 2007 02:47
108 lines
4049 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message
news:45c145d9$1@newsgroups.borland.com...

> we have now started to have reports, from the US, that the help
> dialog is failing to be displayed and the error message returned
> seems to relate to the CoInitialize call failing.

Please be more specific.  What exactly is happening?  What is the
actual error code being returned?  Is it actually being reported when
you call CoInitialize() yourself, or when the dialog is being created?

>       catch (const Exception &exception)
>       {
>          // ************* This seems to be the error message that is
> displayed **************

Given the code you have shown, the error has to be coming from the
dialog itself, since that is the only place a VCL exception can be
getting thrown from.  It would be helpful to know exactly WHICH line
is throwing the exception, though.

Probably the dialog is making its own call to CoInitialize/Ex()
(directly or indirectly) and then failing because CoInitialize() was
previously called with a different threading model specified.

> The problem seems to be in the initial call to CoInitialize, and the
error
> message that our users are seeing is that displayed from the last
catch
> statement (Exception &exception).

What is the actual error message?

> I know this is a bit general

Too general.

> should i sit in a loop calling CoInitialize until i get a success.

Absolutely not.

> If is possible that the necessary services will not have been fully
> started at that point?

No, because you already one one call to CoInitialize() succeeding
before the error ocurs.


Try this code instead:

    if( SUCCEEDED(CoInitialize(NULL)) )
    {
        try
        {
            THelpOptDlg *HelpOptDlg = NULL;

            try
            {
                HelpOptDlg = new THelpOptDlg(NULL);
            }
            catch (...)
            {
                GinaStub->WlxMsgBox(DISPLAY_HELP_DLG_CREATE_ERROR_MSG,
MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_TOPMOST);
            }

            if( HelpOptDlg )
            {
                try
                {
                    try
                    {
                        iModalRst = HelpOptDlg->ShowModal();
                    }
                    __finally
                    {
                        delete HelpOptDlg;
                    }
                }
                catch (const Exception &)
                {

GinaStub->WlxMsgBox(DISPLAY_HELP_DLG_SHOW_ERROR_MSG, MB_OK |
MB_ICONERROR | MB_TASKMODAL | MB_TOPMOST);
                }
            }
        }
        catch (const Exception &e)
        {
            AnsiString szExpMsg;

szExpMsg.sprintf(GinaStub->RtnSz(KID_SAFE_GENERAL_EXCEPTION_MSG),
e.Message.c_str());
            GinaStub->WlxMsgBox(szExpMsg, MB_OK | MB_ICONERROR |
MB_TASKMODAL | MB_TOPMOST);
        }

        // Must be called once the form with the corrisponding OLE
container is destroyed
        CoUninitialize();
    }
    else
        GinaStub->WlxMsgBox(DISPLAY_HELP_OLE_ERROR_MSG, MB_OK |
MB_ICONWARNING | MB_TASKMODAL | MB_TOPMOST);


Gambit
Technical Details
Message-ID: <45c154b4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <45c145d9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6927f106572d30a6
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <45c145d9$1@newsgroups.borland.com>
Subject: Re: CoInitialize issues
Date: Wed, 31 Jan 2007 18:47:43 -0800
Lines: 110
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.34.171
Message-ID: <45c154b4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1170298036 75.83.34.171 (31 Jan 2007 18:47:16 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail