Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

C6225

warning C6225: Implicit cast between semantically different integer types: assigning 1 or TRUE to HRESULT. Consider using S_FALSE instead

This warning indicates that an HRESULT is being assigned or initialized with a value of an explicit 1. Boolean types indicate success by a non-zero value; whereas success (S_OK) in HRESULT is indicated by a value of 0.This warning is frequently caused by accidental confusion of Boolean and HRESULT types. To indicate success, the symbolic constant S_OK should be used.

Example

In the following code, assignment of HRESULT generates this warning:

#include <windows.h>

VOID f( )
{
  HRESULT hr;
  LPMALLOC pMalloc;
  
  if (SUCCEEDED(CoGetMalloc(1, &pMalloc)))
  {
    // code ...
    hr = S_OK;  
  }
  else
  {
    // code ...
    hr = 1;
  }
}

To correct this warning, use the following code:

VOID f( )
{
  HRESULT hr;
  LPMALLOC pMalloc;
  
  if (SUCCEEDED(CoGetMalloc(1, &pMalloc)))
  {
    hr = S_OK;
    // code ...
  }
  else
  {
    hr = S_FALSE;
    // code ...
  }
}

For this warning, the SCODE type is equivalent to HRESULT.

To indicate failure, E_FAIL, or another constant, should be used.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft