Error Checking in C++
In C++, every Certificate Services method directly returns an HRESULT value that indicates whether the method call succeeded or failed. If the call failed, the return value indicates why it failed.
The following example shows how the returned HRESULT values can be used for error checking. For example error codes, see Common HRESULT Values.
HRESULT hr;
BSTR strAttributeName;
BSTR strAttributeValue = NULL;
if(!(strAttributeName = SysAllocString(L"TheAttribute")))
{
printf("Could not allocate memory for attribute name.\n");
exit(1);
}
hr = pICertServerPolicy->GetRequestAttribute(
strAttributeName,
&strAttributeValue);
if(S_OK != hr) // Check to determine whether method failed
{
if (E_INVALIDARG == hr)
{
//... Do something to recover from errors and so on.
}
}
// Free BSTRs when finished.
if (NULL != strAttributeName)
SysFreeString(strAttributeName);
if (NULL != strAttributeValue)
SysFreeString(strAttributeValue);