ホーム › System.Console › ReadConsoleInputExW
ReadConsoleInputExW
関数フラグ指定付きでコンソール入力レコードを読み取る拡張関数(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL ReadConsoleInputExW(
HANDLE hConsoleInput,
INPUT_RECORD* lpBuffer,
DWORD nLength,
DWORD* lpNumberOfEventsRead,
WORD wFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hConsoleInput | HANDLE | in |
| lpBuffer | INPUT_RECORD* | out |
| nLength | DWORD | in |
| lpNumberOfEventsRead | DWORD* | out |
| wFlags | WORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL ReadConsoleInputExW(
HANDLE hConsoleInput,
INPUT_RECORD* lpBuffer,
DWORD nLength,
DWORD* lpNumberOfEventsRead,
WORD wFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool ReadConsoleInputExW(
IntPtr hConsoleInput, // HANDLE
IntPtr lpBuffer, // INPUT_RECORD* out
uint nLength, // DWORD
out uint lpNumberOfEventsRead, // DWORD* out
ushort wFlags // WORD
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ReadConsoleInputExW(
hConsoleInput As IntPtr, ' HANDLE
lpBuffer As IntPtr, ' INPUT_RECORD* out
nLength As UInteger, ' DWORD
<Out> ByRef lpNumberOfEventsRead As UInteger, ' DWORD* out
wFlags As UShort ' WORD
) As Boolean
End Function' hConsoleInput : HANDLE
' lpBuffer : INPUT_RECORD* out
' nLength : DWORD
' lpNumberOfEventsRead : DWORD* out
' wFlags : WORD
Declare PtrSafe Function ReadConsoleInputExW Lib "kernel32" ( _
ByVal hConsoleInput As LongPtr, _
ByVal lpBuffer As LongPtr, _
ByVal nLength As Long, _
ByRef lpNumberOfEventsRead As Long, _
ByVal wFlags As Integer) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ReadConsoleInputExW = ctypes.windll.kernel32.ReadConsoleInputExW
ReadConsoleInputExW.restype = wintypes.BOOL
ReadConsoleInputExW.argtypes = [
wintypes.HANDLE, # hConsoleInput : HANDLE
ctypes.c_void_p, # lpBuffer : INPUT_RECORD* out
wintypes.DWORD, # nLength : DWORD
ctypes.POINTER(wintypes.DWORD), # lpNumberOfEventsRead : DWORD* out
ctypes.c_ushort, # wFlags : WORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
ReadConsoleInputExW = Fiddle::Function.new(
lib['ReadConsoleInputExW'],
[
Fiddle::TYPE_VOIDP, # hConsoleInput : HANDLE
Fiddle::TYPE_VOIDP, # lpBuffer : INPUT_RECORD* out
-Fiddle::TYPE_INT, # nLength : DWORD
Fiddle::TYPE_VOIDP, # lpNumberOfEventsRead : DWORD* out
-Fiddle::TYPE_SHORT, # wFlags : WORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn ReadConsoleInputExW(
hConsoleInput: *mut core::ffi::c_void, // HANDLE
lpBuffer: *mut INPUT_RECORD, // INPUT_RECORD* out
nLength: u32, // DWORD
lpNumberOfEventsRead: *mut u32, // DWORD* out
wFlags: u16 // WORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern bool ReadConsoleInputExW(IntPtr hConsoleInput, IntPtr lpBuffer, uint nLength, out uint lpNumberOfEventsRead, ushort wFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_ReadConsoleInputExW' -Namespace Win32 -PassThru
# $api::ReadConsoleInputExW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead, wFlags)#uselib "KERNEL32.dll"
#func global ReadConsoleInputExW "ReadConsoleInputExW" wptr, wptr, wptr, wptr, wptr
; ReadConsoleInputExW hConsoleInput, varptr(lpBuffer), nLength, varptr(lpNumberOfEventsRead), wFlags ; 戻り値は stat
; hConsoleInput : HANDLE -> "wptr"
; lpBuffer : INPUT_RECORD* out -> "wptr"
; nLength : DWORD -> "wptr"
; lpNumberOfEventsRead : DWORD* out -> "wptr"
; wFlags : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global ReadConsoleInputExW "ReadConsoleInputExW" sptr, var, int, var, int ; res = ReadConsoleInputExW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead, wFlags) ; hConsoleInput : HANDLE -> "sptr" ; lpBuffer : INPUT_RECORD* out -> "var" ; nLength : DWORD -> "int" ; lpNumberOfEventsRead : DWORD* out -> "var" ; wFlags : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global ReadConsoleInputExW "ReadConsoleInputExW" sptr, sptr, int, sptr, int ; res = ReadConsoleInputExW(hConsoleInput, varptr(lpBuffer), nLength, varptr(lpNumberOfEventsRead), wFlags) ; hConsoleInput : HANDLE -> "sptr" ; lpBuffer : INPUT_RECORD* out -> "sptr" ; nLength : DWORD -> "int" ; lpNumberOfEventsRead : DWORD* out -> "sptr" ; wFlags : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ReadConsoleInputExW(HANDLE hConsoleInput, INPUT_RECORD* lpBuffer, DWORD nLength, DWORD* lpNumberOfEventsRead, WORD wFlags) #uselib "KERNEL32.dll" #cfunc global ReadConsoleInputExW "ReadConsoleInputExW" intptr, var, int, var, int ; res = ReadConsoleInputExW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead, wFlags) ; hConsoleInput : HANDLE -> "intptr" ; lpBuffer : INPUT_RECORD* out -> "var" ; nLength : DWORD -> "int" ; lpNumberOfEventsRead : DWORD* out -> "var" ; wFlags : WORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ReadConsoleInputExW(HANDLE hConsoleInput, INPUT_RECORD* lpBuffer, DWORD nLength, DWORD* lpNumberOfEventsRead, WORD wFlags) #uselib "KERNEL32.dll" #cfunc global ReadConsoleInputExW "ReadConsoleInputExW" intptr, intptr, int, intptr, int ; res = ReadConsoleInputExW(hConsoleInput, varptr(lpBuffer), nLength, varptr(lpNumberOfEventsRead), wFlags) ; hConsoleInput : HANDLE -> "intptr" ; lpBuffer : INPUT_RECORD* out -> "intptr" ; nLength : DWORD -> "int" ; lpNumberOfEventsRead : DWORD* out -> "intptr" ; wFlags : WORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procReadConsoleInputExW = kernel32.NewProc("ReadConsoleInputExW")
)
// hConsoleInput (HANDLE), lpBuffer (INPUT_RECORD* out), nLength (DWORD), lpNumberOfEventsRead (DWORD* out), wFlags (WORD)
r1, _, err := procReadConsoleInputExW.Call(
uintptr(hConsoleInput),
uintptr(lpBuffer),
uintptr(nLength),
uintptr(lpNumberOfEventsRead),
uintptr(wFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ReadConsoleInputExW(
hConsoleInput: THandle; // HANDLE
lpBuffer: Pointer; // INPUT_RECORD* out
nLength: DWORD; // DWORD
lpNumberOfEventsRead: Pointer; // DWORD* out
wFlags: Word // WORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'ReadConsoleInputExW';result := DllCall("KERNEL32\ReadConsoleInputExW"
, "Ptr", hConsoleInput ; HANDLE
, "Ptr", lpBuffer ; INPUT_RECORD* out
, "UInt", nLength ; DWORD
, "Ptr", lpNumberOfEventsRead ; DWORD* out
, "UShort", wFlags ; WORD
, "Int") ; return: BOOL●ReadConsoleInputExW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead, wFlags) = DLL("KERNEL32.dll", "bool ReadConsoleInputExW(void*, void*, dword, void*, int)")
# 呼び出し: ReadConsoleInputExW(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead, wFlags)
# hConsoleInput : HANDLE -> "void*"
# lpBuffer : INPUT_RECORD* out -> "void*"
# nLength : DWORD -> "dword"
# lpNumberOfEventsRead : DWORD* out -> "void*"
# wFlags : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。