The CertDuplicateStore function duplicates a store handle by incrementing the reference count. The reference count is used to keep track of the lifetime of the store.
#include <wincrypt.h>
HCERTSTORE WINAPI CertDuplicateStore(
HCERTSTORE hCertStore // in
);
Currently, a copy is not made of the handle, and the returned handle is the same as the handle that was input.
// handle_error() is a function defined in a separate file.
HCERTSTORE hCertStore; // The store to be duplicated.
HCERTSTORE hDupStore ; // The duplicate store to be.
// Open a file store as the certificate store to be duplicated.
// See CertOpenStore for details.
if (hCertStore = CertOpenStore(
CERT_STORE_PROV_FILENAME,0,NULL,0,L"teststor.sto"))
printf("The file store is open. Continue. \n");
else
handle_error("Store not opened");
// Duplicate the store.
if(hDupStore = CertDuplicateStore(hCertStore))
printf("The store is duplicated. Continue.\n");
else
handle_error("Duplication of the store failed.");
if (CertCloseStore(hDupStore,0))
printf("Closed the duplicate store.\n");
else
handle_error("Closing the duplicate store failed.");
if (CertCloseStore(hCertStore,0))
printf("Closed the original store.\n");
else
handle_error("Closing the original store failed.");
printf("Program completed successfully.\n");
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 95 OSR2 or later.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.