Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 1) C4165

'HRESULT' is being converted to 'bool'; are you sure this is what you want?

When using an HRESULT in an if statement, the HRESULT will be converted to a bool unless you explicitly test for the variable as an HRESULT. This warning is off by default.

The following sample generates C4165

// C4165.cpp
// compile with: /W1
#include <windows.h>
#pragma warning(1:4165)

extern HRESULT hr;
int main() {
   if (hr) {
   // try either of the following ...
   // if (FAILED(hr)) { // C4165 expected
   // if (hr != S_OK) {
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft