Here is some code that maybe of use 2 u:
I ripped it out of my Certificate Manager class:
Basically first function initializes, ie gets the handle, second one
actually adds the certificate, you must do it before you fire up your
IE instance.
// Initialize the testing certificate store and personal certificate
store
BOOL CCertMgr::InitCertStore()
{
// Testing store: myTestStore
if (!(m_hCertStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM, //cert provider
0, // not used
NULL,//uses default crypt provider
CERT_SYSTEM_STORE_CURRENT_USER, //specify system store registry
location
L"myTestStore" // Store name as Unicode string
)))
{
return FALSE;
}
// Personal store
if ((m_hMyStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
0,
NULL,
CERT_SYSTEM_STORE_CURRENT_USER,
L"MY"// Opens System store
)))
return TRUE;
return FALSE;
}
Here I add a certificate to do personal store
// Add the testing certificate to the personal store
BOOL CCertMgr::AddCertToPersonalStore()
{
BOOL bAddOK = FALSE;
if (m_hMyStore == NULL || m_pMyCert == NULL)
return FALSE;
bAddOK = CertAddCertificateContextToStore(m_hMyStore, m_pMyCert,
CERT_STORE_ADD_NEW, NULL);
if (!bAddOK)
{
DWORD dwError = GetLastError();
if (dwError == CRYPT_E_EXISTS)
bAddOK = TRUE;
else if (dwError == E_INVALIDARG)
bAddOK = FALSE;
}
else
{
m_bNeedToDelete = TRUE;
}
return bAddOK;
} |