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

CryptRegisterDefaultOIDFunction

関数
既定のOID関数DLLをレジストリに登録する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL CryptRegisterDefaultOIDFunction(
    DWORD dwEncodingType,
    LPCSTR pszFuncName,
    DWORD dwIndex,
    LPCWSTR pwszDll
);

パラメーター

名前方向説明
dwEncodingTypeDWORDin

照合するエンコード種別を指定します。現在使用されているのは X509_ASN_ENCODINGPKCS_7_ASN_ENCODING のみですが、将来的に他のエンコード種別が追加される可能性があります。現在の両方のエンコード種別を照合するには、次のように指定します。

X509_ASN_ENCODING | PKCS_7_ASN_ENCODING

pszFuncNameLPCSTRin登録する関数の名前です。
dwIndexDWORDinDLL のリスト内で DLL を挿入する位置のインデックスです。dwIndex が 0 の場合、DLL はリストの先頭に挿入されます。CRYPT_REGISTER_LAST_INDEX の場合、DLL はリストの末尾に追加されます。
pwszDllLPCWSTRinDLL を読み込む前に ExpandEnvironmentStrings 関数で展開される、省略可能な環境変数文字列です。

戻り値の型: BOOL

公式ドキュメント

CryptRegisterDefaultOIDFunction は、指定したエンコード種別および関数名に対して呼び出される既定の関数を含む DLL を登録します。CryptRegisterOIDFunction とは異なり、DLL がエクスポートする関数名を上書きすることはできません。

戻り値

関数が成功した場合、戻り値は 0 以外の値(TRUE)です。

関数が失敗した場合、戻り値は 0(FALSE)です。

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

各言語での呼び出し定義

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

