CryptEnumKeyIdentifierProperties
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptEnumKeyIdentifierProperties(
const CRYPT_INTEGER_BLOB* pKeyIdentifier, // optional
DWORD dwPropId,
DWORD dwFlags,
LPCWSTR pwszComputerName, // optional
void* pvReserved, // optional
void* pvArg, // optional
PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pKeyIdentifier | CRYPT_INTEGER_BLOB* | inoptional | キー識別子を格納した CRYPT_HASH_BLOB 構造体へのポインターです。 pKeyIdentifier が NULL の場合、この関数はすべてのキー識別子を列挙します。 pKeyIdentifier が NULL でない場合、コールバック関数 pfnEnum は指定したキー識別子に対してのみ呼び出されます。 |
| dwPropId | DWORD | in | 列挙対象のプロパティ識別子を示します。 dwPropId がゼロに設定されている場合、この関数はすべてのプロパティを伴ってコールバック関数を呼び出します。 dwPropId がゼロ以外で、かつ pKeyIdentifier が NULL の場合、コールバック関数は指定したプロパティを持つキー識別子に対してのみ呼び出されます(pfnEnum の cProp パラメーターは 1 に設定されます)。そのプロパティを持たないキー識別子はすべてスキップされます。 任意の証明書プロパティ識別子を使用できます。 |
| dwFlags | DWORD | in | 既定では、CurrentUser のキー識別子の一覧が検索されます。CRYPT_KEYID_MACHINE_FLAG が設定されている場合は、LocalMachine(pwszComputerName が NULL の場合)またはリモートコンピューター(pwszComputerName が NULL でない場合)のキー識別子の一覧が検索されます。詳細については pwszComputerName を参照してください。 |
| pwszComputerName | LPCWSTR | inoptional | 検索対象となるリモートコンピューターの名前へのポインターです。dwFlags に CRYPT_KEYID_MACHINE_FLAG が設定されている場合、リモートコンピューターからキー識別子の一覧が検索されます。リモートコンピューターではなくローカルコンピューターを検索する場合は、pwszComputerName を NULL に設定します。 |
| pvReserved | void* | optional | 将来の使用のために予約されており、NULL でなければなりません。 |
| pvArg | void* | inoutoptional | コールバック関数に渡されるデータへのポインターです。型は void であり、アプリケーションが任意の情報を保持する構造体や引数を宣言、定義、初期化できるようにします。 |
| pfnEnum | PFN_CRYPT_ENUM_KEYID_PROP | in | 入力パラメーターに一致する各キー識別子エントリに対して実行される、アプリケーション定義のコールバック関数へのポインターです。コールバック関数のパラメーターの詳細については、CRYPT_ENUM_KEYID_PROP を参照してください。 |
戻り値の型: BOOL
公式ドキュメント
CryptEnumKeyIdentifierProperties 関数は、キー識別子とそのプロパティを列挙します。
戻り値
CryptEnumKeyIdentifierProperties 関数は、最後のキー識別子が列挙されるか、コールバック関数が FALSE を返すまで、CRYPT_ENUM_KEYID_PROP コールバック関数を繰り返し呼び出します。
メイン関数が成功した場合、この関数は 0 以外(TRUE)を返します。
関数が失敗した場合は 0(FALSE)を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。
列挙を継続するには、関数は TRUE を返します。
列挙を停止するには、関数は FALSE を返し、最終エラーコードを設定します。
解説(Remarks)
キー識別子は、証明書コンテキストと同じプロパティを持つことができます。
例
この関数を使用する例については、 Example C Program: Working with Key Identifiers を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptEnumKeyIdentifierProperties(
const CRYPT_INTEGER_BLOB* pKeyIdentifier, // optional
DWORD dwPropId,
DWORD dwFlags,
LPCWSTR pwszComputerName, // optional
void* pvReserved, // optional
void* pvArg, // optional
PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptEnumKeyIdentifierProperties(
IntPtr pKeyIdentifier, // CRYPT_INTEGER_BLOB* optional
uint dwPropId, // DWORD
uint dwFlags, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pwszComputerName, // LPCWSTR optional
IntPtr pvReserved, // void* optional
IntPtr pvArg, // void* optional, in/out
IntPtr pfnEnum // PFN_CRYPT_ENUM_KEYID_PROP
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptEnumKeyIdentifierProperties(
pKeyIdentifier As IntPtr, ' CRYPT_INTEGER_BLOB* optional
dwPropId As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pwszComputerName As String, ' LPCWSTR optional
pvReserved As IntPtr, ' void* optional
pvArg As IntPtr, ' void* optional, in/out
pfnEnum As IntPtr ' PFN_CRYPT_ENUM_KEYID_PROP
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' pKeyIdentifier : CRYPT_INTEGER_BLOB* optional
' dwPropId : DWORD
' dwFlags : DWORD
' pwszComputerName : LPCWSTR optional
' pvReserved : void* optional
' pvArg : void* optional, in/out
' pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP
Declare PtrSafe Function CryptEnumKeyIdentifierProperties Lib "crypt32" ( _
ByVal pKeyIdentifier As LongPtr, _
ByVal dwPropId As Long, _
ByVal dwFlags As Long, _
ByVal pwszComputerName As LongPtr, _
ByVal pvReserved As LongPtr, _
ByVal pvArg As LongPtr, _
ByVal pfnEnum As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptEnumKeyIdentifierProperties = ctypes.windll.crypt32.CryptEnumKeyIdentifierProperties
CryptEnumKeyIdentifierProperties.restype = wintypes.BOOL
CryptEnumKeyIdentifierProperties.argtypes = [
ctypes.c_void_p, # pKeyIdentifier : CRYPT_INTEGER_BLOB* optional
wintypes.DWORD, # dwPropId : DWORD
wintypes.DWORD, # dwFlags : DWORD
wintypes.LPCWSTR, # pwszComputerName : LPCWSTR optional
ctypes.POINTER(None), # pvReserved : void* optional
ctypes.POINTER(None), # pvArg : void* optional, in/out
ctypes.c_void_p, # pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptEnumKeyIdentifierProperties = Fiddle::Function.new(
lib['CryptEnumKeyIdentifierProperties'],
[
Fiddle::TYPE_VOIDP, # pKeyIdentifier : CRYPT_INTEGER_BLOB* optional
-Fiddle::TYPE_INT, # dwPropId : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # pwszComputerName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pvReserved : void* optional
Fiddle::TYPE_VOIDP, # pvArg : void* optional, in/out
Fiddle::TYPE_VOIDP, # pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptEnumKeyIdentifierProperties(
pKeyIdentifier: *const CRYPT_INTEGER_BLOB, // CRYPT_INTEGER_BLOB* optional
dwPropId: u32, // DWORD
dwFlags: u32, // DWORD
pwszComputerName: *const u16, // LPCWSTR optional
pvReserved: *mut (), // void* optional
pvArg: *mut (), // void* optional, in/out
pfnEnum: *const core::ffi::c_void // PFN_CRYPT_ENUM_KEYID_PROP
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CryptEnumKeyIdentifierProperties(IntPtr pKeyIdentifier, uint dwPropId, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string pwszComputerName, IntPtr pvReserved, IntPtr pvArg, IntPtr pfnEnum);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptEnumKeyIdentifierProperties' -Namespace Win32 -PassThru
# $api::CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)#uselib "CRYPT32.dll"
#func global CryptEnumKeyIdentifierProperties "CryptEnumKeyIdentifierProperties" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptEnumKeyIdentifierProperties varptr(pKeyIdentifier), dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum ; 戻り値は stat
; pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "sptr"
; dwPropId : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; pwszComputerName : LPCWSTR optional -> "sptr"
; pvReserved : void* optional -> "sptr"
; pvArg : void* optional, in/out -> "sptr"
; pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll" #cfunc global CryptEnumKeyIdentifierProperties "CryptEnumKeyIdentifierProperties" var, int, int, wstr, sptr, sptr, sptr ; res = CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum) ; pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "var" ; dwPropId : DWORD -> "int" ; dwFlags : DWORD -> "int" ; pwszComputerName : LPCWSTR optional -> "wstr" ; pvReserved : void* optional -> "sptr" ; pvArg : void* optional, in/out -> "sptr" ; pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptEnumKeyIdentifierProperties "CryptEnumKeyIdentifierProperties" sptr, int, int, wstr, sptr, sptr, sptr ; res = CryptEnumKeyIdentifierProperties(varptr(pKeyIdentifier), dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum) ; pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "sptr" ; dwPropId : DWORD -> "int" ; dwFlags : DWORD -> "int" ; pwszComputerName : LPCWSTR optional -> "wstr" ; pvReserved : void* optional -> "sptr" ; pvArg : void* optional, in/out -> "sptr" ; pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CryptEnumKeyIdentifierProperties(CRYPT_INTEGER_BLOB* pKeyIdentifier, DWORD dwPropId, DWORD dwFlags, LPCWSTR pwszComputerName, void* pvReserved, void* pvArg, PFN_CRYPT_ENUM_KEYID_PROP pfnEnum) #uselib "CRYPT32.dll" #cfunc global CryptEnumKeyIdentifierProperties "CryptEnumKeyIdentifierProperties" var, int, int, wstr, intptr, intptr, intptr ; res = CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum) ; pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "var" ; dwPropId : DWORD -> "int" ; dwFlags : DWORD -> "int" ; pwszComputerName : LPCWSTR optional -> "wstr" ; pvReserved : void* optional -> "intptr" ; pvArg : void* optional, in/out -> "intptr" ; pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptEnumKeyIdentifierProperties(CRYPT_INTEGER_BLOB* pKeyIdentifier, DWORD dwPropId, DWORD dwFlags, LPCWSTR pwszComputerName, void* pvReserved, void* pvArg, PFN_CRYPT_ENUM_KEYID_PROP pfnEnum) #uselib "CRYPT32.dll" #cfunc global CryptEnumKeyIdentifierProperties "CryptEnumKeyIdentifierProperties" intptr, int, int, wstr, intptr, intptr, intptr ; res = CryptEnumKeyIdentifierProperties(varptr(pKeyIdentifier), dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum) ; pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "intptr" ; dwPropId : DWORD -> "int" ; dwFlags : DWORD -> "int" ; pwszComputerName : LPCWSTR optional -> "wstr" ; pvReserved : void* optional -> "intptr" ; pvArg : void* optional, in/out -> "intptr" ; pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptEnumKeyIdentifierProperties = crypt32.NewProc("CryptEnumKeyIdentifierProperties")
)
// pKeyIdentifier (CRYPT_INTEGER_BLOB* optional), dwPropId (DWORD), dwFlags (DWORD), pwszComputerName (LPCWSTR optional), pvReserved (void* optional), pvArg (void* optional, in/out), pfnEnum (PFN_CRYPT_ENUM_KEYID_PROP)
r1, _, err := procCryptEnumKeyIdentifierProperties.Call(
uintptr(pKeyIdentifier),
uintptr(dwPropId),
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszComputerName))),
uintptr(pvReserved),
uintptr(pvArg),
uintptr(pfnEnum),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptEnumKeyIdentifierProperties(
pKeyIdentifier: Pointer; // CRYPT_INTEGER_BLOB* optional
dwPropId: DWORD; // DWORD
dwFlags: DWORD; // DWORD
pwszComputerName: PWideChar; // LPCWSTR optional
pvReserved: Pointer; // void* optional
pvArg: Pointer; // void* optional, in/out
pfnEnum: Pointer // PFN_CRYPT_ENUM_KEYID_PROP
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptEnumKeyIdentifierProperties';result := DllCall("CRYPT32\CryptEnumKeyIdentifierProperties"
, "Ptr", pKeyIdentifier ; CRYPT_INTEGER_BLOB* optional
, "UInt", dwPropId ; DWORD
, "UInt", dwFlags ; DWORD
, "WStr", pwszComputerName ; LPCWSTR optional
, "Ptr", pvReserved ; void* optional
, "Ptr", pvArg ; void* optional, in/out
, "Ptr", pfnEnum ; PFN_CRYPT_ENUM_KEYID_PROP
, "Int") ; return: BOOL●CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum) = DLL("CRYPT32.dll", "bool CryptEnumKeyIdentifierProperties(void*, dword, dword, char*, void*, void*, void*)")
# 呼び出し: CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)
# pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "void*"
# dwPropId : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# pwszComputerName : LPCWSTR optional -> "char*"
# pvReserved : void* optional -> "void*"
# pvArg : void* optional, in/out -> "void*"
# pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptEnumKeyIdentifierProperties(
pKeyIdentifier: [*c]CRYPT_INTEGER_BLOB, // CRYPT_INTEGER_BLOB* optional
dwPropId: u32, // DWORD
dwFlags: u32, // DWORD
pwszComputerName: [*c]const u16, // LPCWSTR optional
pvReserved: ?*anyopaque, // void* optional
pvArg: ?*anyopaque, // void* optional, in/out
pfnEnum: ?*anyopaque // PFN_CRYPT_ENUM_KEYID_PROP
) callconv(std.os.windows.WINAPI) i32;proc CryptEnumKeyIdentifierProperties(
pKeyIdentifier: ptr CRYPT_INTEGER_BLOB, # CRYPT_INTEGER_BLOB* optional
dwPropId: uint32, # DWORD
dwFlags: uint32, # DWORD
pwszComputerName: WideCString, # LPCWSTR optional
pvReserved: pointer, # void* optional
pvArg: pointer, # void* optional, in/out
pfnEnum: pointer # PFN_CRYPT_ENUM_KEYID_PROP
): int32 {.importc: "CryptEnumKeyIdentifierProperties", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptEnumKeyIdentifierProperties(
CRYPT_INTEGER_BLOB* pKeyIdentifier, // CRYPT_INTEGER_BLOB* optional
uint dwPropId, // DWORD
uint dwFlags, // DWORD
const(wchar)* pwszComputerName, // LPCWSTR optional
void* pvReserved, // void* optional
void* pvArg, // void* optional, in/out
void* pfnEnum // PFN_CRYPT_ENUM_KEYID_PROP
);ccall((:CryptEnumKeyIdentifierProperties, "CRYPT32.dll"), stdcall, Int32,
(Ptr{CRYPT_INTEGER_BLOB}, UInt32, UInt32, Cwstring, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)
# pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> Ptr{CRYPT_INTEGER_BLOB}
# dwPropId : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# pwszComputerName : LPCWSTR optional -> Cwstring
# pvReserved : void* optional -> Ptr{Cvoid}
# pvArg : void* optional, in/out -> Ptr{Cvoid}
# pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptEnumKeyIdentifierProperties(
void* pKeyIdentifier,
uint32_t dwPropId,
uint32_t dwFlags,
const uint16_t* pwszComputerName,
void* pvReserved,
void* pvArg,
void* pfnEnum);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)
-- pKeyIdentifier : CRYPT_INTEGER_BLOB* optional
-- dwPropId : DWORD
-- dwFlags : DWORD
-- pwszComputerName : LPCWSTR optional
-- pvReserved : void* optional
-- pvArg : void* optional, in/out
-- pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptEnumKeyIdentifierProperties = lib.func('__stdcall', 'CryptEnumKeyIdentifierProperties', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'str16', 'void *', 'void *', 'void *']);
// CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)
// pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> 'void *'
// dwPropId : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// pwszComputerName : LPCWSTR optional -> 'str16'
// pvReserved : void* optional -> 'void *'
// pvArg : void* optional, in/out -> 'void *'
// pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("CRYPT32.dll", {
CryptEnumKeyIdentifierProperties: { parameters: ["pointer", "u32", "u32", "buffer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum)
// pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> "pointer"
// dwPropId : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// pwszComputerName : LPCWSTR optional -> "buffer"
// pvReserved : void* optional -> "pointer"
// pvArg : void* optional, in/out -> "pointer"
// pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptEnumKeyIdentifierProperties(
void* pKeyIdentifier,
uint32_t dwPropId,
uint32_t dwFlags,
const uint16_t* pwszComputerName,
void* pvReserved,
void* pvArg,
void* pfnEnum);
C, "CRYPT32.dll");
// $ffi->CryptEnumKeyIdentifierProperties(pKeyIdentifier, dwPropId, dwFlags, pwszComputerName, pvReserved, pvArg, pfnEnum);
// pKeyIdentifier : CRYPT_INTEGER_BLOB* optional
// dwPropId : DWORD
// dwFlags : DWORD
// pwszComputerName : LPCWSTR optional
// pvReserved : void* optional
// pvArg : void* optional, in/out
// pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP
// 構造体/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 Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptEnumKeyIdentifierProperties(
Pointer pKeyIdentifier, // CRYPT_INTEGER_BLOB* optional
int dwPropId, // DWORD
int dwFlags, // DWORD
WString pwszComputerName, // LPCWSTR optional
Pointer pvReserved, // void* optional
Pointer pvArg, // void* optional, in/out
Callback pfnEnum // PFN_CRYPT_ENUM_KEYID_PROP
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptEnumKeyIdentifierProperties = CryptEnumKeyIdentifierProperties(
pKeyIdentifier : CRYPT_INTEGER_BLOB*, # CRYPT_INTEGER_BLOB* optional
dwPropId : UInt32, # DWORD
dwFlags : UInt32, # DWORD
pwszComputerName : UInt16*, # LPCWSTR optional
pvReserved : Void*, # void* optional
pvArg : Void*, # void* optional, in/out
pfnEnum : Void* # PFN_CRYPT_ENUM_KEYID_PROP
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptEnumKeyIdentifierPropertiesNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef CryptEnumKeyIdentifierPropertiesDart = int Function(Pointer<Void>, int, int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final CryptEnumKeyIdentifierProperties = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptEnumKeyIdentifierPropertiesNative, CryptEnumKeyIdentifierPropertiesDart>('CryptEnumKeyIdentifierProperties');
// pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> Pointer<Void>
// dwPropId : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// pwszComputerName : LPCWSTR optional -> Pointer<Utf16>
// pvReserved : void* optional -> Pointer<Void>
// pvArg : void* optional, in/out -> Pointer<Void>
// pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptEnumKeyIdentifierProperties(
pKeyIdentifier: Pointer; // CRYPT_INTEGER_BLOB* optional
dwPropId: DWORD; // DWORD
dwFlags: DWORD; // DWORD
pwszComputerName: PWideChar; // LPCWSTR optional
pvReserved: Pointer; // void* optional
pvArg: Pointer; // void* optional, in/out
pfnEnum: Pointer // PFN_CRYPT_ENUM_KEYID_PROP
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptEnumKeyIdentifierProperties';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptEnumKeyIdentifierProperties"
c_CryptEnumKeyIdentifierProperties :: Ptr () -> Word32 -> Word32 -> CWString -> Ptr () -> Ptr () -> Ptr () -> IO CInt
-- pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> Ptr ()
-- dwPropId : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- pwszComputerName : LPCWSTR optional -> CWString
-- pvReserved : void* optional -> Ptr ()
-- pvArg : void* optional, in/out -> Ptr ()
-- pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptenumkeyidentifierproperties =
foreign "CryptEnumKeyIdentifierProperties"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> (ptr void) *)
(* dwPropId : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* pwszComputerName : LPCWSTR optional -> (ptr uint16_t) *)
(* pvReserved : void* optional -> (ptr void) *)
(* pvArg : void* optional, in/out -> (ptr void) *)
(* pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptEnumKeyIdentifierProperties" crypt-enum-key-identifier-properties :convention :stdcall) :int32
(p-key-identifier :pointer) ; CRYPT_INTEGER_BLOB* optional
(dw-prop-id :uint32) ; DWORD
(dw-flags :uint32) ; DWORD
(pwsz-computer-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(pv-reserved :pointer) ; void* optional
(pv-arg :pointer) ; void* optional, in/out
(pfn-enum :pointer)) ; PFN_CRYPT_ENUM_KEYID_PROP
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptEnumKeyIdentifierProperties = Win32::API::More->new('CRYPT32',
'BOOL CryptEnumKeyIdentifierProperties(LPVOID pKeyIdentifier, DWORD dwPropId, DWORD dwFlags, LPCWSTR pwszComputerName, LPVOID pvReserved, LPVOID pvArg, LPVOID pfnEnum)');
# my $ret = $CryptEnumKeyIdentifierProperties->Call($pKeyIdentifier, $dwPropId, $dwFlags, $pwszComputerName, $pvReserved, $pvArg, $pfnEnum);
# pKeyIdentifier : CRYPT_INTEGER_BLOB* optional -> LPVOID
# dwPropId : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# pwszComputerName : LPCWSTR optional -> LPCWSTR
# pvReserved : void* optional -> LPVOID
# pvArg : void* optional, in/out -> LPVOID
# pfnEnum : PFN_CRYPT_ENUM_KEYID_PROP -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
- f CryptGetKeyIdentifierProperty — 鍵識別子に関連付けられたプロパティを取得する。
- f CryptSetKeyIdentifierProperty — 鍵識別子にプロパティを設定する。