Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:22:03+00:00 2026-06-01T21:22:03+00:00

To follow typical COM procedure, whenever any error occurs, one must do the following:

  • 0

To follow typical COM procedure, whenever any error occurs, one must do the following:

  1. Check the HRESULT with FAILED or similar, to see if an error occured.
  2. Create a variable to hold an IErrorInfo (typically CComPtr<IErrorInfo>)
  3. Call ::GetErrorInfo(0, &var).
  4. Get the human readable version of that by calling IErrorInfo::GetDescription.
  5. Convert the BSTR into a std::wstring.
  6. Convert the std::wstring into some form of char const*.
  7. Throw a user defined exception type which derives from std::exception which exposes bits 1, 5, and 6 above.

This all seems like a lot of boilerplate which has to go around pretty much every function call in COM.

I know the MSVC++ compiler provides a whole bunch of stuff to make messing with COM easier, such as ATL, and the compiler specific COM extensions _com_error, _com_raise_error and similar, but I’m not sure how to use these, or if they’re even intended to be used by user code.

Are there any typical strategies that are used to manage this complexity in an exception safe and race condition safe manner?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:22:04+00:00Added an answer on June 1, 2026 at 9:22 pm

    The “obvious” solution is a ComException. It can handle pretty much all steps – you just need to get obtain the HRESULT for the ctor and throw the resulting object (steps 1 and 7).

    You can even write

    HRESULT check(HRESULT hr)
    {
      if(FAILED(hr)) throw ComException(hr);
      return hr; // Success comes in different forms. 
    }
    

    to take care of step 7 for you. E.g. check(pUnk->QueryInterface(MyID, &pMyIf));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My typical usage of uploadify [www.uploadify.com] follows the following pattern: // to initialize $(#divid).uploadify({
Follow up to this question . I have the following code: string[] names =
Follow up question from Multi-core usage, threads, thread-pools . Are threads moved from one
For a typical user registration and membership system i follow in ASP.NET website i
Shouldn't follow AJAX request with JQuery work? $.getJSON('https://graph.facebook.com/138654562862101/feed?callback=onLoadJSONP'); I have defined a callback function
In a typical N-Tier app, my understanding of the tiers is as follows: DAL
I have a table set up as follows id origin destination carrier_id so typical
Follow up from: Directdraw: Rotate video stream I managed to preview the camera's video
Follow up to this question about GNU make : I've got a directory, flac
Follow up to this question for Facebook Friends.getAppUsers using Graph API that pulls friends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.