Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. _com_error not caught by 'Try-Catch' code

_com_error not caught by 'Try-Catch' code

Scheduled Pinned Locked Moved C / C++ / MFC
c++questioncsharpvisual-studiocom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Grove
    wrote on last edited by
    #1

    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 functionality

    IAgilentU265xPtr 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 saying

    Quote:

    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??

    L A 2 Replies Last reply
    0
    • M Mike Grove

      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 functionality

      IAgilentU265xPtr 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 saying

      Quote:

      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??

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M Mike Grove

        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 functionality

        IAgilentU265xPtr 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 saying

        Quote:

        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??

        A Offline
        A Offline
        Aescleal
        wrote on last edited by
        #3

        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!

        M 1 Reply Last reply
        0
        • L Lost User

          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

          M Offline
          M Offline
          Mike Grove
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • A Aescleal

            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!

            M Offline
            M Offline
            Mike Grove
            wrote on last edited by
            #5

            Ooops, sorry - I missed your reply earlier! Yes, you were correct - thank-you :thumbsup: Feeling like a newbie (again) :(

            A 1 Reply Last reply
            0
            • M Mike Grove

              Ooops, sorry - I missed your reply earlier! Yes, you were correct - thank-you :thumbsup: Feeling like a newbie (again) :(

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              No probs - I only thought about it as I had the same problem last week :-)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups