签入C++时出错

在 C++ 中,每个证书服务方法直接返回一个 HRESULT 值,该值指示方法调用是成功还是失败。 如果调用失败,则返回值指示失败的原因。

以下示例演示如何将返回的 HRESULT 值用于错误检查。 有关错误代码示例,请参阅 常见 HRESULT 值

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);