BOOL CryptRegisterDefaultOIDFunction(
    DWORD dwEncodingType,
    LPCSTR pszFuncName,
    DWORD dwIndex,
    LPCWSTR pwszDll
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern bool CryptRegisterDefaultOIDFunction(
    uint dwEncodingType,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string pszFuncName,   // LPCSTR
    uint dwIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pwszDll   // LPCWSTR
);
<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CryptRegisterDefaultOIDFunction(
    dwEncodingType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pszFuncName As String,   ' LPCSTR
    dwIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pwszDll As String   ' LPCWSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' dwEncodingType : DWORD
' pszFuncName : LPCSTR
' dwIndex : DWORD
' pwszDll : LPCWSTR
Declare PtrSafe Function CryptRegisterDefaultOIDFunction Lib "crypt32" ( _
    ByVal dwEncodingType As Long, _
    ByVal pszFuncName As String, _
    ByVal dwIndex As Long, _
    ByVal pwszDll As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptRegisterDefaultOIDFunction = ctypes.windll.crypt32.CryptRegisterDefaultOIDFunction
CryptRegisterDefaultOIDFunction.restype = wintypes.BOOL
CryptRegisterDefaultOIDFunction.argtypes = [
    wintypes.DWORD,  # dwEncodingType : DWORD
    wintypes.LPCSTR,  # pszFuncName : LPCSTR
    wintypes.DWORD,  # dwIndex : DWORD
    wintypes.LPCWSTR,  # pwszDll : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CryptRegisterDefaultOIDFunction = Fiddle::Function.new(
  lib['CryptRegisterDefaultOIDFunction'],
  [
    -Fiddle::TYPE_INT,  # dwEncodingType : DWORD
    Fiddle::TYPE_VOIDP,  # pszFuncName : LPCSTR
    -Fiddle::TYPE_INT,  # dwIndex : DWORD
    Fiddle::TYPE_VOIDP,  # pwszDll : LPCWSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CryptRegisterDefaultOIDFunction(
        dwEncodingType: u32,  // DWORD
        pszFuncName: *const u8,  // LPCSTR
        dwIndex: u32,  // DWORD
        pwszDll: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll")]
public static extern bool CryptRegisterDefaultOIDFunction(uint dwEncodingType, [MarshalAs(UnmanagedType.LPStr)] string pszFuncName, uint dwIndex, [MarshalAs(UnmanagedType.LPWStr)] string pwszDll);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptRegisterDefaultOIDFunction' -Namespace Win32 -PassThru
# $api::CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
#uselib "CRYPT32.dll"
#func global CryptRegisterDefaultOIDFunction "CryptRegisterDefaultOIDFunction" sptr, sptr, sptr, sptr
; CryptRegisterDefaultOIDFunction dwEncodingType, pszFuncName, dwIndex, pwszDll   ; 戻り値は stat
; dwEncodingType : DWORD -> "sptr"
; pszFuncName : LPCSTR -> "sptr"
; dwIndex : DWORD -> "sptr"
; pwszDll : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CRYPT32.dll"
#cfunc global CryptRegisterDefaultOIDFunction "CryptRegisterDefaultOIDFunction" int, str, int, wstr
; res = CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
; dwEncodingType : DWORD -> "int"
; pszFuncName : LPCSTR -> "str"
; dwIndex : DWORD -> "int"
; pwszDll : LPCWSTR -> "wstr"
; BOOL CryptRegisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
#uselib "CRYPT32.dll"
#cfunc global CryptRegisterDefaultOIDFunction "CryptRegisterDefaultOIDFunction" int, str, int, wstr
; res = CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
; dwEncodingType : DWORD -> "int"
; pszFuncName : LPCSTR -> "str"
; dwIndex : DWORD -> "int"
; pwszDll : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptRegisterDefaultOIDFunction = crypt32.NewProc("CryptRegisterDefaultOIDFunction")
)

// dwEncodingType (DWORD), pszFuncName (LPCSTR), dwIndex (DWORD), pwszDll (LPCWSTR)
r1, _, err := procCryptRegisterDefaultOIDFunction.Call(
	uintptr(dwEncodingType),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszFuncName))),
	uintptr(dwIndex),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszDll))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptRegisterDefaultOIDFunction(
  dwEncodingType: DWORD;   // DWORD
  pszFuncName: PAnsiChar;   // LPCSTR
  dwIndex: DWORD;   // DWORD
  pwszDll: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptRegisterDefaultOIDFunction';
result := DllCall("CRYPT32\CryptRegisterDefaultOIDFunction"
    , "UInt", dwEncodingType   ; DWORD
    , "AStr", pszFuncName   ; LPCSTR
    , "UInt", dwIndex   ; DWORD
    , "WStr", pwszDll   ; LPCWSTR
    , "Int")   ; return: BOOL
●CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll) = DLL("CRYPT32.dll", "bool CryptRegisterDefaultOIDFunction(dword, char*, dword, char*)")
# 呼び出し: CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
# dwEncodingType : DWORD -> "dword"
# pszFuncName : LPCSTR -> "char*"
# dwIndex : DWORD -> "dword"
# pwszDll : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CryptRegisterDefaultOIDFunction(
    dwEncodingType: u32, // DWORD
    pszFuncName: [*c]const u8, // LPCSTR
    dwIndex: u32, // DWORD
    pwszDll: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;
proc CryptRegisterDefaultOIDFunction(
    dwEncodingType: uint32,  # DWORD
    pszFuncName: cstring,  # LPCSTR
    dwIndex: uint32,  # DWORD
    pwszDll: WideCString  # LPCWSTR
): int32 {.importc: "CryptRegisterDefaultOIDFunction", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
int CryptRegisterDefaultOIDFunction(
    uint dwEncodingType,   // DWORD
    const(char)* pszFuncName,   // LPCSTR
    uint dwIndex,   // DWORD
    const(wchar)* pwszDll   // LPCWSTR
);
ccall((:CryptRegisterDefaultOIDFunction, "CRYPT32.dll"), stdcall, Int32,
      (UInt32, Cstring, UInt32, Cwstring),
      dwEncodingType, pszFuncName, dwIndex, pwszDll)
# dwEncodingType : DWORD -> UInt32
# pszFuncName : LPCSTR -> Cstring
# dwIndex : DWORD -> UInt32
# pwszDll : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CryptRegisterDefaultOIDFunction(
    uint32_t dwEncodingType,
    const char* pszFuncName,
    uint32_t dwIndex,
    const uint16_t* pwszDll);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
