Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function retrieves the first or next certificate in a certificate store. Used in a loop, this function can retrieve in sequence all certificates in a certificate store.

Syntax

PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(
  HCERTSTORE 
hCertStore,
  PCCERT_CONTEXT 
pPrevCertContext
);

Parameters

hCertStore

[in] Handle to a certificate store.

pPrevCertContext

[in] Pointer to the CERT_CONTEXTstructure of the previous certificate context found.

This parameter must be NULL to begin the enumeration and get the first certificate in the store. Successive certificates are enumerated by setting the pPrevCertContextparameter to the pointer returned by a previous call to the function.

The enumeration skips any certificate previously deleted by the CertDeleteCertificateFromStorefunction.

Return Value

If the function succeeds, the return value is a pointer to the next CERT_CONTEXTstructure in the store. If no more certificates exist in the store, the function returns NULL.

For extended error information, call the GetLastErrorfunction. The following table shows some possible error codes.

Value Description

E_INVALIDARG

The handle in the hCertStoreparameter is not the same as that in the certificate context pointed to by the pPrevCertContextparameter.

CRYPT_E_NOT_FOUND

No certificates were found. This happens if the store is empty or if the function reached the end of the store's list.

Remarks

The returned pointer is freed when passed as the pPrevCertContextparameter on a subsequent call. Otherwise, the pointer must be freed by calling the CertFreeCertificateContextfunction. A pPrevCertContextparameter that is not NULL is always freed by the CertFreeCertificateContextfunction, even for an error.

A duplicate of the currently enumerated certificate can be made by calling the CertDuplicateCertificateContextfunction.

Requirements

Header wincrypt.h
Library crypt32.lib
Windows Embedded CE Windows CE 3.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also