Win32 API 日本語リファレンス
ホームSystem.Console › CloseConsoleHandle

CloseConsoleHandle

関数
コンソールハンドルを閉じる内部関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

BOOL CloseConsoleHandle(
    HANDLE hConsole
);

パラメーター

名前方向
hConsoleHANDLEin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CloseConsoleHandle = ctypes.windll.kernel32.CloseConsoleHandle
CloseConsoleHandle.restype = wintypes.BOOL
CloseConsoleHandle.argtypes = [
    wintypes.HANDLE,  # hConsole : HANDLE
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCloseConsoleHandle = kernel32.NewProc("CloseConsoleHandle")
)

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