-- dwEncodingType : DWORD
-- pszFuncName : LPCSTR
-- dwIndex : DWORD
-- pwszDll : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptRegisterDefaultOIDFunction = lib.func('__stdcall', 'CryptRegisterDefaultOIDFunction', 'int32_t', ['uint32_t', 'str', 'uint32_t', 'str16']);
// CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
// dwEncodingType : DWORD -> 'uint32_t'
// pszFuncName : LPCSTR -> 'str'
// dwIndex : DWORD -> 'uint32_t'
// pwszDll : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CryptRegisterDefaultOIDFunction: { parameters: ["u32", "buffer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll)
// dwEncodingType : DWORD -> "u32"
// pszFuncName : LPCSTR -> "buffer"
// dwIndex : DWORD -> "u32"
// pwszDll : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CryptRegisterDefaultOIDFunction(
    uint32_t dwEncodingType,
    const char* pszFuncName,
    uint32_t dwIndex,
    const uint16_t* pwszDll);
C, "CRYPT32.dll");
// $ffi->CryptRegisterDefaultOIDFunction(dwEncodingType, pszFuncName, dwIndex, pwszDll);
// dwEncodingType : DWORD
// pszFuncName : LPCSTR
// dwIndex : DWORD
// pwszDll : LPCWSTR
// 構造体/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 CryptRegisterDefaultOIDFunction(
        int dwEncodingType,   // DWORD
        String pszFuncName,   // LPCSTR
        int dwIndex,   // DWORD
        WString pwszDll   // LPCWSTR
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CryptRegisterDefaultOIDFunction = CryptRegisterDefaultOIDFunction(
    dwEncodingType : UInt32,   # DWORD
    pszFuncName : UInt8*,   # LPCSTR
    dwIndex : UInt32,   # DWORD
    pwszDll : UInt16*   # LPCWSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CryptRegisterDefaultOIDFunctionNative = Int32 Function(Uint32, Pointer<Utf8>, Uint32, Pointer<Utf16>);
typedef CryptRegisterDefaultOIDFunctionDart = int Function(int, Pointer<Utf8>, int, Pointer<Utf16>);
final CryptRegisterDefaultOIDFunction = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CryptRegisterDefaultOIDFunctionNative, CryptRegisterDefaultOIDFunctionDart>('CryptRegisterDefaultOIDFunction');
// dwEncodingType : DWORD -> Uint32
// pszFuncName : LPCSTR -> Pointer<Utf8>
// dwIndex : DWORD -> Uint32
// pwszDll : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CryptRegisterDefaultOIDFunction(
  dwEncodingType: DWORD;   // DWORD
  pszFuncName: PAnsiChar;   // LPCSTR
  dwIndex: DWORD;   // DWORD
  pwszDll: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptRegisterDefaultOIDFunction';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CryptRegisterDefaultOIDFunction"
  c_CryptRegisterDefaultOIDFunction :: Word32 -> CString -> Word32 -> CWString -> IO CInt
-- dwEncodingType : DWORD -> Word32
-- pszFuncName : LPCSTR -> CString
-- dwIndex : DWORD -> Word32
-- pwszDll : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cryptregisterdefaultoidfunction =
  foreign "CryptRegisterDefaultOIDFunction"
    (uint32_t @-> string @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* dwEncodingType : DWORD -> uint32_t *)
(* pszFuncName : LPCSTR -> string *)
(* dwIndex : DWORD -> uint32_t *)
(* pwszDll : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)

(cffi:defcfun ("CryptRegisterDefaultOIDFunction" crypt-register-default-oidfunction :convention :stdcall) :int32
  (dw-encoding-type :uint32)   ; DWORD
  (psz-func-name :string)   ; LPCSTR
  (dw-index :uint32)   ; DWORD
  (pwsz-dll (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CryptRegisterDefaultOIDFunction = Win32::API::More->new('CRYPT32',
    'BOOL CryptRegisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)');
# my $ret = $CryptRegisterDefaultOIDFunction->Call($dwEncodingType, $pszFuncName, $dwIndex, $pwszDll);
# dwEncodingType : DWORD -> DWORD
# pszFuncName : LPCSTR -> LPCSTR
# dwIndex : DWORD -> DWORD
# pwszDll : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。