Compartilhar via


PREfast Warning 217 (Windows CE 5.0)

Send Feedback

217 - Implicit cast between semantically different integer types.
Additional Information: testing HRESULT with 'not'. 
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 tested with the C not (!) operator.

This is almost certain to give undesirable results.

The typical success value for HRESULT (S_OK) is FALSE when tested as a Boolean.

If the intent is to see whether the HRESULT is a success status, use the SUCCEEDED macro instead.

If the intent is to check specifically for the S_OK HRESULT (such as ignoring other possible success values), an explicit comparison to S_OK is appropriate.

Example

Defective Source

HRESULT hr;

hr = SomeFunction();

if (!hr) {
    return 1;
} else {
    return -1;
}

Corrected Source

HRESULT hr;

hr = SomeFunction();

if (hr == S_OK) {
    return 1;
} else {
    return -1;
}

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.