ICertServerPolicy::EnumerateExtensions 方法 (certif.h)

EnumerateExtensions方法會擷取目前延伸模組 (OID) 的物件識別碼,並將內部列舉指標移至下一個延伸模組。

語法

HRESULT EnumerateExtensions(
  [out] BSTR *pstrExtensionName
);

參數

[out] pstrExtensionName

BSTR的指標,其中包含目前延伸模組的 OID。

傳回值

C++

如果方法成功,方法會傳回S_OK,而 pstrExtensionName 參數包含目前擴充功能的 OID。 如果已列舉最後一個延伸模組,則會傳回S_FALSE的值。

若要使用此方法,請建立 BSTR 類型的變數、將變數設定為 Null,並將此變數的位址傳遞為 pstrExtensionName

當您完成 使用 BSTR時,請呼叫 SysFreeString 函式來釋放它。

如果方法失敗,它會傳回指出錯誤的 HRESULT 值。 如需常見錯誤碼的清單,請參閱 一般 HRESULT 值

VB

傳回包含延伸模組 OID 的字串,如果已列舉最後一個延伸模組,則傳回空字串。

備註

這個方法會列舉資料庫中記錄的憑證延伸模組,即使已停用且不會出現在憑證中。 若要判斷延伸模組是否已停用,請使用 GetCertificateExtensionFlags 來測試延伸模組的EXTENSION_DISABLE_FLAG位。

完成列舉時,呼叫 EnumerateExtensionsClose 方法來釋放列舉呼叫所使用的資源。

範例

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

BSTR     bstrExt = NULL;
VARIANT  varExt;
LONG     ExtFlags;
HRESULT  hr;

VariantInit(&varExt);

// Enumerate the extensions.
while (S_OK ==
      (hr = pCertServerPol->EnumerateExtensions(&bstrExt)))
{
  // Retrieve the extension data.
  if (FAILED(pCertServerPol->GetCertificateExtension(
                             bstrExt,
                             PROPTYPE_BINARY,
                             &varExt)))
      printf("Failed GetCertificateExtension\n");
  else
  {
     // Retrieve the extension flags.
    if (FAILED(pCertServerPol->GetCertificateExtensionFlags(
                               &ExtFlags)))
        printf("Failed GetCertificateExtensionFlags\n");
    else
        // This sample will display the extension OID string,
        // the extension flags (in hex) and
        // the length of the BSTR binary ASN-encode extension.
        printf("Extension: %ws\tFlags:%x\tLength:%u\n",
               bstrExt,
               ExtFlags,
               SysStringByteLen(varExt.bstrVal));
  }
}
// Determine if hr was S_FALSE, meaning the enumeration 
// was completed, or some other error.
if (S_FALSE != hr)
    printf("Failed EnumerateExtensions - %x\n", hr);
// Free BSTR resource.
if (NULL != bstrExt)
    SysFreeString(bstrExt);
// Free VARIANT resource.
    VariantClear(&varExt);

規格需求

   
最低支援的用戶端 都不支援
最低支援的伺服器 Windows Server 2003 [僅限桌面應用程式]
目標平台 Windows
標頭 certif.h (包含 Certsrv.h)
程式庫 Certidl.lib
Dll Certcli.dll

另請參閱

EnumerateExtensionsClose

EnumerateExtensionsSetup

GetCertificateExtension

GetCertificateExtensionFlags

ICertServerPolicy