Win32 API 日本語リファレンス
ホームSecurity.Cryptography › BCryptQueryContextConfiguration

BCryptQueryContextConfiguration

関数
指定したCNGコンテキストの構成情報を取得する。
DLLbcrypt.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// bcrypt.dll
#include <windows.h>

NTSTATUS BCryptQueryContextConfiguration(
    BCRYPT_TABLE dwTable,
    LPCWSTR pszContext,
    DWORD* pcbBuffer,
    CRYPT_CONTEXT_CONFIG** ppBuffer   // optional
);

パラメーター

名前方向説明
dwTableBCRYPT_TABLEin

コンテキストが存在する構成テーブルを識別します。次のいずれかの値を指定できます。

意味
CRYPT_LOCAL
コンテキストはローカルマシンの構成テーブルに存在します。
CRYPT_DOMAIN
この値は使用できません。
pszContextLPCWSTRin構成情報を取得する対象のコンテキストの識別子を含む、null で終わる Unicode 文字列へのポインターです。
pcbBufferDWORD*inout

ULONG 変数のアドレスです。呼び出し時には、ppBuffer が指すバッファーのサイズ(バイト単位)を格納します。このサイズがコンテキスト情報を保持するのに十分でない場合、この関数は STATUS_BUFFER_TOO_SMALL で失敗します。

この関数が返った後、この変数には ppBuffer バッファーにコピーされたバイト数が格納されます。

ppBufferCRYPT_CONTEXT_CONFIG**outoptional

この関数が取得したコンテキスト構成情報を受け取る CRYPT_CONTEXT_CONFIG 構造体へのポインターのアドレスです。pcbBuffer パラメーターが指す値には、このバッファーのサイズが格納されます。

このパラメーターが指す値が NULL の場合、この関数は必要なメモリを割り当てます。このメモリは不要になった時点で、このポインターを BCryptFreeBuffer 関数に渡して解放する必要があります。

このパラメーターが NULL の場合、この関数は必要なサイズ(バイト単位)を pcbBuffer パラメーターが指す変数に格納し、STATUS_BUFFER_TOO_SMALL を返します。

このパラメーターの使用方法の詳細については、「解説」を参照してください。

戻り値の型: NTSTATUS

公式ドキュメント

指定された CNG コンテキストの現在の構成を取得します。

戻り値

関数の成功または失敗を示すステータスコードを返します。

返される可能性のあるコードには、次のものが含まれますが、これらに限定されません。

戻り値 説明
STATUS_SUCCESS
関数は成功しました。
STATUS_BUFFER_TOO_SMALL
ppBuffer パラメーターが NULL ではなく、かつ pcbBuffer パラメーターが指す値がコンテキストのセットを保持するのに十分な大きさではありません。
STATUS_INVALID_PARAMETER
1 つ以上のパラメーターが無効です。
STATUS_NO_MEMORY
メモリの割り当てに失敗しました。
STATUS_NOT_FOUND
指定されたコンテキストが見つかりませんでした。

解説(Remarks)

各コンテキストは構成情報のセットを 1 つだけ持つため、ppBuffer パラメーターは配列として使用されるように見えますが、この関数はこれを要素が 1 つだけの配列として扱います。次の例は、このパラメーターの使用方法を明確にするのに役立ちます。

// コンテキストの構成情報を取得します。
CRYPT_CONTEXT_CONFIG config;
ULONG uSize = sizeof(config);
PCRYPT_CONTEXT_CONFIG pConfig = &config;
status = BCryptQueryContextConfiguration(
    CRYPT_LOCAL, 
    pszContextID, 
    &uSize, 
    &pConfig);

BCryptQueryContextConfiguration はユーザーモードでのみ呼び出すことができます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// bcrypt.dll
#include <windows.h>

