Warning C6215
Cast between semantically different integer types: a Boolean type to HRESULT
This warning indicates that a Boolean is being cast to an HRESULT
. Boolean types indicate success by a non-zero value, whereas success (S_OK
) in HRESULT
is indicated by a value of 0. Casting a Boolean type to an HRESULT
and then using it in a test expression will yield an incorrect result.
Remarks
This warning frequently occurs when a Boolean is used as an argument to SUCCEEDED
or FAILED
macro, which explicitly casts their arguments to an HRESULT
.
Code analysis name: CAST_BOOL_TO_HRESULT
Example
The following code generates this warning:
#include <windows.h>
BOOL IsEqual(REFGUID, REFGUID);
void f( REFGUID riid1, REFGUID riid2 )
{
if (SUCCEEDED( IsEqual( riid1, riid2 ) )) //warning C6215
{
// success code ...
}
else
{
// failure code ...
}
}
Generally, the SUCCEEDED
or FAILED
macros should only be applied to HRESULT
.
To correct this warning, use the following code:
#include <windows.h>
BOOL IsEqual(REFGUID, REFGUID);
void f( REFGUID riid1, REFGUID riid2 )
{
if (IsEqual( riid1, riid2 ) == TRUE)
{
// code for riid1 == riid2
}
else
{
// code for riid1 != riid2
}
}
For more information, see SUCCEEDED Macro and FAILED Macro