CertEnumCertificatesInStore

A version of this page is also available for

Windows Embedded CE 6.0 R3

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_CONTEXT structure 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 pPrevCertContext parameter to the pointer returned by a previous call to the function.

    The enumeration skips any certificate previously deleted by the CertDeleteCertificateFromStore function.

Return Value

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

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

Value Description

E_INVALIDARG

The handle in the hCertStore parameter is not the same as that in the certificate context pointed to by the pPrevCertContext parameter.

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 pPrevCertContext parameter on a subsequent call. Otherwise, the pointer must be freed by calling the CertFreeCertificateContext function. A pPrevCertContext parameter that is not NULL is always freed by the CertFreeCertificateContext function, even for an error.

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

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

Reference

CertDeleteCertificateFromStore
CertDuplicateCertificateContext
CertFindCertificateInStore
CertFreeCertificateContext
CERT_CONTEXT