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

GetConsoleScreenBufferInfoEx

関数
コンソール画面バッファの拡張情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL GetConsoleScreenBufferInfoEx(
    HANDLE hConsoleOutput,
    CONSOLE_SCREEN_BUFFER_INFOEX* lpConsoleScreenBufferInfoEx
);

パラメーター

名前方向
hConsoleOutputHANDLEin
lpConsoleScreenBufferInfoExCONSOLE_SCREEN_BUFFER_INFOEX*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

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

GetConsoleScreenBufferInfoEx = ctypes.windll.kernel32.GetConsoleScreenBufferInfoEx
GetConsoleScreenBufferInfoEx.restype = wintypes.BOOL
GetConsoleScreenBufferInfoEx.argtypes = [
    wintypes.HANDLE,  # hConsoleOutput : HANDLE
    ctypes.c_void_p,  # lpConsoleScreenBufferInfoEx : CONSOLE_SCREEN_BUFFER_INFOEX* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetConsoleScreenBufferInfoEx = Fiddle::Function.new(
  lib['GetConsoleScreenBufferInfoEx'],
  [
    Fiddle::TYPE_VOIDP,  # hConsoleOutput : HANDLE
    Fiddle::TYPE_VOIDP,  # lpConsoleScreenBufferInfoEx : CONSOLE_SCREEN_BUFFER_INFOEX* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetConsoleScreenBufferInfoEx(
        hConsoleOutput: *mut core::ffi::c_void,  // HANDLE
        lpConsoleScreenBufferInfoEx: *mut CONSOLE_SCREEN_BUFFER_INFOEX  // CONSOLE_SCREEN_BUFFER_INFOEX* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool GetConsoleScreenBufferInfoEx(IntPtr hConsoleOutput, IntPtr lpConsoleScreenBufferInfoEx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetConsoleScreenBufferInfoEx' -Namespace Win32 -PassThru
# $api::GetConsoleScreenBufferInfoEx(hConsoleOutput, lpConsoleScreenBufferInfoEx)
#uselib "KERNEL32.dll"
#func global GetConsoleScreenBufferInfoEx "GetConsoleScreenBufferInfoEx" sptr, sptr
; GetConsoleScreenBufferInfoEx hConsoleOutput, varptr(lpConsoleScreenBufferInfoEx)   ; 戻り値は stat
; hConsoleOutput : HANDLE -> "sptr"
; lpConsoleScreenBufferInfoEx : CONSOLE_SCREEN_BUFFER_INFOEX* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetConsoleScreenBufferInfoEx "GetConsoleScreenBufferInfoEx" sptr, var
; res = GetConsoleScreenBufferInfoEx(hConsoleOutput, lpConsoleScreenBufferInfoEx)
; hConsoleOutput : HANDLE -> "sptr"
; lpConsoleScreenBufferInfoEx : CONSOLE_SCREEN_BUFFER_INFOEX* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetConsoleScreenBufferInfoEx(HANDLE hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFOEX* lpConsoleScreenBufferInfoEx)
#uselib "KERNEL32.dll"
#cfunc global GetConsoleScreenBufferInfoEx "GetConsoleScreenBufferInfoEx" intptr, var
; res = GetConsoleScreenBufferInfoEx(hConsoleOutput, lpConsoleScreenBufferInfoEx)
; hConsoleOutput : HANDLE -> "intptr"
; lpConsoleScreenBufferInfoEx : CONSOLE_SCREEN_BUFFER_INFOEX* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetConsoleScreenBufferInfoEx = kernel32.NewProc("GetConsoleScreenBufferInfoEx")
)

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