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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "advapi32" fn CryptDestroyKey(
    hKey: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;
proc CryptDestroyKey(
    hKey: uint  # UINT_PTR
): int32 {.importc: "CryptDestroyKey", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
int CryptDestroyKey(
    size_t hKey   // UINT_PTR
);
ccall((:CryptDestroyKey, "ADVAPI32.dll"), stdcall, Int32,
      (Csize_t,),
      hKey)
# hKey : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CryptDestroyKey(
    uintptr_t hKey);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.CryptDestroyKey(hKey)
-- hKey : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const CryptDestroyKey = lib.func('__stdcall', 'CryptDestroyKey', 'int32_t', ['uintptr_t']);
// CryptDestroyKey(hKey)
// hKey : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  CryptDestroyKey: { parameters: ["usize"], result: "i32" },
});
// lib.symbols.CryptDestroyKey(hKey)
// hKey : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CryptDestroyKey(
    size_t hKey);
C, "ADVAPI32.dll");
// $ffi->CryptDestroyKey(hKey);
// hKey : UINT_PTR
// 構造体/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 Advapi32 extends StdCallLibrary {
    Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
    boolean CryptDestroyKey(
        long hKey   // UINT_PTR
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun CryptDestroyKey = CryptDestroyKey(
    hKey : LibC::SizeT   # UINT_PTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CryptDestroyKeyNative = Int32 Function(UintPtr);
typedef CryptDestroyKeyDart = int Function(int);
final CryptDestroyKey = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<CryptDestroyKeyNative, CryptDestroyKeyDart>('CryptDestroyKey');
// hKey : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CryptDestroyKey(
  hKey: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'CryptDestroyKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CryptDestroyKey"
  c_CryptDestroyKey :: CUIntPtr -> IO CInt
-- hKey : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cryptdestroykey =
  foreign "CryptDestroyKey"
    (size_t @-> returning int32_t)
(* hKey : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("CryptDestroyKey" crypt-destroy-key :convention :stdcall) :int32
  (h-key :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CryptDestroyKey = Win32::API::More->new('ADVAPI32',
    'BOOL CryptDestroyKey(WPARAM hKey)');
# my $ret = $CryptDestroyKey->Call($hKey);
# hKey : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。