Thread View: borland.public.cppbuilder.nativeapi
6 messages
6 total messages
Started by Mike Collins
Thu, 01 Feb 2007 01:44
CoInitialize issues
Author: Mike Collins
Date: Thu, 01 Feb 2007 01:44
Date: Thu, 01 Feb 2007 01:44
91 lines
4562 bytes
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
Re: CoInitialize issues
Author: Remy Lebeau (TeamB)
Date: Thu, 01 Feb 2007 02:47
Date: Thu, 01 Feb 2007 02:47
108 lines
4049 bytes
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
Re: CoInitialize issues
Author: Mike Collins
Date: Thu, 01 Feb 2007 14:30
Date: Thu, 01 Feb 2007 14:30
142 lines
5885 bytes
5885 bytes
Remy, thanks a hundred fold, you reply was very useful
I've just given it a quick scan but the points you raised are very valid -
i'll give it my full attention when i get back.
The problem that i'm having is that i cannot reproduce the error - we have
done hundreds of sales and thus installations without issue. It has only
been reported by a handfull of people. To add to this problem, all the
uninstallation funcitonality and live update functionality WAS only
accessible from the help - so if the dialog fails, as it has, we knacked.
There is no, proactical was to remove the software. This was obviously a
design flaw by myself and has been re-addressed - there are now other ways
to access the said fucntionality.
But because of this, i can't send out updates to try and test to see if
anything resolves the problem. I did strip out the Help dialog and place it
in a stand alone applicaiton that mimiced exactly, what was going on and
sent this to our clients, however theis executed without issue and displaye
dthe dialog correctly.
I have not tracked down a UK customer who is allowing me access to there
laptop tomorrow so i should be able to provide you with a beter
explaintaiton and locate the point of failour.
I had thought that it might be possible that some of the OLE / COM
underlying services might not be fully initialised at such an early point in
the startup of the system.
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:45c154b4$1@newsgroups.borland.com...
>
> "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
>
>
Re: CoInitialize issues
Author: Mike Collins
Date: Fri, 02 Feb 2007 11:17
Date: Fri, 02 Feb 2007 11:17
16 lines
1748 bytes
1748 bytes
Ok, got a bit more information - sitting infront of a system that is exibiting the problem not - remember that we have hundreds of installations that work fine - so i'm at a lost to the actual cause. Whilst i can now say what the error message is, and thus where it must be stemming from, i've know idea why one system should fail and another work The error message that i get is an EAccessViolation - which is being catcht and shown from the final catch statement: catch (const Exception &exception) - the title of the error message confirms this also. So i'm not a million miles futher forward - excpet that i know that somewhere between the outer most try / catch, a VCL EAccessViolation is being raise.. Any ideas?
Re: CoInitialize issues
Author: Remy Lebeau (TeamB)
Date: Fri, 02 Feb 2007 19:41
Date: Fri, 02 Feb 2007 19:41
16 lines
1427 bytes
1427 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message news:45c31da6@newsgroups.borland.com... > The error message that i get is an EAccessViolation That is a long way away from a CoInitialize problem. > which is being catcht and shown from the final catch statement: Wht does your code actually look like now? Which catch statement are you referring to? Which line is actually throwing the exception to begin with? Gambit
Re: CoInitialize issues
Author: Mike Collins
Date: Fri, 02 Feb 2007 21:17
Date: Fri, 02 Feb 2007 21:17
7 lines
1248 bytes
1248 bytes
Hay Remy, I've found the erroneous code, but I'm going to report a new item as it's nothing to do with the CoInitialize "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:45c393cb$1@newsgroups.borland.com... >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads