Platform SDK: Certificate Enrollment Control

The Certificate Enrollment Control Instantiated in C++

The Certificate Enrollment Control is provided to C and C++ developers by the header file xenroll.h and the link library uuid.lib.

The following example uses CoCreateInstance to create an instance of the Certificate Enrollment Control object. When the object is no longer needed, it is freed from memory by a call to the Release method.

Example in C++

#include <xenroll.h>

HRESULT __cdecl main()
{
    // pointer to interface object
    ICEnroll * pEnroll = NULL;

    // variable for return value
    HRESULT    hr;

    // Initialize COM.
    hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );

    // Check status.
    if ( FAILED( hr ) )
    {
        printf("Failed CoInitializeEx - [%x]\n", hr);
        goto error;
    }

    // Create an instance of the object.
    hr = CoCreateInstance( CLSID_CEnroll,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_ICEnroll,
                           (void **)&pEnroll);

    // Check status.
    if ( FAILED( hr ) )
    {
        printf("Failed CoCreateInstance - pEnroll [%x]\n", hr);
        goto error;
    }
    else
    {
        // Successfully instantiated object.
        printf("Obtained pointer to Enrollment interface\n");
        // Use object as needed.
        // ...
    }

error:

    // Done processing.
    // Clean up resources.
    if ( NULL != pEnroll )
        pEnroll->Release();

    // Free COM resources.
    CoUninitialize();

    return hr;
}

Beginning with Microsoft® Windows® 2000, a second interface, ICEnroll2, is supported. The ICEnroll2 interface is derived from ICEnroll, so all methods and properties supported by ICEnroll are supported by ICEnroll2. Additionally, several new methods and properties are supported by ICEnroll2. To use the ICEnroll2 interface, declare a pointer of type ICEnroll2, and use the IID of IID_ICEnroll2 in the call to CoCreateInstance. For example:

ICEnroll2 * pEnroll2 = NULL;

hr = CoCreateInstance( CLSID_CEnroll,
                       NULL,
                       CLSCTX_INPROC_SERVER,
                       IID_ICEnroll2,
                       (void **)&pEnroll2);
// Check hr for success (not shown here).
// Use object as needed.
// …
// Done processing, free resources associated with this object.
if ( NULL != pEnroll2 )
    pEnroll2->Release();

Beginning with Microsoft® Windows® 2000, a third interface, ICEnroll3, is supported. The ICEnroll3 interface is derived from ICEnroll2, so all methods and properties supported by ICEnroll2 (and therefore ICEnroll) are supported by ICEnroll3. Additionally, several new methods and properties are supported by ICEnroll3. To use the ICEnroll3 interface, declare a pointer of type ICEnroll3, and use the IID of IID_ICEnroll3 in the call to CoCreateInstance. For example:

ICEnroll3 * pEnroll3 = NULL;

hr = CoCreateInstance( CLSID_CEnroll,
                       NULL,
                       CLSCTX_INPROC_SERVER,
                       IID_ICEnroll3,
                       (void **)&pEnroll3);
// Check hr for success (not shown here).
// Use object as needed.
// …
// Done processing; free resources associated with this object.
if ( NULL != pEnroll3 )
    pEnroll3->Release();