🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

CoInitialize issues

#2679
From: Mike Collins
Date: Thu, 01 Feb 2007 01:44
91 lines
4562 bytes
Hi all, possibly should have posted in the .ActiveX so apologies first off.

I've just been hit by an issue with CoInitialize().  In order to understand, 
i need to give a bit of background information.  We've developed a child 
protection system to allow parents to control access to there computer.  The 
system is based around a GINA-stub.  I've posted on this general topic 
several times.  Our gina loads up and everything works fine.

We have a 'help' system based on a TForm dialog that is accessible from the 
gina.  With in this 'help' dialog, we have an embedded browser object, 
TCppWebBrowser, that is used to display html licence information.  Now i was 
having problems with this in initial development and i posted on the 
problem.  I was told to use CoInitialize / CoUnInitialize before i created 
the Help dialog and not to look for the S_OK return value.  Based on this, i 
modified my code and all seemed to work.

We deployed our product with positive feedback.  However, 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.  This is absolutely terrible from our point of view as core 
functionality is accessed from the help.

My code looks basically like this:

     try
     {
         if (SUCCEEDED(CoInitialize(NULL)))
         {
            try
            {
               THelpOptDlg *HelpOptDlg = NULL;
               try
               {
                  try
                  {
                     HelpOptDlg = new THelpOptDlg(Application->MainForm);
                     iModalRst = HelpOptDlg->ShowModal();
                  }
                  catch (const std::bad_alloc &e)
                  {
                     GinaStub->WlxMsgBox(DISPLAY_HELP_DLG_ERROR_MSG, MB_OK | 
MB_ICONERROR | MB_TASKMODAL | MB_TOPMOST);
                  }
               }
               __finally
               {
                  if (HelpOptDlg)
                  {
                     delete HelpOptDlg;
                     HelpOptDlg = NULL;
                  }
               }
            }
            __finally
            {
               // 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);
      }
      catch (const Exception &exception)
      {
         // ************* This seems to be the error message that is 
displayed **************

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

the WlxMsgBox is just a wrapper around the win32 api MessageBox.  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).

I know this is a bit general, but any help or suggestions would be 
gratefully received.  Should i be testing for success in a different 
fashion, should i sit in a loop calling CoInitialize until i get a success. 
If is possible that the necessary services will not have been fully started 
at that point?

Thank again,

Mike Collins 
Technical Details
Message-ID: <45c145d9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!feeder.news-service.com!news.germany.com!news.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6927f106572d30a6,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mike Collins" <its@TheBottomOfThePost.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: CoInitialize issues
Date: Thu, 1 Feb 2007 01:44:53 -0000
Lines: 93
Organization: SDA Ltd
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.2826
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2826
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 84.13.8.188
Message-ID: <45c145d9$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1170294233 84.13.8.188 (31 Jan 2007 17:43:53 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!feeder.news-service.com!news.germany.com!news.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail