[This is preliminary documentation and subject to change.]
The CertAddStoreToCollection function adds a sibling certificate store to a collection certificate store.
#include <wincrypt.h>
BOOL WINAPI CertAddStoreToCollection(
HCERTSTORE hCollectionStore, // in
HCERTSTORE hSiblingStore, // in optional
DWORD dwUpdateFlag, // in
DWORD dwPriority // in
);
TRUE is returned if a new store was added to the collection of stores. FALSE is returned if the function failed.
A collection store has the same HCERTSTORE handle as a single store; thus, almost all functions that apply to any certificate store also apply to any collection store. Enumeration and find processes span all of the stores in a collection store; however, functions that add links to stores such as CertAddCertificateLinkToStore cannot be used with collection stores.
When a certificate, CRL, or CTL is added to a collection store, the list of sibling stores in the collection is searched in priority order to find the first store that allows adding. Adding is enabled if CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG was set in the CertAddStoreToCollection call. With any function that adds elements to a store, if a store that allows adding does not return success, the add function silently continues on to the next store.
When a collection store and its sibling stores are closed with CertCloseStore using the CERT_CLOSE_STORE_FORCE_FLAG, the collection store must be closed before its sibling stores. If the CERT_CLOSE_STORE_FORCE_FLAG is not used, the stores may be closed in any order.
// handle_error() is a function defined in a separate file.
HCERTSTORE hCollectionStore;
HCERTSTORE hSiblingStore;
// Open the collection store. For details, see CertOpenStore.
if(hCollectionStore = CertOpenStore(
CERT_STORE_PROV_COLLECTION,
0, // For CERT_STORE_PROV_COLLECTION,
// the rest of the parameters
// must be 0 or NULL.
NULL,
0,
NULL))
// The collection store opened. Continue.
printf("Opened the COLLECTION Store\n");
else
handle_error("Error opening Store from disk.");
// Open a sibling store. For details, see CertOpenStore.
if(hsiblingstore = CertOpenStore(
CERT_STORE_PROV_MEMORY, // For the memory provider type,
0, // the rest of the parameters must
NULL, // be 0 or NULL.
0,
NULL))
// The memory store to be a sibling store opened. Continue.
printf("Memory store open. \n");
else
handle_error("Memory store not open.");
// Add the sibling store to the collection.
if(CertAddStoreToCollection(
hCollectionStore,
hSiblingStore,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, // dwUpdateFlag
3 // Store priority
// in the collection.
))
// The sibling store was added to the collection. Continue.
printf("A sibling store has been added to the collection.\n");
else
handle_error("The sibling store was not added to the collection.");
//
// Work with certificates in the collection store and close the
// stores.
// Note that a find on the collection store will locate
// contexts in any of its sibling stores.
//
Windows NT: Requires version 5.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.