http://technet.microsoft...u/subscriptions/aa380290 //------------------------------------------------------------------- // Declare and initialize variables.
HCERTSTORE hCertStore = NULL;
PCCERT_CONTEXT pCertContext = NULL;
//------------------------------------------------------------------- // Open a certificate store.
if ( hCertStore = CertOpenSystemStore( NULL, "MY"))
{ printf("The MY store has been opened.\n"); }
else
{ printf("A certificate store was not opened.\n"); exit(1); }
//-------------------------------------------------------------------
// Use CertEnumCertificatesInStore to retrieve a certificate
// from the open store. pCertContext is NULL to retrieve the first
// certificate in the store.
if (
pCertContext =
CertEnumCertificatesInStore( hCertStore, pCertContext))
{ //---------------------------------------------------------------
// A certificate was retrieved, display it.
if (!CryptUIDlgViewContext( CERT_STORE_CERTIFICATE_CONTEXT,
// Display a certificate.
pCertContext,
// Pointer to the
// certificate.
NULL, NULL, 0, NULL))
{ printf("CryptUIDlgViewContext call failed.\n"); exit(1); }
} else
{ printf("No certificate available. The store may be empty.\n"); exit(1);
}
//-------------------------------------------------------------------
// When all processing is completed, clean up.
if(pCertContext)
{ CertFreeCertificateContext(pCertContext); }
if(hCertStore)
{ if (!CertCloseStore(hCertStore,0))
{ printf("No certificate available. The store may " "be empty.\n"); exit(1); }
}