CertGetStoreProperty

[This is preliminary documentation and subject to change.]

The CertGetStoreProperty function gets a store property.

#include <wincrypt.h>
BOOL CertGetStoreProperty(
  HCERTSTORE hCertStore,           // in
  DWORD dwPropId,                  // in
  void *pvData,                    // out
  DWORD *pcbData                   // in, out 
);
 

Parameters

hCertStore
Handle for a certificate store.
dwPropId
DWORD indicating one of a range of user defined store properties. These values should be outside the current range of values for predefined context properties. Currently, user defined pwPropId values should begin at 4096.

There is one predefined store property, CERT_STORE_LOCALIZED_NAME_PROP_ID, the localized name of the store.

pvData
Pointer to a buffer that receives the data as determined by dwPropId. For CERT_STORE_LOCALIZED_NAME_PROP_ID, the localized name of the store, pvData points to a NULL terminated unicode, wide character string. For other dwPropIds, pvData points to an array of bytes.

This parameter can be NULL to set the size of this information for memory allocation purposes. For more information, see Common In/Out Parameter Conventions.

pcbData
Pointer to a DWORD that specifies the size, in bytes, of the buffer pointed to by the pvData parameter. When the function returns, the variable pointed to by the pcbData parameter contains the number of bytes stored in the buffer. This parameter can be NULL, only if pvData is NULL.

Return Values

If the store property is found the function returns TRUE. pvDate points to the property and pcbData points to the length of the string. If the store property is not found, the function returns FALSE and GetLastError returns CRYPT_E_NOT_FOUND.

Remarks

Store property IDs are properties applicable to an entire store. They are not properties on an individual certificate, CRL, or CTL context. Currently, no store properties are persisted.

Example

//
// Example code for CertSetStoreProperty and CertGetStoreProperty
//
//
// handle_error is a function defined in a separate file.
//
HCERTSTORE hCertStore;
void *pvData=NULL;
DWORD cbData;
CRYPT_DATA_BLOB Property_Name_Blob;

// Open the MY certificate store. 
// See CertOpenStore for details.
if ( hCertStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
0,
NULL,
CERT_SYSTEM_STORE_CURRENT_USER,
L"MY"))
printf("The MY store is open. Continue. \n");
else
handle_error("The MY store did not open.");
// Prepare a data strucute to set a store property.
// Initialize the members of the CRYPT_DATA_BLOB.  
Property_Name_Blob.pbData =(BYTE *) L"The name of MY Store";
Property_Name_Blob.cbData = (wcslen((LPWSTR) Property_Name_Blob.pbData)+1) * sizeof(WCHAR);
// Set the store's localized name property.
if (CertSetStoreProperty(
hCertStore,
CERT_STORE_LOCALIZED_NAME_PROP_ID,
0,
&Property_Name_Blob)
printf("The name of the store has been set. Continue. \n");
else
handle_error("Setting the store's localized name failed.");
// Call CerGetStorePropertyt a first time
// to get the length of the store name string to be returned
if(CertGetStoreProperty(
hCertStore,
CERT_STORE_LOCALIZED_NAME_PROP_ID,
    NULL,     // NULL on the first call  
              // to establish the length of the string to
              // to be returned.
&cbData)))
printf("The first call succeed. Continue.\n");
else
handle_error("The first call to the function failed.");
// cbData is the length of a string to be allocated. 
// Allocate the space for the string and call the function a 
//  the second time.
if(pvData = malloc(cbData)
printf("Memory is allocated. Continue. \n");
else
handle_error("Memory was not allocated.");
if(CertGetStoreProperty(
hCertStore,
CERT_STORE_LOCALIZED_NAME_PROP_ID,
pvData,
&cbData))
printf("The second call to the function worked. Continue.\n");
else
handle_error("The second call to CertGetStoreProperty failed.");
// Print the name of the store.
printf("The localized name is %S.\n",pvData);
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.

See Also

CertSetStoreProperty