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

  • Home
  • SEARCH
  • 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 9047595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:56:58+00:00 2026-06-16T11:56:58+00:00

Short story is that I want this behavior: #if defined(DEBUG) || defined(_DEBUG) #define CHECK_HRESULT(x)

  • 0

Short story is that I want this behavior:

#if defined(DEBUG) || defined(_DEBUG)
#define CHECK_HRESULT(x)                                    \
{                                                           \
    HRESULT hr = (x);                                       \
    if (FAILED(hr))                                         \
    {                                                       \
        DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true);  \
    }                                                       \
}
#else
#define CHECK_HRESULT(x)    (x)
#endif

but I also want to save and return the HRESULT value for error checking in free builds. So basically, I want to be able to do something like:

HRESULT hr = CHECK_HRESULT(Some_Function_Call());

which will assign a value to hr for both free and check builds, but will also display a dialog box when an invalid HRESULT is returned for check builds. Yes, I know I could create an inline function, but then I would have to pass in a string for L#x which means copying the statement twice in my code, which is something I would like to avoid (also, the same issue arises when you try to write a macro that just takes hr in as the input). I would also like to avoid something like:

#if defined(DEBUG) || defined(_DEBUG)
#define CHECK_HRESULT(x)    (x);                            \
{                                                           \
    HRESULT hr = (x);                                       \
    if (FAILED(hr))                                         \
    {                                                       \
        DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true);  \
    }                                                       \
}
#else
#define CHECK_HRESULT(x)    (x)
#endif

since x could very easily be a function that allocates memory or does something important, and calling that function twice would cause severe unwanted behavior, especially between checked and free builds. Also, it almost goes without saying that I would like to avoid the assumption that there is already an HRESULT named hr… I’ve gone down that dark path before. I do realize that it would probably be safe to assign a value of S_OK by default in checked builds since the program will most likely crash anyway, but that just seems sloppy to me.

Anyway, thanks for ya’lls help!

  • 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-16T11:56:59+00:00Added an answer on June 16, 2026 at 11:56 am

    gcc has an extension allowing full code blocks in expressions but I’m assuming you need this for VC++? In which case, could you define a macro “CHECK_ASSIGN_HRESULT(v,x)” that does the checks but also assigns the result to v?

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

Sidebar

Related Questions

Long story short, I have a SQL file that I want to import as
Short story: I want to make slight changes to the behavior of a MainClass,
Long story short, we found files promoting prescription drugs on our server that we
Long story short, I'm developing a theme template for a blog that enables you
Long story short, I'm making a custom Swing component that's basically a JTable with
Long story short, the database I'm using needs to get looked at. Until that
So long story short, i have some forms (2) of them that, need different
Long story short, I have an ASP.NET application I'm trying to debug and at
I'm going to make a long story short. It's been a while that I
Long story short: var o="before"; x = function() //this needs to be an anonymous

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.