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

CryptDestroyKey

関数
暗号鍵ハンドルを破棄する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptDestroyKey(
    UINT_PTR hKey
);

パラメーター

名前方向
hKeyUINT_PTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CryptDestroyKey(
    UINT_PTR hKey
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptDestroyKey(
    UIntPtr hKey   // UINT_PTR
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptDestroyKey(
    hKey As UIntPtr   ' UINT_PTR
) As Boolean
End Function
' hKey : UINT_PTR
Declare PtrSafe Function CryptDestroyKey Lib "advapi32" ( _
    ByVal hKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptDestroyKey = ctypes.windll.advapi32.CryptDestroyKey
CryptDestroyKey.restype = wintypes.BOOL
CryptDestroyKey.argtypes = [
    ctypes.c_size_t,  # hKey : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
CryptDestroyKey = Fiddle::Function.new(
  lib['CryptDestroyKey'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hKey : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn CryptDestroyKey(
        hKey: usize  // UINT_PTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool CryptDestroyKey(UIntPtr hKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CryptDestroyKey' -Namespace Win32 -PassThru
# $api::CryptDestroyKey(hKey)
#uselib "ADVAPI32.dll"
#func global CryptDestroyKey "CryptDestroyKey" sptr
; CryptDestroyKey hKey   ; 戻り値は stat
; hKey : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global CryptDestroyKey "CryptDestroyKey" sptr
; res = CryptDestroyKey(hKey)
; hKey : UINT_PTR -> "sptr"
; BOOL CryptDestroyKey(UINT_PTR hKey)
#uselib "ADVAPI32.dll"
#cfunc global CryptDestroyKey "CryptDestroyKey" intptr
; res = CryptDestroyKey(hKey)
; hKey : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procCryptDestroyKey = advapi32.NewProc("CryptDestroyKey")
)

// hKey (UINT_PTR)
r1, _, err := procCryptDestroyKey.Call(
	uintptr(hKey),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptDestroyKey(
  hKey: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'CryptDestroyKey';
result := DllCall("ADVAPI32\CryptDestroyKey"
    , "UPtr", hKey   ; UINT_PTR
    , "Int")   ; return: BOOL
●CryptDestroyKey(hKey) = DLL("ADVAPI32.dll", "bool CryptDestroyKey(int)")
# 呼び出し: CryptDestroyKey(hKey)
# hKey : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。