다음을 통해 공유


C++에서 오류 확인

C++에서 모든 Certificate Services 메서드는 메서드 호출의 성공 여부를 나타내는 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);