Partilhar via


Erro ao verificar em C++

Em C++, cada método de Serviços de Certificados retorna diretamente um valor de HRESULT que indica se a chamada de método foi bem-sucedida ou falhou. Se a chamada falhou, o valor de retorno indica por que falhou.

O exemplo a seguir mostra como os valores retornados HRESULT podem ser usados para verificação de erros. Por exemplo, códigos de erro, consulte 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);