BOOL CertAddCertificateContextToStore(
[in] HCERTSTORE hCertStore,
[in] PCCERT_CONTEXT pCertContext,
[in] DWORD dwAddDisposition,
[out, optional] PCCERT_CONTEXT *ppStoreContext
Parameters
[in] hCertStore
Handle of a certificate store.
[in] pCertContext
A pointer to the
CERT_CONTEXT structure to be added to the store.
[in] dwAddDisposition
Specifies the action to take if a matching certificate or a link to a matching certificate already exists in the store. Currently defined disposition values and their uses are as follows.
Value
Meaning
CERT_STORE_ADD_ALWAYS
The function makes no check for an existing matching certificate or link to a matching certificate. A new certificate is always added to the store. This can lead to duplicates in a store.
If a matching certificate or a link to a matching certificate exists, the operation fails.
GetLastError returns the CRYPT_E_EXISTS code.
If a matching certificate or a link to a matching certificate exists and the NotBefore
time of the existing context is equal to or greater than the
NotBefore time of the new context being added, the operation fails and GetLastError returns the CRYPT_E_EXISTS code.
If the NotBefore
time of the existing context is less than the
NotBefore time of the new context being added, the existing certificate or link is deleted and a new certificate is created and added to the store. If a matching certificate or a link to a matching certificate does not exist, a new link is added.
If certificate revocation lists (CRLs) or certificate trust list (CTLs) are being compared, the ThisUpdate time is used.
If a matching certificate or a link to a matching certificate exists and the NotBefore
time of the existing context is equal to or greater than the
NotBefore time of the new context being added, the operation fails and GetLastError returns the CRYPT_E_EXISTS code.
If the NotBefore
time of the existing context is less than the
NotBefore time of the new context being added, the existing context is deleted before creating and adding the new context. The new added context inherits properties from the existing certificate.
If CRLs or CTLs are being compared, the ThisUpdate time is used.
If a matching certificate or a link to a matching certificate exists, that existing certificate or link is used and properties from the new certificate are added. The function does not fail, but it does not add a new context. If pCertContext is not NULL, the existing context is duplicated.
If a matching certificate or a link to a matching certificate does not exist, a new certificate is added.
[out, optional] ppStoreContext
A pointer to a pointer to the copy to be made of the certificate that was added to the store.
The ppStoreContext parameter can be NULL, indicating that the calling application does not require a copy of the added certificate. If a copy is made, it must be freed by using
CertFreeCertificateContext.
Return value
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. For extended error information, call
GetLastError. Some possible error codes follow.
Return code
Description
Errors from the called functions,
CertAddEncodedCertificateToStore and
CertSetCertificateContextProperty, can be propagated to this function.
The certificate context is not duplicated using CertDuplicateCertificateContext. Instead, the function creates a new copy of the context and adds it to the store.
In addition to the encoded certificate, CertDuplicateCertificateContext also copies the context's properties, with the exception of the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_CONTEXT_PROP_ID properties.
To remove the certificate context from the certificate store, use the CertDeleteCertificateFromStore function.
Note The order of the certificate context may not be preserved within the store.
To access a specific certificate you must iterate across the certificates in the store.
Requirements