Dela via


C6216

warning C6216: compiler-inserted cast between semantically different integral types: a Boolean type to HRESULT

This warning indicates that a Boolean is being used as an HRESULT without being explicitly cast. Boolean types indicate success by a non-zero value; success (S_OK) in HRESULT is indicated by a value of 0. The typical failure value for functions that return a Boolean false is a success status when it is tested as an HRESULT. This is likely to lead to incorrect results.

Example

The following code generates this warning:

#include <windows.h>
BOOL IsEqual(REFGUID, REFGUID);

HRESULT f( REFGUID riid1, REFGUID riid2 )
{
  // code ...
  return IsEqual(riid1, riid2);  
}

To correct this warning, use the following code:

#include <windows.h>
BOOL IsEqual(REFGUID, REFGUID);

HRESULT f( REFGUID riid1, REFGUID riid2 )
{
  if (IsEqual(riid1, riid2) == TRUE)
  {
    // code ...
    return S_OK;
  }
  else
  {
    // code ...
    return E_FAIL;
  }
}

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

For more information, see SUCCEEDED Macro and FAILED Macro.