Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
ATL
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

ATLENSURE

This macro is used to validate parameters passed to a function.

ATLENSURE(booleanExpression); 
ATLENSURE_THROW(booleanExpression, hr);

booleanExpression

Specifies a boolean expression to be tested.

hr

Specifies an error code to return.

These macros provide a mechanism to detect and notify the user of incorrect parameter usage.

The macro calls ATLASSERT and if the condition fails calls AtlThrow.

In the ATLENSURE case, AtlThrow is called with E_FAIL.

In the ATLENSURE_THROW case, AtlThrow is called with the specified HRESULT.

The difference between ATLENSURE and ATLASSERT is that ATLENSURE throws an exception in Release builds as well as in Debug builds.

void MyImportantFunction(char* psz)
{
   ATLENSURE(NULL != psz);

   char mysz[64];
   strcpy_s(mysz, sizeof(mysz), psz);
}

Header: afx.h

Community Additions

ADD
Show:
© 2015 Microsoft