NTSTATUS BCryptQueryContextConfiguration(
    BCRYPT_TABLE dwTable,
    LPCWSTR pszContext,
    DWORD* pcbBuffer,
    CRYPT_CONTEXT_CONFIG** ppBuffer   // optional
);
[DllImport("bcrypt.dll", ExactSpelling = true)]
static extern int BCryptQueryContextConfiguration(
    uint dwTable,   // BCRYPT_TABLE
    [MarshalAs(UnmanagedType.LPWStr)] string pszContext,   // LPCWSTR
    ref uint pcbBuffer,   // DWORD* in/out
    IntPtr ppBuffer   // CRYPT_CONTEXT_CONFIG** optional, out
);
<DllImport("bcrypt.dll", ExactSpelling:=True)>
Public Shared Function BCryptQueryContextConfiguration(
    dwTable As UInteger,   ' BCRYPT_TABLE
    <MarshalAs(UnmanagedType.LPWStr)> pszContext As String,   ' LPCWSTR
    ByRef pcbBuffer As UInteger,   ' DWORD* in/out
    ppBuffer As IntPtr   ' CRYPT_CONTEXT_CONFIG** optional, out
) As Integer
End Function
' dwTable : BCRYPT_TABLE
' pszContext : LPCWSTR
' pcbBuffer : DWORD* in/out
' ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out
Declare PtrSafe Function BCryptQueryContextConfiguration Lib "bcrypt" ( _
    ByVal dwTable As Long, _
    ByVal pszContext As LongPtr, _
    ByRef pcbBuffer As Long, _
    ByVal ppBuffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BCryptQueryContextConfiguration = ctypes.windll.bcrypt.BCryptQueryContextConfiguration
BCryptQueryContextConfiguration.restype = ctypes.c_int
BCryptQueryContextConfiguration.argtypes = [
    wintypes.DWORD,  # dwTable : BCRYPT_TABLE
    wintypes.LPCWSTR,  # pszContext : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pcbBuffer : DWORD* in/out
    ctypes.c_void_p,  # ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('bcrypt.dll')
BCryptQueryContextConfiguration = Fiddle::Function.new(
  lib['BCryptQueryContextConfiguration'],
  [
    -Fiddle::TYPE_INT,  # dwTable : BCRYPT_TABLE
    Fiddle::TYPE_VOIDP,  # pszContext : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pcbBuffer : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "bcrypt")]
extern "system" {
    fn BCryptQueryContextConfiguration(
        dwTable: u32,  // BCRYPT_TABLE
        pszContext: *const u16,  // LPCWSTR
        pcbBuffer: *mut u32,  // DWORD* in/out
        ppBuffer: *mut *mut CRYPT_CONTEXT_CONFIG  // CRYPT_CONTEXT_CONFIG** optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("bcrypt.dll")]
public static extern int BCryptQueryContextConfiguration(uint dwTable, [MarshalAs(UnmanagedType.LPWStr)] string pszContext, ref uint pcbBuffer, IntPtr ppBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcrypt_BCryptQueryContextConfiguration' -Namespace Win32 -PassThru
# $api::BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
#uselib "bcrypt.dll"
#func global BCryptQueryContextConfiguration "BCryptQueryContextConfiguration" sptr, sptr, sptr, sptr
; BCryptQueryContextConfiguration dwTable, pszContext, varptr(pcbBuffer), varptr(ppBuffer)   ; 戻り値は stat
; dwTable : BCRYPT_TABLE -> "sptr"
; pszContext : LPCWSTR -> "sptr"
; pcbBuffer : DWORD* in/out -> "sptr"
; ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "bcrypt.dll"
#cfunc global BCryptQueryContextConfiguration "BCryptQueryContextConfiguration" int, wstr, var, var
; res = BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
; dwTable : BCRYPT_TABLE -> "int"
; pszContext : LPCWSTR -> "wstr"
; pcbBuffer : DWORD* in/out -> "var"
; ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; NTSTATUS BCryptQueryContextConfiguration(BCRYPT_TABLE dwTable, LPCWSTR pszContext, DWORD* pcbBuffer, CRYPT_CONTEXT_CONFIG** ppBuffer)
#uselib "bcrypt.dll"
#cfunc global BCryptQueryContextConfiguration "BCryptQueryContextConfiguration" int, wstr, var, var
; res = BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
; dwTable : BCRYPT_TABLE -> "int"
; pszContext : LPCWSTR -> "wstr"
; pcbBuffer : DWORD* in/out -> "var"
; ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bcrypt = windows.NewLazySystemDLL("bcrypt.dll")
	procBCryptQueryContextConfiguration = bcrypt.NewProc("BCryptQueryContextConfiguration")
)

// dwTable (BCRYPT_TABLE), pszContext (LPCWSTR), pcbBuffer (DWORD* in/out), ppBuffer (CRYPT_CONTEXT_CONFIG** optional, out)
r1, _, err := procBCryptQueryContextConfiguration.Call(
	uintptr(dwTable),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszContext))),
	uintptr(pcbBuffer),
	uintptr(ppBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function BCryptQueryContextConfiguration(
  dwTable: DWORD;   // BCRYPT_TABLE
  pszContext: PWideChar;   // LPCWSTR
  pcbBuffer: Pointer;   // DWORD* in/out
  ppBuffer: Pointer   // CRYPT_CONTEXT_CONFIG** optional, out
): Integer; stdcall;
  external 'bcrypt.dll' name 'BCryptQueryContextConfiguration';
result := DllCall("bcrypt\BCryptQueryContextConfiguration"
    , "UInt", dwTable   ; BCRYPT_TABLE
    , "WStr", pszContext   ; LPCWSTR
    , "Ptr", pcbBuffer   ; DWORD* in/out
    , "Ptr", ppBuffer   ; CRYPT_CONTEXT_CONFIG** optional, out
    , "Int")   ; return: NTSTATUS
●BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer) = DLL("bcrypt.dll", "int BCryptQueryContextConfiguration(dword, char*, void*, void*)")
# 呼び出し: BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
# dwTable : BCRYPT_TABLE -> "dword"
# pszContext : LPCWSTR -> "char*"
# pcbBuffer : DWORD* in/out -> "void*"
# ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "bcrypt" fn BCryptQueryContextConfiguration(
    dwTable: u32, // BCRYPT_TABLE
    pszContext: [*c]const u16, // LPCWSTR
    pcbBuffer: [*c]u32, // DWORD* in/out
    ppBuffer: [*c][*c]CRYPT_CONTEXT_CONFIG // CRYPT_CONTEXT_CONFIG** optional, out
) callconv(std.os.windows.WINAPI) i32;
proc BCryptQueryContextConfiguration(
    dwTable: uint32,  # BCRYPT_TABLE
    pszContext: WideCString,  # LPCWSTR
    pcbBuffer: ptr uint32,  # DWORD* in/out
    ppBuffer: ptr CRYPT_CONTEXT_CONFIG  # CRYPT_CONTEXT_CONFIG** optional, out
): int32 {.importc: "BCryptQueryContextConfiguration", stdcall, dynlib: "bcrypt.dll".}
pragma(lib, "bcrypt");
extern(Windows)
int BCryptQueryContextConfiguration(
    uint dwTable,   // BCRYPT_TABLE
    const(wchar)* pszContext,   // LPCWSTR
    uint* pcbBuffer,   // DWORD* in/out
    CRYPT_CONTEXT_CONFIG** ppBuffer   // CRYPT_CONTEXT_CONFIG** optional, out
);
ccall((:BCryptQueryContextConfiguration, "bcrypt.dll"), stdcall, Int32,
      (UInt32, Cwstring, Ptr{UInt32}, Ptr{CRYPT_CONTEXT_CONFIG}),
      dwTable, pszContext, pcbBuffer, ppBuffer)
# dwTable : BCRYPT_TABLE -> UInt32
# pszContext : LPCWSTR -> Cwstring
# pcbBuffer : DWORD* in/out -> Ptr{UInt32}
# ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> Ptr{CRYPT_CONTEXT_CONFIG}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t BCryptQueryContextConfiguration(
    uint32_t dwTable,
    const uint16_t* pszContext,
    uint32_t* pcbBuffer,
    void* ppBuffer);
]]
local bcrypt = ffi.load("bcrypt")
-- bcrypt.BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
-- dwTable : BCRYPT_TABLE
-- pszContext : LPCWSTR
-- pcbBuffer : DWORD* in/out
-- ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('bcrypt.dll');
const BCryptQueryContextConfiguration = lib.func('__stdcall', 'BCryptQueryContextConfiguration', 'int32_t', ['uint32_t', 'str16', 'uint32_t *', 'void *']);
// BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
// dwTable : BCRYPT_TABLE -> 'uint32_t'
// pszContext : LPCWSTR -> 'str16'
// pcbBuffer : DWORD* in/out -> 'uint32_t *'
// ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("bcrypt.dll", {
  BCryptQueryContextConfiguration: { parameters: ["u32", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer)
// dwTable : BCRYPT_TABLE -> "u32"
// pszContext : LPCWSTR -> "buffer"
// pcbBuffer : DWORD* in/out -> "pointer"
// ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t BCryptQueryContextConfiguration(
    uint32_t dwTable,
    const uint16_t* pszContext,
    uint32_t* pcbBuffer,
    void* ppBuffer);
