ホーム › Security.Cryptography › BCryptAddContextFunction
BCryptAddContextFunction
関数CNGコンテキストの指定インターフェイスに暗号機能を追加する。
シグネチャ
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptAddContextFunction(
BCRYPT_TABLE dwTable,
LPCWSTR pszContext,
BCRYPT_INTERFACE dwInterface,
LPCWSTR pszFunction,
DWORD dwPosition
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwTable | BCRYPT_TABLE | in |
| pszContext | LPCWSTR | in |
| dwInterface | BCRYPT_INTERFACE | in |
| pszFunction | LPCWSTR | in |
| dwPosition | DWORD | in |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptAddContextFunction(
BCRYPT_TABLE dwTable,
LPCWSTR pszContext,
BCRYPT_INTERFACE dwInterface,
LPCWSTR pszFunction,
DWORD dwPosition
);[DllImport("bcrypt.dll", ExactSpelling = true)]
static extern int BCryptAddContextFunction(
uint dwTable, // BCRYPT_TABLE
[MarshalAs(UnmanagedType.LPWStr)] string pszContext, // LPCWSTR
uint dwInterface, // BCRYPT_INTERFACE
[MarshalAs(UnmanagedType.LPWStr)] string pszFunction, // LPCWSTR
uint dwPosition // DWORD
);<DllImport("bcrypt.dll", ExactSpelling:=True)>
Public Shared Function BCryptAddContextFunction(
dwTable As UInteger, ' BCRYPT_TABLE
<MarshalAs(UnmanagedType.LPWStr)> pszContext As String, ' LPCWSTR
dwInterface As UInteger, ' BCRYPT_INTERFACE
<MarshalAs(UnmanagedType.LPWStr)> pszFunction As String, ' LPCWSTR
dwPosition As UInteger ' DWORD
) As Integer
End Function' dwTable : BCRYPT_TABLE
' pszContext : LPCWSTR
' dwInterface : BCRYPT_INTERFACE
' pszFunction : LPCWSTR
' dwPosition : DWORD
Declare PtrSafe Function BCryptAddContextFunction Lib "bcrypt" ( _
ByVal dwTable As Long, _
ByVal pszContext As LongPtr, _
ByVal dwInterface As Long, _
ByVal pszFunction As LongPtr, _
ByVal dwPosition As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BCryptAddContextFunction = ctypes.windll.bcrypt.BCryptAddContextFunction
BCryptAddContextFunction.restype = ctypes.c_int
BCryptAddContextFunction.argtypes = [
wintypes.DWORD, # dwTable : BCRYPT_TABLE
wintypes.LPCWSTR, # pszContext : LPCWSTR
wintypes.DWORD, # dwInterface : BCRYPT_INTERFACE
wintypes.LPCWSTR, # pszFunction : LPCWSTR
wintypes.DWORD, # dwPosition : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bcrypt.dll')
BCryptAddContextFunction = Fiddle::Function.new(
lib['BCryptAddContextFunction'],
[
-Fiddle::TYPE_INT, # dwTable : BCRYPT_TABLE
Fiddle::TYPE_VOIDP, # pszContext : LPCWSTR
-Fiddle::TYPE_INT, # dwInterface : BCRYPT_INTERFACE
Fiddle::TYPE_VOIDP, # pszFunction : LPCWSTR
-Fiddle::TYPE_INT, # dwPosition : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bcrypt")]
extern "system" {
fn BCryptAddContextFunction(
dwTable: u32, // BCRYPT_TABLE
pszContext: *const u16, // LPCWSTR
dwInterface: u32, // BCRYPT_INTERFACE
pszFunction: *const u16, // LPCWSTR
dwPosition: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bcrypt.dll")]
public static extern int BCryptAddContextFunction(uint dwTable, [MarshalAs(UnmanagedType.LPWStr)] string pszContext, uint dwInterface, [MarshalAs(UnmanagedType.LPWStr)] string pszFunction, uint dwPosition);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcrypt_BCryptAddContextFunction' -Namespace Win32 -PassThru
# $api::BCryptAddContextFunction(dwTable, pszContext, dwInterface, pszFunction, dwPosition)#uselib "bcrypt.dll"
#func global BCryptAddContextFunction "BCryptAddContextFunction" sptr, sptr, sptr, sptr, sptr
; BCryptAddContextFunction dwTable, pszContext, dwInterface, pszFunction, dwPosition ; 戻り値は stat
; dwTable : BCRYPT_TABLE -> "sptr"
; pszContext : LPCWSTR -> "sptr"
; dwInterface : BCRYPT_INTERFACE -> "sptr"
; pszFunction : LPCWSTR -> "sptr"
; dwPosition : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "bcrypt.dll"
#cfunc global BCryptAddContextFunction "BCryptAddContextFunction" int, wstr, int, wstr, int
; res = BCryptAddContextFunction(dwTable, pszContext, dwInterface, pszFunction, dwPosition)
; dwTable : BCRYPT_TABLE -> "int"
; pszContext : LPCWSTR -> "wstr"
; dwInterface : BCRYPT_INTERFACE -> "int"
; pszFunction : LPCWSTR -> "wstr"
; dwPosition : DWORD -> "int"; NTSTATUS BCryptAddContextFunction(BCRYPT_TABLE dwTable, LPCWSTR pszContext, BCRYPT_INTERFACE dwInterface, LPCWSTR pszFunction, DWORD dwPosition)
#uselib "bcrypt.dll"
#cfunc global BCryptAddContextFunction "BCryptAddContextFunction" int, wstr, int, wstr, int
; res = BCryptAddContextFunction(dwTable, pszContext, dwInterface, pszFunction, dwPosition)
; dwTable : BCRYPT_TABLE -> "int"
; pszContext : LPCWSTR -> "wstr"
; dwInterface : BCRYPT_INTERFACE -> "int"
; pszFunction : LPCWSTR -> "wstr"
; dwPosition : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bcrypt = windows.NewLazySystemDLL("bcrypt.dll")
procBCryptAddContextFunction = bcrypt.NewProc("BCryptAddContextFunction")
)
// dwTable (BCRYPT_TABLE), pszContext (LPCWSTR), dwInterface (BCRYPT_INTERFACE), pszFunction (LPCWSTR), dwPosition (DWORD)
r1, _, err := procBCryptAddContextFunction.Call(
uintptr(dwTable),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszContext))),
uintptr(dwInterface),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFunction))),
uintptr(dwPosition),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction BCryptAddContextFunction(
dwTable: DWORD; // BCRYPT_TABLE
pszContext: PWideChar; // LPCWSTR
dwInterface: DWORD; // BCRYPT_INTERFACE
pszFunction: PWideChar; // LPCWSTR
dwPosition: DWORD // DWORD
): Integer; stdcall;
external 'bcrypt.dll' name 'BCryptAddContextFunction';result := DllCall("bcrypt\BCryptAddContextFunction"
, "UInt", dwTable ; BCRYPT_TABLE
, "WStr", pszContext ; LPCWSTR
, "UInt", dwInterface ; BCRYPT_INTERFACE
, "WStr", pszFunction ; LPCWSTR
, "UInt", dwPosition ; DWORD
, "Int") ; return: NTSTATUS●BCryptAddContextFunction(dwTable, pszContext, dwInterface, pszFunction, dwPosition) = DLL("bcrypt.dll", "int BCryptAddContextFunction(dword, char*, dword, char*, dword)")
# 呼び出し: BCryptAddContextFunction(dwTable, pszContext, dwInterface, pszFunction, dwPosition)
# dwTable : BCRYPT_TABLE -> "dword"
# pszContext : LPCWSTR -> "char*"
# dwInterface : BCRYPT_INTERFACE -> "dword"
# pszFunction : LPCWSTR -> "char*"
# dwPosition : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。