Share via


BCryptEnumContexts 函式 (bcrypt.h)

[BCryptEnumContexts 可用於需求一節中指定的操作系統。 後續版本可能會變更或無法使用。]

BCryptEnumContexts 函式會取得指定組態數據表中內容的標識碼。

語法

NTSTATUS BCryptEnumContexts(
  [in]      ULONG           dwTable,
  [in, out] ULONG           *pcbBuffer,
  [in, out] PCRYPT_CONTEXTS *ppBuffer
);

參數

[in] dwTable

識別要從中擷取內容的組態數據表。 這可以是下列其中一個值。

意義
CRYPT_LOCAL
從本機計算機組態數據表擷取內容。
CRYPT_DOMAIN
這個值無法使用。

[in, out] pcbBuffer

在專案上, ULONG 變數的位址包含 ppBuffer 所指向緩衝區的大小,以位元組為單位。 如果這個大小不夠大,無法保存內容標識符集,此函式將會失敗並 STATUS_BUFFER_TOO_SMALL

這個函式傳回之後,這個值會包含複製到 ppBuffer 緩衝區的位元元組數目。

[in, out] ppBuffer

接收此函式所擷取之內容集 之CRYPT_CONTEXTS 結構的指標位址。 由參數所指向的值包含這個緩衝區的大小。

如果此參數所指向的值是 NULL,此函式會配置所需的記憶體。 當不再需要此記憶體時,必須將此指標傳遞至 BCryptFreeBuffer 函 式來釋放。

如果此參數為 NULL,則此函式會將所需的大小,以位元組為單位,放在 由STATUS_BUFFER_TOO_SMALL參數 所指向的變數中,並傳回 STATUS_BUFFER_TOO_SMALL

傳回值

傳回狀態代碼,指出函式的成功或失敗。

可能的傳回碼包括但不限於下列專案。

傳回碼 Description
STATUS_SUCCESS
函式成功。
STATUS_INVALID_PARAMETER
一或多個參數無效。
STATUS_NO_MEMORY
發生記憶體配置失敗。
STATUS_BUFFER_TOO_SMALL
ppBuffer 參數不是 NULL而由其所指向的值不夠大,無法保存一組內容。

備註

BCryptEnumContexts 只能在使用者模式中呼叫。

範例

下列範例示範如何使用 BCryptEnumContexts 函式來配置 ppBuffer 緩衝區的記憶體。

#ifndef NT_SUCCESS
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
#endif

NTSTATUS EnumContexts_SystemAlloc()
{
    NTSTATUS status;
    ULONG uSize = 0;
    PCRYPT_CONTEXTS pContexts = NULL;
    
    // Get the contexts for the local computer. 
    // CNG allocates the memory.
    status = BCryptEnumContexts(CRYPT_LOCAL, &uSize, &pContexts);
    if(NT_SUCCESS(status))
    {
        // Enumerate the context identifiers.
        for(ULONG i = 0; i < pContexts->cContexts; i++)
        {
            wprintf(pContexts->rgpszContexts[i]);
            wprintf(L"\n");
        }

        // Free the buffer.
        BCryptFreeBuffer(pContexts);
    }

    return status;
}

下列範例示範如何使用 BCryptEnumContexts 函式為 ppBuffer 緩衝區配置您自己的記憶體。

#ifndef NT_SUCCESS
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
#endif

NTSTATUS EnumContexts_SelfAlloc()
{
    NTSTATUS status;
    ULONG uSize = 0;
    
    // Get the required size of the buffer.
    status = BCryptEnumContexts(CRYPT_LOCAL, &uSize, NULL);
    if(STATUS_BUFFER_TOO_SMALL == status)
    {
        // Allocate the buffer.
        PCRYPT_CONTEXTS pContexts = (PCRYPT_CONTEXTS)HeapAlloc(
            GetProcessHeap(), 
            HEAP_ZERO_MEMORY, 
            uSize);
        if(pContexts)
        {
            // Get the contexts for the local machine.
            status = BCryptEnumContexts(
                CRYPT_LOCAL, 
                &uSize, 
                &pContexts);
            if(NT_SUCCESS((status))
            {
                // Enumerate the context identifiers.
                for(ULONG i = 0; i < pContexts->cContexts; i++)
                {
                    wprintf(pContexts->rgpszContexts[i]);
                    wprintf(L"\n");
                }
            }

            // Free the buffer.
            HeapFree(GetProcessHeap(), 0, pContexts);
            pContexts = NULL;
        }
        else
        {
            status = STATUS_NO_MEMORY;
        }
    }

    return status;
}

規格需求

需求
最低支援的用戶端 Windows Vista [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 [僅限傳統型應用程式]
目標平台 Windows
標頭 bcrypt.h
程式庫 Bcrypt.lib
Dll Bcrypt.dll

另請參閱

BCryptFreeBuffer

CRYPT_CONTEXTS