[This is preliminary documentation and subject to change.]
The CertControlStore function allows an application to be notified when there is a difference between the contents of a cached store and the contents of the store that is persisted to storage.
CertControlStore also provides re-synchronization of the cached store if necessary, and provides a means to commit changes made in the cached store to persisted storage. Additional functionality is planned.
#include <wincrypt.h>
BOOL WINAPI CertControlStore(
HCERTSTORE hCertStore, // in
DWORD dwFlags, // in
DWORD dwCtrlType, // in
void const *pvCtrlPara // in
);
CERT_STORE_CTRL_COMMIT_FORCE_FLAG(0x1) forces the contents of the cache memory store to be copied to permanent storage even if it has not been changed.
CERT_STORE_CTRL_COMMIT_CLEAR_FLAG(0x2) inhibits the copying the contents of the cache memory store to permanent storage even when the store is closed.
For dwCtrlType CERT_STORE_CTRL_NOTIFY_CHANGE and CERT_STORE_CTRL_RESYNC,.dwflags is not used and must be set to 0.
If dwCtrlType is CERT_STORE_CTRL_RESYNC or CERT_STORE_CTRL_COMMIT, pvCtrlPara is not used and should be set to NULL.
If dwCtrlType is CERT_STORE_NOTIFY_CHANGE, the function returns TRUE if a HANDLE for the event signal was successfully set up. FALSE is returned if the event HANDLE was not set up.
If dwCtrlType is CERT_STORE_CTRL_RESYNC, the function returns TRUE if the re-synchronization succeeded and FALSE if the re-synchronization failed.
If dwCtrlType is CERT_STORE_CTRL_COMMIT, the function returns TRUE to indicate the successful completion of the commit to persisted storage and FALSE if the commit failed.
Some providers may not support specific control types. In these cases, CertControlStore returns FALSE and GetLastError is set to ERROR_NOT_SUPPORTED.
Re-synchronization of a store may be done at any time. It need not follow a signaled notify change event.
CERT_STORE_CTRL_NOTIFY_CHANGE is supported on registry based store providers via the RegNotifyChangeKeyValue function.
HANDLE hEvent;
HCERTSTORE hCertStore;
BOOL fSignal;
// Initalize the event.
hEvent=CreateEvent(
NULL,
FALSE, // Manual reset is FALSE.
FALSE, // The initial state of the event is FALSE.
NULL);
// Open the MY system store. For details, see CertOpenStore.
if(hCertStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM_A, 0, NULL, 0, "MY"))
printf("The MY store is open.\n");
else
handle_error("The MY store was not opened.");
// Call CertControlStore the first time with
// CERT_CONTROL_STORE_NOTIFY_CHANGE.
if(CertControlStore(
hCertStore, // The store to be controlled
0, // Not used
CERT_STORE_CTRL_NOTIFY_CHANGE, // Control action type
&hEvent)) // Points to the event Handle.
// When a change is detected,
// a signal is written to the
// space pointed to by
// hHandle.
printf("Notify change worked \n");
else
handle_error("Notify change failed. \n");
// Wait for the store to change.
If(WAIT_OBJECT_0 == WaitForSingleObjectEx(
hEvent,
INFINITE, // number of milliseconds to wait
FALSE))
fSignal = TRUE;
else
fSignal = FALSE;
if (fSignal)
// The store has changed.
// Call the function a second time with CERT_STORE_CTRL_RESYNC
if(CertControlStore(
hCertStore, // in, The store to be controlled
0, // in, Not used.
CERT_STORE_CTRL_RESYNC, // in, Control action type
NULL)) // in, Not used with re-sync
printf("Re-sync worked. \n");
else
handle_error("Re-sync failed.");
else
{
printf("The store was not changed \n");
printf("Re-sync not needed. \n");
}
Windows NT: Requires version 5.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CreateEvent, WaitForSingleObjectEx