_com_error not caught by 'Try-Catch' code
-
I have added some code (to an existing MFC/ATL application), to communicate with a piece of hardware that comes complete with com-based driver software. (Before I forget: I'm writing C++ in Visual Studio 2010, for Windows7). My code is based closely upon the sample code that the hardware manufacturer supplied, and is as follows;
#import "GlobMgr.dll" no_namespace // I/O funtionality
#import "IviDriverTypeLib.dll" no_namespace // IVI inherent functionality
#import "agu265x.dll" no_namespace // Instrument specific functionalityIAgilentU265xPtr spAgDrvrSlot1;
CCMDS::CCMDS( ...class details not relevant... )
: CUSBDevice( ...ditto... )
{
// Must first call either CoInitialize or CoInitializeEx to initialize COM **DON'T NEED THIS BIT - COM ALREADY INITIALISED**
//HRESULT hr = S_OK;
//hr = CoInitialize( NULL );
//if ( hr != S_OK )
//{
// if ( hr == S_FALSE )
// {
// AfxMessageBox( "Com Already Initialised" );
// }
// else
// {
// AfxMessageBox( "Co-initialise Failed" );
// }
//}// Create and Initialise instances of the Agilent driver for
// each of the four U2635A I/O modules in the U2781A rack
spAgDrvrSlot1.CreateInstance( __uuidof( AgilentU265x ) );try
{
spAgDrvrSlot1->Initialize( "USBInstrument1", VARIANT_FALSE, VARIANT_TRUE, "" );
}
catch ( _com_error e )
{
AfxMessageBox( "Driver Initialise Failed" );
}HOWEVER, my code crashes at the
Initialize(USBInstrument1...)
statement with a Windows dialog sayingQuote:
First-chance exception at 0x755bb9bc in IOHandler.exe: Microsoft C++ exception: _com_error at memory location 0x001de4e0..
Why this code fails at all is a mystery but the big question is why does Windows crash with a dialog rather than my Try-Catch code catching the error in the controlled fashion I'd hoped for??
-
I have added some code (to an existing MFC/ATL application), to communicate with a piece of hardware that comes complete with com-based driver software. (Before I forget: I'm writing C++ in Visual Studio 2010, for Windows7). My code is based closely upon the sample code that the hardware manufacturer supplied, and is as follows;
#import "GlobMgr.dll" no_namespace // I/O funtionality
#import "IviDriverTypeLib.dll" no_namespace // IVI inherent functionality
#import "agu265x.dll" no_namespace // Instrument specific functionalityIAgilentU265xPtr spAgDrvrSlot1;
CCMDS::CCMDS( ...class details not relevant... )
: CUSBDevice( ...ditto... )
{
// Must first call either CoInitialize or CoInitializeEx to initialize COM **DON'T NEED THIS BIT - COM ALREADY INITIALISED**
//HRESULT hr = S_OK;
//hr = CoInitialize( NULL );
//if ( hr != S_OK )
//{
// if ( hr == S_FALSE )
// {
// AfxMessageBox( "Com Already Initialised" );
// }
// else
// {
// AfxMessageBox( "Co-initialise Failed" );
// }
//}// Create and Initialise instances of the Agilent driver for
// each of the four U2635A I/O modules in the U2781A rack
spAgDrvrSlot1.CreateInstance( __uuidof( AgilentU265x ) );try
{
spAgDrvrSlot1->Initialize( "USBInstrument1", VARIANT_FALSE, VARIANT_TRUE, "" );
}
catch ( _com_error e )
{
AfxMessageBox( "Driver Initialise Failed" );
}HOWEVER, my code crashes at the
Initialize(USBInstrument1...)
statement with a Windows dialog sayingQuote:
First-chance exception at 0x755bb9bc in IOHandler.exe: Microsoft C++ exception: _com_error at memory location 0x001de4e0..
Why this code fails at all is a mystery but the big question is why does Windows crash with a dialog rather than my Try-Catch code catching the error in the controlled fashion I'd hoped for??
-
I have added some code (to an existing MFC/ATL application), to communicate with a piece of hardware that comes complete with com-based driver software. (Before I forget: I'm writing C++ in Visual Studio 2010, for Windows7). My code is based closely upon the sample code that the hardware manufacturer supplied, and is as follows;
#import "GlobMgr.dll" no_namespace // I/O funtionality
#import "IviDriverTypeLib.dll" no_namespace // IVI inherent functionality
#import "agu265x.dll" no_namespace // Instrument specific functionalityIAgilentU265xPtr spAgDrvrSlot1;
CCMDS::CCMDS( ...class details not relevant... )
: CUSBDevice( ...ditto... )
{
// Must first call either CoInitialize or CoInitializeEx to initialize COM **DON'T NEED THIS BIT - COM ALREADY INITIALISED**
//HRESULT hr = S_OK;
//hr = CoInitialize( NULL );
//if ( hr != S_OK )
//{
// if ( hr == S_FALSE )
// {
// AfxMessageBox( "Com Already Initialised" );
// }
// else
// {
// AfxMessageBox( "Co-initialise Failed" );
// }
//}// Create and Initialise instances of the Agilent driver for
// each of the four U2635A I/O modules in the U2781A rack
spAgDrvrSlot1.CreateInstance( __uuidof( AgilentU265x ) );try
{
spAgDrvrSlot1->Initialize( "USBInstrument1", VARIANT_FALSE, VARIANT_TRUE, "" );
}
catch ( _com_error e )
{
AfxMessageBox( "Driver Initialise Failed" );
}HOWEVER, my code crashes at the
Initialize(USBInstrument1...)
statement with a Windows dialog sayingQuote:
First-chance exception at 0x755bb9bc in IOHandler.exe: Microsoft C++ exception: _com_error at memory location 0x001de4e0..
Why this code fails at all is a mystery but the big question is why does Windows crash with a dialog rather than my Try-Catch code catching the error in the controlled fashion I'd hoped for??
Something you might have missed: You can set the VC++ debugger up to catch exceptions where they're thrown and it generates a message like the dialogue you're getting. Are you running under the debugger with that setting enabled? If you're not running under a debugger then it's something else but I thought I'd try and clear that up first!
-
Presumably something in Windows is catching the error and not re-throwing it. You may wish to talk to the people who provided this code for more help.
Veni, vidi, abiit domum
Ok, got it thanks - Windows was catching the error and not re-throwing it because... I'm running in Debug and had Visual Studio set to catch all Exceptions :-O
-
Something you might have missed: You can set the VC++ debugger up to catch exceptions where they're thrown and it generates a message like the dialogue you're getting. Are you running under the debugger with that setting enabled? If you're not running under a debugger then it's something else but I thought I'd try and clear that up first!
Ooops, sorry - I missed your reply earlier! Yes, you were correct - thank-you :thumbsup: Feeling like a newbie (again) :(
-
Ooops, sorry - I missed your reply earlier! Yes, you were correct - thank-you :thumbsup: Feeling like a newbie (again) :(