Export (0) Print
Expand All

ICertEncodeCRLDistInfo::Encode method

The Encode method performs Abstract Syntax Notation One (ASN.1) encoding on a certificate revocation list (CRL) distribution information array stored in the COM object and returns the ASN.1-encoded extension.

Before using this method, you must call the Reset method to size the array and the SetNameCount and SetNameEntry methods to set each element in each distribution point structure.

Syntax


HRESULT Encode(
  [out]  BSTR *pbstrBinary
);

Parameters

pbstrBinary [out]

A pointer to a BSTR that will contain the encoded CRL distribution information extension. When you have finished using the BSTR, free it by calling the SysFreeString function.

Return value

C++

If the method succeeds, the method returns S_OK.

If the method fails, it returns an HRESULT value that indicates the error. For a list of common error codes, see Common HRESULT Values.

VB

The return value is the ASN.1-encoded string that represents the CRL distribution information array.

Examples


    HRESULT hr = 0;
    ICertEncodeCRLDistInfo *pDistInfo = NULL;
    BSTR bstrEMailAddress = NULL;

    hr = CoInitialize(NULL);
    hr = CoCreateInstance(__uuidof(CCertEncodeCRLDistInfo), 
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(ICertEncodeCRLDistInfo), 
                          (void**)&pDistInfo);
    if (FAILED(hr))
    {
        printf("CoCreateInstance failed: 0x%x\n", hr);
        // handle error, release resources
    }

    // Set the array size that the CertEnableCRLDistInfo object 
    // contains to one.
    hr = pDistInfo->Reset(1);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::Reset failed: 0x%x\n", hr);
        // handle error, release resources
    }

    // Specify that the first element of the pDistInfo array will 
    // contain two names.
    hr = pDistInfo->SetNameCount(0, 2);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::SetNameCount "
            "failed: 0x%x\n", hr);
        // handle error, release resources
    }

    // Specify the first name as an email address. For example,
    // "someone@example.com". Add the name as the
    // first name in the first element of the pDistInfo array.
    bstrEMailAddress = SysAllocString(L"<EMAILADDRESSHERE>");
    if (NULL == bstrEMailAddress)
    {
        printf("Memory allocation failed for bstrEMailAddress\n");
        // handle error, release resources
    }

    hr = pDistInfo->SetNameEntry(0, 0, CERT_ALT_NAME_RFC822_NAME, 
        bstrEMailAddress);
    SysFreeString(bstrEMailAddress);
    bstrEMailAddress = NULL;
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::SetNameEntry "
            "failed: 0x%x\n", hr);
        // handle error, release resources
    }


    // Specify the second name as an email address. For example, 
    // "someone@example.com". Add the name as the second name in the
    // first element of the pDistInfo array.
    bstrEMailAddress = SysAllocString(L"<EMAILADDRESSHERE>");
    if (NULL == bstrEMailAddress)
    {
        printf("Memory allocation failed for bstrEMailAddress\n");
        // handle error, release resources
    }

    hr = pDistInfo->SetNameEntry(0, 1, CERT_ALT_NAME_RFC822_NAME, 
        bstrEMailAddress);
    SysFreeString(bstrEMailAddress);
    bstrEMailAddress = NULL;
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::SetNameEntry "
            "failed: 0x%x\n", hr);
        // handle error, release resources
    }


    LONG DPCount = 0;
    LONG NameCount = 0;
    LONG NameChoice = 0;

    // Get the number of elements in the pDistInfo array.
    // Loop through the array, printing all the names 
    // associated with each element.
    hr = pDistInfo->GetDistPointCount(&DPCount);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::GetDistPointCount "
            "failed: 0x%x\n", hr);
        // handle error, release resources
    }
    for (LONG i=0; i<DPCount; i++)
    {
        hr = pDistInfo->GetNameCount(i, &NameCount);
        if (FAILED(hr))
        {
            printf("ICertEncodeCRLDistInfo::GetNameCount "
                "failed: 0x%x\n", hr);
            // handle error, release resources
        }
        for (LONG j=0; j<NameCount; j++)
        {
            hr = pDistInfo->GetNameChoice(i, j, &NameChoice);
            if (FAILED(hr))
            {
                printf("ICertEncodeCRLDistInfo::GetNameChoice "
                    "failed: 0x%x\n", hr);
                // handle error, release resources
            }
            printf("DP[%d] Name[%d] %s an email address.\n", i, j,
                   (CERT_ALT_NAME_RFC822_NAME == NameChoice) 
                   ? "is" : "is not");

            hr = pDistInfo->GetName(i, j, &bstrEMailAddress);
            if (FAILED(hr))
            {
                printf("ICertEncodeCRLDistInfo::GetName "
                    "failed: 0x%x\n", hr);
                // handle error, release resources
            }
            printf("DP[%d] Name[%d] is %ws\n", i, j, 
                bstrEMailAddress);
            SysFreeString(bstrEMailAddress);
            bstrEMailAddress = NULL;
        }
    }

    // Encode the dist info from the CertEncodeCRLDistInfo 
    // object into a BSTR. You can store the names for later use.
    BSTR bstrEncoded = NULL;
    hr = pDistInfo->Encode(&bstrEncoded);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::Encode failed: 0x%x\n", hr);
        // handle error, release resources
    }
    pDistInfo->Release();
    pDistInfo = NULL;

    hr = CoCreateInstance(__uuidof(CCertEncodeCRLDistInfo), 
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(ICertEncodeCRLDistInfo), 
                          (void**)&pDistInfo);
    if (FAILED(hr))
    {
        printf("CoCreateInstance failed: 0x%x\n", hr);
        // handle error, release resources
    }

    // Decode the encoded dist info into the new 
    // CertEncodeCRLDistInfo object.
    hr = pDistInfo->Decode(bstrEncoded);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::Decode failed: 0x%x\n", hr);
        // handle error, release resources
    }
    SysFreeString(bstrEncoded);
    bstrEncoded = NULL;

    DPCount = 0;
    NameCount = 0;
    NameChoice = 0;

    // Get the number of elements in the pDistInfo array.
    // Loop through the array, printing all the names 
    // associated with each element.
    hr = pDistInfo->GetDistPointCount(&DPCount);
    if (FAILED(hr))
    {
        printf("ICertEncodeCRLDistInfo::GetDistPointCount "
            "failed: 0x%x\n", hr);
        // handle error, release resources
    }
    for (LONG i=0; i<DPCount; i++)
    {
        hr = pDistInfo->GetNameCount(i, &NameCount);
        if (FAILED(hr))
        {
            printf("ICertEncodeCRLDistInfo::GetNameCount "
                "failed: 0x%x\n", hr);
            // handle error, release resources
        }
        for (LONG j=0; j<NameCount; j++)
        {
            hr = pDistInfo->GetNameChoice(i, j, &NameChoice);
            if (FAILED(hr))
            {
                printf("ICertEncodeCRLDistInfo::GetNameChoice "
                    "failed: 0x%x\n", hr);
                // handle error, release resources
            }
            printf("DP[%d] Name[%d] %s an email address.\n", i, j,
                (CERT_ALT_NAME_RFC822_NAME == NameChoice) ? 
                "is" : "is not");

            hr = pDistInfo->GetName(i, j, &bstrEMailAddress);
            if (FAILED(hr))
            {
                printf("ICertEncodeCRLDistInfo::GetName "
                    "failed: 0x%x\n", hr);
                // handle error, release resources
            }
            printf("DP[%d] Name[%d] is %ws\n", i, j, 
                bstrEMailAddress);
            SysFreeString(bstrEMailAddress);
            bstrEMailAddress = NULL;
        }
    }

    pDistInfo->Release();



Requirements

Minimum supported client

None supported

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Certenc.h (include Certsrv.h)

Library

Certidl.lib

DLL

Certenc.dll

IID

IID_ICertEncodeCRLDistInfo is defined as 01958640-bbff-11d0-8825-00a0c903b83c

See also

ICertEncodeCRLDistInfo
ICertEncodeCRLDistInfo::Reset
ICertEncodeCRLDistInfo::SetNameCount
ICertEncodeCRLDistInfo::SetNameEntry

 

 

Community Additions

ADD
Show:
© 2014 Microsoft