Compartilhar via


PREfast Warning 214 (Windows CE 5.0)

Send Feedback

214 - Cast between semantically different integer types.
Additional Information: HRESULT to Boolean

**Note   **For this warning, the SCODE type is equivalent to HRESULT.

This warning indicates that an HRESULT is being explicitly cast to a Boolean type.

This is likely to give undesirable results. For example, the typical success value for HRESULT, S_OK, is FALSE when tested as a Boolean.

In most cases, the SUCCEEDED or FAILED macro should be used to test the value of an HRESULT.

In some cases, the program can be attempting to reuse a Boolean local variable to store HRESULTs as well. This practice is often error prone. It is much safer and likely more efficient to use a separate HRESULT variable.

Example

Defective Source

HRESULT hr;
LPMALLOC pMalloc;

hr = CoGetMalloc(1, &pMalloc);

if (FAILED(hr)) {
    return ((BOOL)hr);
}

/* ... */

return hr;

Corrected Source

HRESULT hr;
LPMALLOC pMalloc;

hr = CoGetMalloc(1, &pMalloc);

if (FAILED(hr)) {
    return FALSE;
}
/* ... */

return TRUE;

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.