CryptGetDefaultOIDFunctionAddress
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptGetDefaultOIDFunctionAddress(
void* hFuncSet,
DWORD dwEncodingType,
LPCWSTR pwszDll, // optional
DWORD dwFlags,
void** ppvFuncAddr,
void** phFuncAddr
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hFuncSet | void* | in | 以前に CryptInitOIDFunctionSet の呼び出しによって取得した関数セットのハンドルです。 |
| dwEncodingType | DWORD | in | 照合するエンコーディングの種類です。現在は X509_ASN_ENCODING と PKCS_7_ASN_ENCODING のみが使用されていますが、将来的にエンコーディングの種類が追加される可能性があります。現在の両方のエンコーディングの種類を照合するには、次を使用します。 |
| pwszDll | LPCWSTR | inoptional | 読み込む DLL の名前です。通常、DLL 名は CryptGetDefaultOIDDllList が返すリストから取得します。pwszDll が NULL の場合、インストール済みの既定の関数のリストに対して検索が実行されます。 |
| dwFlags | DWORD | in | 将来の使用のために予約されており、ゼロを指定する必要があります。 |
| ppvFuncAddr | void** | out | 戻り値となる関数のアドレスへのポインターです。関数が失敗した場合、ppvFuncAddr には NULL が返されます。 |
| phFuncAddr | void** | inout | pwszDll が NULL の場合にのみ使用されます。この関数を最初に呼び出すときは、最初のインストール済み関数を取得するために *phFuncAddr を NULL にする必要があります。 この関数が成功すると、*phFuncAddr には関数ハンドルが設定されます。関数ハンドルの 参照カウント がインクリメントされます。 最初の呼び出し以降は、phFuncAddr に前回の呼び出しで返されたポインターを設定します。この入力ポインターは、この関数内で常に CryptFreeOIDFunctionAddress の呼び出しによって解放されます。この解放の呼び出しは、メイン関数がエラーを返す場合でも常に行われます。 NULL 以外の phFuncAddr は、CryptFreeOIDFunctionAddress の呼び出しによって解放するか、この関数または CryptGetOIDFunctionAddress への入力として渡して解放する必要があります。 pwszDll が NULL でない場合、このパラメーターの値は無視され、NULL 以外のポインターは解放されません。 |
戻り値の型: BOOL
公式ドキュメント
CryptGetDefaultOIDFunctionAddress 関数は、既定の関数アドレスを含む DLL を読み込みます。
戻り値
関数が成功した場合は、非ゼロ (TRUE) を返します。
関数が失敗した場合は、ゼロ (FALSE) を返します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptGetDefaultOIDFunctionAddress(
void* hFuncSet,
DWORD dwEncodingType,
LPCWSTR pwszDll, // optional
DWORD dwFlags,
void** ppvFuncAddr,
void** phFuncAddr
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern bool CryptGetDefaultOIDFunctionAddress(
IntPtr hFuncSet, // void*
uint dwEncodingType, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pwszDll, // LPCWSTR optional
uint dwFlags, // DWORD
IntPtr ppvFuncAddr, // void** out
IntPtr phFuncAddr // void** in/out
);<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CryptGetDefaultOIDFunctionAddress(
hFuncSet As IntPtr, ' void*
dwEncodingType As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pwszDll As String, ' LPCWSTR optional
dwFlags As UInteger, ' DWORD
ppvFuncAddr As IntPtr, ' void** out
phFuncAddr As IntPtr ' void** in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hFuncSet : void*
' dwEncodingType : DWORD
' pwszDll : LPCWSTR optional
' dwFlags : DWORD
' ppvFuncAddr : void** out
' phFuncAddr : void** in/out
Declare PtrSafe Function CryptGetDefaultOIDFunctionAddress Lib "crypt32" ( _
ByVal hFuncSet As LongPtr, _
ByVal dwEncodingType As Long, _
ByVal pwszDll As LongPtr, _
ByVal dwFlags As Long, _
ByVal ppvFuncAddr As LongPtr, _
ByVal phFuncAddr As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptGetDefaultOIDFunctionAddress = ctypes.windll.crypt32.CryptGetDefaultOIDFunctionAddress
CryptGetDefaultOIDFunctionAddress.restype = wintypes.BOOL
CryptGetDefaultOIDFunctionAddress.argtypes = [
ctypes.POINTER(None), # hFuncSet : void*
wintypes.DWORD, # dwEncodingType : DWORD
wintypes.LPCWSTR, # pwszDll : LPCWSTR optional
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_void_p, # ppvFuncAddr : void** out
ctypes.c_void_p, # phFuncAddr : void** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptGetDefaultOIDFunctionAddress = Fiddle::Function.new(
lib['CryptGetDefaultOIDFunctionAddress'],
[
Fiddle::TYPE_VOIDP, # hFuncSet : void*
-Fiddle::TYPE_INT, # dwEncodingType : DWORD
Fiddle::TYPE_VOIDP, # pwszDll : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # ppvFuncAddr : void** out
Fiddle::TYPE_VOIDP, # phFuncAddr : void** in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptGetDefaultOIDFunctionAddress(
hFuncSet: *mut (), // void*
dwEncodingType: u32, // DWORD
pwszDll: *const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
ppvFuncAddr: *mut *mut (), // void** out
phFuncAddr: *mut *mut () // void** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll")]
public static extern bool CryptGetDefaultOIDFunctionAddress(IntPtr hFuncSet, uint dwEncodingType, [MarshalAs(UnmanagedType.LPWStr)] string pwszDll, uint dwFlags, IntPtr ppvFuncAddr, IntPtr phFuncAddr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptGetDefaultOIDFunctionAddress' -Namespace Win32 -PassThru
# $api::CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)#uselib "CRYPT32.dll"
#func global CryptGetDefaultOIDFunctionAddress "CryptGetDefaultOIDFunctionAddress" sptr, sptr, sptr, sptr, sptr, sptr
; CryptGetDefaultOIDFunctionAddress hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr ; 戻り値は stat
; hFuncSet : void* -> "sptr"
; dwEncodingType : DWORD -> "sptr"
; pwszDll : LPCWSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ppvFuncAddr : void** out -> "sptr"
; phFuncAddr : void** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptGetDefaultOIDFunctionAddress "CryptGetDefaultOIDFunctionAddress" sptr, int, wstr, int, sptr, sptr
; res = CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
; hFuncSet : void* -> "sptr"
; dwEncodingType : DWORD -> "int"
; pwszDll : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; ppvFuncAddr : void** out -> "sptr"
; phFuncAddr : void** in/out -> "sptr"; BOOL CryptGetDefaultOIDFunctionAddress(void* hFuncSet, DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void** ppvFuncAddr, void** phFuncAddr)
#uselib "CRYPT32.dll"
#cfunc global CryptGetDefaultOIDFunctionAddress "CryptGetDefaultOIDFunctionAddress" intptr, int, wstr, int, intptr, intptr
; res = CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
; hFuncSet : void* -> "intptr"
; dwEncodingType : DWORD -> "int"
; pwszDll : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; ppvFuncAddr : void** out -> "intptr"
; phFuncAddr : void** in/out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptGetDefaultOIDFunctionAddress = crypt32.NewProc("CryptGetDefaultOIDFunctionAddress")
)
// hFuncSet (void*), dwEncodingType (DWORD), pwszDll (LPCWSTR optional), dwFlags (DWORD), ppvFuncAddr (void** out), phFuncAddr (void** in/out)
r1, _, err := procCryptGetDefaultOIDFunctionAddress.Call(
uintptr(hFuncSet),
uintptr(dwEncodingType),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszDll))),
uintptr(dwFlags),
uintptr(ppvFuncAddr),
uintptr(phFuncAddr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptGetDefaultOIDFunctionAddress(
hFuncSet: Pointer; // void*
dwEncodingType: DWORD; // DWORD
pwszDll: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // DWORD
ppvFuncAddr: Pointer; // void** out
phFuncAddr: Pointer // void** in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptGetDefaultOIDFunctionAddress';result := DllCall("CRYPT32\CryptGetDefaultOIDFunctionAddress"
, "Ptr", hFuncSet ; void*
, "UInt", dwEncodingType ; DWORD
, "WStr", pwszDll ; LPCWSTR optional
, "UInt", dwFlags ; DWORD
, "Ptr", ppvFuncAddr ; void** out
, "Ptr", phFuncAddr ; void** in/out
, "Int") ; return: BOOL●CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr) = DLL("CRYPT32.dll", "bool CryptGetDefaultOIDFunctionAddress(void*, dword, char*, dword, void*, void*)")
# 呼び出し: CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
# hFuncSet : void* -> "void*"
# dwEncodingType : DWORD -> "dword"
# pwszDll : LPCWSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# ppvFuncAddr : void** out -> "void*"
# phFuncAddr : void** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptGetDefaultOIDFunctionAddress(
hFuncSet: ?*anyopaque, // void*
dwEncodingType: u32, // DWORD
pwszDll: [*c]const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
ppvFuncAddr: ?*anyopaque, // void** out
phFuncAddr: ?*anyopaque // void** in/out
) callconv(std.os.windows.WINAPI) i32;proc CryptGetDefaultOIDFunctionAddress(
hFuncSet: pointer, # void*
dwEncodingType: uint32, # DWORD
pwszDll: WideCString, # LPCWSTR optional
dwFlags: uint32, # DWORD
ppvFuncAddr: pointer, # void** out
phFuncAddr: pointer # void** in/out
): int32 {.importc: "CryptGetDefaultOIDFunctionAddress", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptGetDefaultOIDFunctionAddress(
void* hFuncSet, // void*
uint dwEncodingType, // DWORD
const(wchar)* pwszDll, // LPCWSTR optional
uint dwFlags, // DWORD
void** ppvFuncAddr, // void** out
void** phFuncAddr // void** in/out
);ccall((:CryptGetDefaultOIDFunctionAddress, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Cwstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
# hFuncSet : void* -> Ptr{Cvoid}
# dwEncodingType : DWORD -> UInt32
# pwszDll : LPCWSTR optional -> Cwstring
# dwFlags : DWORD -> UInt32
# ppvFuncAddr : void** out -> Ptr{Cvoid}
# phFuncAddr : void** in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptGetDefaultOIDFunctionAddress(
void* hFuncSet,
uint32_t dwEncodingType,
const uint16_t* pwszDll,
uint32_t dwFlags,
void** ppvFuncAddr,
void** phFuncAddr);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
-- hFuncSet : void*
-- dwEncodingType : DWORD
-- pwszDll : LPCWSTR optional
-- dwFlags : DWORD
-- ppvFuncAddr : void** out
-- phFuncAddr : void** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptGetDefaultOIDFunctionAddress = lib.func('__stdcall', 'CryptGetDefaultOIDFunctionAddress', 'int32_t', ['void *', 'uint32_t', 'str16', 'uint32_t', 'void *', 'void *']);
// CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
// hFuncSet : void* -> 'void *'
// dwEncodingType : DWORD -> 'uint32_t'
// pwszDll : LPCWSTR optional -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// ppvFuncAddr : void** out -> 'void *'
// phFuncAddr : void** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptGetDefaultOIDFunctionAddress: { parameters: ["pointer", "u32", "buffer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr)
// hFuncSet : void* -> "pointer"
// dwEncodingType : DWORD -> "u32"
// pwszDll : LPCWSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// ppvFuncAddr : void** out -> "pointer"
// phFuncAddr : void** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptGetDefaultOIDFunctionAddress(
void* hFuncSet,
uint32_t dwEncodingType,
const uint16_t* pwszDll,
uint32_t dwFlags,
void** ppvFuncAddr,
void** phFuncAddr);
C, "CRYPT32.dll");
// $ffi->CryptGetDefaultOIDFunctionAddress(hFuncSet, dwEncodingType, pwszDll, dwFlags, ppvFuncAddr, phFuncAddr);
// hFuncSet : void*
// dwEncodingType : DWORD
// pwszDll : LPCWSTR optional
// dwFlags : DWORD
// ppvFuncAddr : void** out
// phFuncAddr : void** in/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 Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptGetDefaultOIDFunctionAddress(
Pointer hFuncSet, // void*
int dwEncodingType, // DWORD
WString pwszDll, // LPCWSTR optional
int dwFlags, // DWORD
Pointer ppvFuncAddr, // void** out
Pointer phFuncAddr // void** in/out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptGetDefaultOIDFunctionAddress = CryptGetDefaultOIDFunctionAddress(
hFuncSet : Void*, # void*
dwEncodingType : UInt32, # DWORD
pwszDll : UInt16*, # LPCWSTR optional
dwFlags : UInt32, # DWORD
ppvFuncAddr : Void**, # void** out
phFuncAddr : Void** # void** in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptGetDefaultOIDFunctionAddressNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>);
typedef CryptGetDefaultOIDFunctionAddressDart = int Function(Pointer<Void>, int, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>);
final CryptGetDefaultOIDFunctionAddress = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptGetDefaultOIDFunctionAddressNative, CryptGetDefaultOIDFunctionAddressDart>('CryptGetDefaultOIDFunctionAddress');
// hFuncSet : void* -> Pointer<Void>
// dwEncodingType : DWORD -> Uint32
// pwszDll : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// ppvFuncAddr : void** out -> Pointer<Void>
// phFuncAddr : void** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptGetDefaultOIDFunctionAddress(
hFuncSet: Pointer; // void*
dwEncodingType: DWORD; // DWORD
pwszDll: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // DWORD
ppvFuncAddr: Pointer; // void** out
phFuncAddr: Pointer // void** in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptGetDefaultOIDFunctionAddress';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptGetDefaultOIDFunctionAddress"
c_CryptGetDefaultOIDFunctionAddress :: Ptr () -> Word32 -> CWString -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- hFuncSet : void* -> Ptr ()
-- dwEncodingType : DWORD -> Word32
-- pwszDll : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- ppvFuncAddr : void** out -> Ptr ()
-- phFuncAddr : void** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptgetdefaultoidfunctionaddress =
foreign "CryptGetDefaultOIDFunctionAddress"
((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hFuncSet : void* -> (ptr void) *)
(* dwEncodingType : DWORD -> uint32_t *)
(* pwszDll : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* ppvFuncAddr : void** out -> (ptr void) *)
(* phFuncAddr : void** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptGetDefaultOIDFunctionAddress" crypt-get-default-oidfunction-address :convention :stdcall) :int32
(h-func-set :pointer) ; void*
(dw-encoding-type :uint32) ; DWORD
(pwsz-dll (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32) ; DWORD
(ppv-func-addr :pointer) ; void** out
(ph-func-addr :pointer)) ; void** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptGetDefaultOIDFunctionAddress = Win32::API::More->new('CRYPT32',
'BOOL CryptGetDefaultOIDFunctionAddress(LPVOID hFuncSet, DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, LPVOID ppvFuncAddr, LPVOID phFuncAddr)');
# my $ret = $CryptGetDefaultOIDFunctionAddress->Call($hFuncSet, $dwEncodingType, $pwszDll, $dwFlags, $ppvFuncAddr, $phFuncAddr);
# hFuncSet : void* -> LPVOID
# dwEncodingType : DWORD -> DWORD
# pwszDll : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# ppvFuncAddr : void** out -> LPVOID
# phFuncAddr : void** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。