以 C++ 具現化的憑證註冊控制項
下列 C++ 範例會初始化 COM、建立 憑證註冊控制項的實例、使用憑證註冊控制,以及釋放資源。
C++ 中的範例
下列範例會建立 憑證註冊控制項 的實例,並顯示 MyStoreName 屬性的值。 此範例使用 ICEnroll4 介面。
#include <windows.h>
#include <stdio.h>
#include <xenroll.h>
// Copyright (C) Microsoft. All rights reserved.
HRESULT __cdecl main(void)
{
HRESULT hr = 0;
ICEnroll4 *pEnroll = NULL;
BSTR bstrStoreName = NULL;
// Initialize COM.
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
if ( FAILED( hr ) )
{
printf("Failed CoInitializeEx - [0x%x]\n", hr);
exit(hr);
}
// Create an instance of the object.
hr = CoCreateInstance( __uuidof(CEnroll),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(ICEnroll4),
(void **)&pEnroll);
if ( FAILED( hr ) )
{
printf("Failed CoCreateInstance - pEnroll [0x%x]\n", hr);
exit(hr);
}
hr = pEnroll->get_MyStoreName(&bstrStoreName);
if (SUCCEEDED(hr))
{
printf("The value of MyStoreName is %ws\n", bstrStoreName);
}
else
{
printf("pEnroll->GetMyStoreName failed: 0x%x\n", hr);
}
pEnroll->Release();
SysFreeString(bstrStoreName);
CoUninitialize();
return hr;
}