ホーム › Security.Cryptography › CryptFreeOIDFunctionAddress
CryptFreeOIDFunctionAddress
関数取得したOID関数アドレスのハンドルを解放する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptFreeOIDFunctionAddress(
void* hFuncAddr,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hFuncAddr | void* | in | CryptGetOIDFunctionAddress または CryptGetDefaultOIDFunctionAddress の呼び出しによって以前に取得した関数のハンドル。 |
| dwFlags | DWORD | in | 将来の使用のために予約されており、ゼロである必要があります。 |
戻り値の型: BOOL
公式ドキュメント
CryptFreeOIDFunctionAddress 関数は、関数ハンドルの参照カウントをデクリメントすることで、CryptGetOIDFunctionAddress または CryptGetDefaultOIDFunctionAddress が返したハンドルを解放します。
戻り値
関数が成功した場合、関数はゼロ以外の値 (TRUE) を返します。
関数が失敗した場合は、ゼロ (FALSE) を返します。
解説(Remarks)
参照カウントがゼロになり、解放対象の関数のために DLL がロードされている場合、その DLL はアンロードされる可能性があります。DLL が DLLCanUnloadNow 関数をエクスポートしている場合、その関数が呼び出され、戻り値が確認されます。この関数が S_FALSE を返すと、この時点での DLL のアンロードはキャンセルされます。関数が S_TRUE を返す場合、または DLL が DLLCanUnloadNow 関数をエクスポートしていない場合は、アンロード処理が開始されます。この場合、実際のアンロードは 15 秒間遅延されます。15 秒が経過する前に、その DLL を必要とする別の CryptFreeOIDFunctionAddress または CryptGetDefaultOIDFunctionAddress が発生した場合、遅延されていたアンロード処理はキャンセルされます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptFreeOIDFunctionAddress(
void* hFuncAddr,
DWORD dwFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern bool CryptFreeOIDFunctionAddress(
IntPtr hFuncAddr, // void*
uint dwFlags // DWORD
);<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CryptFreeOIDFunctionAddress(
hFuncAddr As IntPtr, ' void*
dwFlags As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hFuncAddr : void*
' dwFlags : DWORD
Declare PtrSafe Function CryptFreeOIDFunctionAddress Lib "crypt32" ( _
ByVal hFuncAddr As LongPtr, _
ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptFreeOIDFunctionAddress = ctypes.windll.crypt32.CryptFreeOIDFunctionAddress
CryptFreeOIDFunctionAddress.restype = wintypes.BOOL
CryptFreeOIDFunctionAddress.argtypes = [
ctypes.POINTER(None), # hFuncAddr : void*
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptFreeOIDFunctionAddress = Fiddle::Function.new(
lib['CryptFreeOIDFunctionAddress'],
[
Fiddle::TYPE_VOIDP, # hFuncAddr : void*
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptFreeOIDFunctionAddress(
hFuncAddr: *mut (), // void*
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll")]
public static extern bool CryptFreeOIDFunctionAddress(IntPtr hFuncAddr, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptFreeOIDFunctionAddress' -Namespace Win32 -PassThru
# $api::CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)#uselib "CRYPT32.dll"
#func global CryptFreeOIDFunctionAddress "CryptFreeOIDFunctionAddress" sptr, sptr
; CryptFreeOIDFunctionAddress hFuncAddr, dwFlags ; 戻り値は stat
; hFuncAddr : void* -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll"
#cfunc global CryptFreeOIDFunctionAddress "CryptFreeOIDFunctionAddress" sptr, int
; res = CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
; hFuncAddr : void* -> "sptr"
; dwFlags : DWORD -> "int"; BOOL CryptFreeOIDFunctionAddress(void* hFuncAddr, DWORD dwFlags)
#uselib "CRYPT32.dll"
#cfunc global CryptFreeOIDFunctionAddress "CryptFreeOIDFunctionAddress" intptr, int
; res = CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
; hFuncAddr : void* -> "intptr"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptFreeOIDFunctionAddress = crypt32.NewProc("CryptFreeOIDFunctionAddress")
)
// hFuncAddr (void*), dwFlags (DWORD)
r1, _, err := procCryptFreeOIDFunctionAddress.Call(
uintptr(hFuncAddr),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptFreeOIDFunctionAddress(
hFuncAddr: Pointer; // void*
dwFlags: DWORD // DWORD
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptFreeOIDFunctionAddress';result := DllCall("CRYPT32\CryptFreeOIDFunctionAddress"
, "Ptr", hFuncAddr ; void*
, "UInt", dwFlags ; DWORD
, "Int") ; return: BOOL●CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags) = DLL("CRYPT32.dll", "bool CryptFreeOIDFunctionAddress(void*, dword)")
# 呼び出し: CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
# hFuncAddr : void* -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptFreeOIDFunctionAddress(
hFuncAddr: ?*anyopaque, // void*
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc CryptFreeOIDFunctionAddress(
hFuncAddr: pointer, # void*
dwFlags: uint32 # DWORD
): int32 {.importc: "CryptFreeOIDFunctionAddress", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptFreeOIDFunctionAddress(
void* hFuncAddr, // void*
uint dwFlags // DWORD
);ccall((:CryptFreeOIDFunctionAddress, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32),
hFuncAddr, dwFlags)
# hFuncAddr : void* -> Ptr{Cvoid}
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptFreeOIDFunctionAddress(
void* hFuncAddr,
uint32_t dwFlags);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
-- hFuncAddr : void*
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptFreeOIDFunctionAddress = lib.func('__stdcall', 'CryptFreeOIDFunctionAddress', 'int32_t', ['void *', 'uint32_t']);
// CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
// hFuncAddr : void* -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptFreeOIDFunctionAddress: { parameters: ["pointer", "u32"], result: "i32" },
});
// lib.symbols.CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags)
// hFuncAddr : void* -> "pointer"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptFreeOIDFunctionAddress(
void* hFuncAddr,
uint32_t dwFlags);
C, "CRYPT32.dll");
// $ffi->CryptFreeOIDFunctionAddress(hFuncAddr, dwFlags);
// hFuncAddr : void*
// dwFlags : DWORD
// 構造体/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 CryptFreeOIDFunctionAddress(
Pointer hFuncAddr, // void*
int dwFlags // DWORD
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptFreeOIDFunctionAddress = CryptFreeOIDFunctionAddress(
hFuncAddr : Void*, # void*
dwFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptFreeOIDFunctionAddressNative = Int32 Function(Pointer<Void>, Uint32);
typedef CryptFreeOIDFunctionAddressDart = int Function(Pointer<Void>, int);
final CryptFreeOIDFunctionAddress = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptFreeOIDFunctionAddressNative, CryptFreeOIDFunctionAddressDart>('CryptFreeOIDFunctionAddress');
// hFuncAddr : void* -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptFreeOIDFunctionAddress(
hFuncAddr: Pointer; // void*
dwFlags: DWORD // DWORD
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptFreeOIDFunctionAddress';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptFreeOIDFunctionAddress"
c_CryptFreeOIDFunctionAddress :: Ptr () -> Word32 -> IO CInt
-- hFuncAddr : void* -> Ptr ()
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptfreeoidfunctionaddress =
foreign "CryptFreeOIDFunctionAddress"
((ptr void) @-> uint32_t @-> returning int32_t)
(* hFuncAddr : void* -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptFreeOIDFunctionAddress" crypt-free-oidfunction-address :convention :stdcall) :int32
(h-func-addr :pointer) ; void*
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptFreeOIDFunctionAddress = Win32::API::More->new('CRYPT32',
'BOOL CryptFreeOIDFunctionAddress(LPVOID hFuncAddr, DWORD dwFlags)');
# my $ret = $CryptFreeOIDFunctionAddress->Call($hFuncAddr, $dwFlags);
# hFuncAddr : void* -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CryptGetDefaultOIDFunctionAddress — 既定DLLからOID関数のアドレスを取得する。
- f CryptGetOIDFunctionAddress — 指定OIDに対応する関数のアドレスを取得する。