C6215
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
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.
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
.
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 6215
{
// 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