CertGetStoreProperty 函式 (wincrypt.h)

CertGetStoreProperty 函式會擷取存放區屬性。

語法

BOOL CertGetStoreProperty(
  [in]      HCERTSTORE hCertStore,
  [in]      DWORD      dwPropId,
  [out]     void       *pvData,
  [in, out] DWORD      *pcbData
);

參數

[in] hCertStore

開啟 證書存儲的句柄。

[in] dwPropId

指出其中一個範圍存放區屬性。 有一個預先定義的存放區屬性,CERT_STORE_LOCALIZED_NAME_PROP_ID存放區的當地語系化名稱。

使用者定義的屬性必須超出預先定義內容屬性的目前值範圍。 目前,使用者定義的 dwPropId 值從 4,096 開始。

[out] pvData

緩衝區的指標,接收 由 dwPropId 決定的數據。 對於 CERT_STORE_LOCALIZED_NAME_PROP_ID,這是存放區的當地語系化名稱, pvData 會指向以 Null 結尾的 Unicode 寬字元字串。 針對其他 dwPropIds,pvData 會指向位元組陣列。

此參數可以是 NULL ,可針對記憶體配置目的設定此資訊的大小。 如需詳細資訊,請參閱 擷取未知長度的數據

[in, out] pcbData

DWORD 值的指標,指定 pvData 緩衝區的大小,以位元組為單位。 當函式傳回時, DWORD 值會包含儲存在緩衝區中的位元元組數目。

傳回值

如果函式成功,函式會傳回非零。

如果函式失敗,它會傳回零。

如果找到存放區屬性,函式會傳回非零的 pvData 指向 屬性,而 azureData 會指向字串的長度。 如果找不到 store 屬性,函式會傳回零, 而 GetLastError 會傳回CRYPT_E_NOT_FOUND。

備註

市集屬性標識碼是適用於整個存放區的屬性。 它們不是個別 憑證證書吊銷清單 (CRL) 或憑證 信任清單 (CTL) 內容的屬性。 目前,不會保存任何存放區屬性。

若要尋找市集的當地語系化名稱,您也可以使用 CryptFindLocalizedName 函式。

範例

下列範例顯示查詢其本機名稱屬性的存放區。 類似的程式代碼可用來擷取其他存放區屬性。 如需使用此函式的完整範例,請參閱 範例 C 程序:設定和取得證書儲存屬性

#include <windows.h>
#include <stdio.h>
#include <Wincrypt.h>


//--------------------------------------------------------------------
// Declare and initialize variables.
void *pvData = NULL;
DWORD cbData = 0;

//--------------------------------------------------------------------
// Call CertGetStoreProperty a first time
// to get the length of the store name string to be returned.
// hCertStore is a previously assigned HCERTSTORE variable that
// represents an open certificate store.
if(CertGetStoreProperty(
    hCertStore,
    CERT_STORE_LOCALIZED_NAME_PROP_ID,
    NULL,     // NULL on the first call  
              // to establish the length of the string
              // to be returned
    &cbData))
{
     printf("The length of the property is %d. \n",cbData);
}
else
{
     printf("The length of the property was not calculated.\n");
     exit(1);
}

//--------------------------------------------------------------------
// cbData is the length of a string to be allocated. 
// Allocate the space for the string and call the function a 
// second time.
if(pvData = malloc(cbData))
{
     printf("%d bytes of memory allocated.\n",cbData);
}
else
{
     printf("Memory was not allocated.\n");
     exit(1);
}

// Call CertGetStoreProperty a second time
// to copy the local store name into the pvData buffer.
if(CertGetStoreProperty(
    hCertStore,
    CERT_STORE_LOCALIZED_NAME_PROP_ID,
    pvData,
    &cbData))
{
     printf("The localized name is %S.\n",pvData);
}
else
{
     printf("CertGetStoreProperty failed.\n");
     exit(1);
}

// Free memory when done.
if (pvData)
    free(pvData);

規格需求

需求
最低支援的用戶端 Windows XP [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2003 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 wincrypt.h
程式庫 Crypt32.lib
Dll Crypt32.dll

另請參閱

CertSetStoreProperty

證書存儲函式