C, "bcrypt.dll");
// $ffi->BCryptQueryContextConfiguration(dwTable, pszContext, pcbBuffer, ppBuffer);
// dwTable : BCRYPT_TABLE
// pszContext : LPCWSTR
// pcbBuffer : DWORD* in/out
// ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Bcrypt extends StdCallLibrary {
    Bcrypt INSTANCE = Native.load("bcrypt", Bcrypt.class);
    int BCryptQueryContextConfiguration(
        int dwTable,   // BCRYPT_TABLE
        WString pszContext,   // LPCWSTR
        IntByReference pcbBuffer,   // DWORD* in/out
        Pointer ppBuffer   // CRYPT_CONTEXT_CONFIG** optional, out
    );
}
@[Link("bcrypt")]
lib Libbcrypt
  fun BCryptQueryContextConfiguration = BCryptQueryContextConfiguration(
    dwTable : UInt32,   # BCRYPT_TABLE
    pszContext : UInt16*,   # LPCWSTR
    pcbBuffer : UInt32*,   # DWORD* in/out
    ppBuffer : CRYPT_CONTEXT_CONFIG**   # CRYPT_CONTEXT_CONFIG** optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BCryptQueryContextConfigurationNative = Int32 Function(Uint32, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
typedef BCryptQueryContextConfigurationDart = int Function(int, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
final BCryptQueryContextConfiguration = DynamicLibrary.open('bcrypt.dll')
    .lookupFunction<BCryptQueryContextConfigurationNative, BCryptQueryContextConfigurationDart>('BCryptQueryContextConfiguration');
// dwTable : BCRYPT_TABLE -> Uint32
// pszContext : LPCWSTR -> Pointer<Utf16>
// pcbBuffer : DWORD* in/out -> Pointer<Uint32>
// ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function BCryptQueryContextConfiguration(
  dwTable: DWORD;   // BCRYPT_TABLE
  pszContext: PWideChar;   // LPCWSTR
  pcbBuffer: Pointer;   // DWORD* in/out
  ppBuffer: Pointer   // CRYPT_CONTEXT_CONFIG** optional, out
): Integer; stdcall;
  external 'bcrypt.dll' name 'BCryptQueryContextConfiguration';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BCryptQueryContextConfiguration"
  c_BCryptQueryContextConfiguration :: Word32 -> CWString -> Ptr Word32 -> Ptr () -> IO Int32
-- dwTable : BCRYPT_TABLE -> Word32
-- pszContext : LPCWSTR -> CWString
-- pcbBuffer : DWORD* in/out -> Ptr Word32
-- ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let bcryptquerycontextconfiguration =
  foreign "BCryptQueryContextConfiguration"
    (uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* dwTable : BCRYPT_TABLE -> uint32_t *)
(* pszContext : LPCWSTR -> (ptr uint16_t) *)
(* pcbBuffer : DWORD* in/out -> (ptr uint32_t) *)
(* ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library bcrypt (t "bcrypt.dll"))
(cffi:use-foreign-library bcrypt)

(cffi:defcfun ("BCryptQueryContextConfiguration" bcrypt-query-context-configuration :convention :stdcall) :int32
  (dw-table :uint32)   ; BCRYPT_TABLE
  (psz-context (:string :encoding :utf-16le))   ; LPCWSTR
  (pcb-buffer :pointer)   ; DWORD* in/out
  (pp-buffer :pointer))   ; CRYPT_CONTEXT_CONFIG** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BCryptQueryContextConfiguration = Win32::API::More->new('bcrypt',
    'int BCryptQueryContextConfiguration(DWORD dwTable, LPCWSTR pszContext, LPVOID pcbBuffer, LPVOID ppBuffer)');
# my $ret = $BCryptQueryContextConfiguration->Call($dwTable, $pszContext, $pcbBuffer, $ppBuffer);
# dwTable : BCRYPT_TABLE -> DWORD
# pszContext : LPCWSTR -> LPCWSTR
# pcbBuffer : DWORD* in/out -> LPVOID
# ppBuffer : CRYPT_CONTEXT_CONFIG** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型