PREfast Warning 221 (Windows CE 5.0)

Send Feedback

221 - Implicit cast between semantically different integer types.
Additional Information: Comparing HRESULT to an integer 
Recommended Fix: Consider using SUCCEEDED or FAILED macro instead.
  • Note   For this warning, the SCODE type is equivalent to HRESULT.

This warning indicates that an HRESULT is being compared against an integer. This can reflect some confusion about HRESULT behavior.

In most cases, this warning is caused when code expects a function to return an integer (using –1 as a failure value) when the function actually returns an HRESULT.

It is also worth noting that some values that are intended to function as HRESULTs are not actually typed that way.

Example

Defective Source

if (SomeFunction() == 4) {
    return S_FALSE;
}

return S_OK;

Corrected Source

if (SUCCEEDED(SomeFunction())) {
    return S_FALSE;
}

return S_OK;

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.