运行错误,错误码:
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE (INTERNET_ERROR_BASE + 18)
代码如下:
LPWSTR pswzFirstCert = L"sss";// Subject of the first
// certificate.
HCERTSTORE hSystemStore; // The system store handle
PCCERT_CONTEXT pDesiredCert;
pDesiredCert = NULL;
if(hSystemStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM, // The system store will be a
// virtual store.
0, // Encoding type not need with this PROV.
NULL, // Accept the default HCRYPTPROV.
CERT_SYSTEM_STORE_CURRENT_USER,
L"ROOT")) // System store name.//MY CA ROOT SPC 四种
{
printf("Opened the MY system store. \n");
}
else
{
}
//-------------------------------------------------------------------
// Get a certificate that has the string "Full Test Cert" in its subject.
if(pDesiredCert)
CertFreeCertificateContext(pDesiredCert);
if(pDesiredCert=CertFindCertificateInStore(
hSystemStore,
X509_ASN_ENCODING, // Use X509_ASN_ENCODING.
0, // No dwFlags needed.
CERT_FIND_SUBJECT_STR, // Find a certificate with a
// subject that matches the string
// in the next parameter.
pswzFirstCert, // The Unicode string to be found
// in a certificate's subject.
NULL)) // NULL is used so that the
// search will begin at the
// beginning of the certificate
// store.
{
printf("The %S certificate was found. \n",pswzFirstCert);
}
else
{
printf("The %S certificate was not found. \n",pswzFirstCert);
}