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

ConsoleControl

関数
コンソールサブシステムへ制御コマンドを送る内部関数。
DLLUSER32.dll呼出規約winapi

シグネチャ

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

NTSTATUS ConsoleControl(
    CONSOLECONTROL Command,
    void* ConsoleInformation,
    DWORD ConsoleInformationLength
);

パラメーター

名前方向
CommandCONSOLECONTROLin
ConsoleInformationvoid*in
ConsoleInformationLengthDWORDin

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS ConsoleControl(
    CONSOLECONTROL Command,
    void* ConsoleInformation,
    DWORD ConsoleInformationLength
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern int ConsoleControl(
    int Command,   // CONSOLECONTROL
    IntPtr ConsoleInformation,   // void*
    uint ConsoleInformationLength   // DWORD
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function ConsoleControl(
    Command As Integer,   ' CONSOLECONTROL
    ConsoleInformation As IntPtr,   ' void*
    ConsoleInformationLength As UInteger   ' DWORD
) As Integer
End Function
' Command : CONSOLECONTROL
' ConsoleInformation : void*
' ConsoleInformationLength : DWORD
Declare PtrSafe Function ConsoleControl Lib "user32" ( _
    ByVal Command As Long, _
    ByVal ConsoleInformation As LongPtr, _
    ByVal ConsoleInformationLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ConsoleControl = ctypes.windll.user32.ConsoleControl
ConsoleControl.restype = ctypes.c_int
ConsoleControl.argtypes = [
    ctypes.c_int,  # Command : CONSOLECONTROL
    ctypes.POINTER(None),  # ConsoleInformation : void*
    wintypes.DWORD,  # ConsoleInformationLength : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
ConsoleControl = Fiddle::Function.new(
  lib['ConsoleControl'],
  [
    Fiddle::TYPE_INT,  # Command : CONSOLECONTROL
    Fiddle::TYPE_VOIDP,  # ConsoleInformation : void*
    -Fiddle::TYPE_INT,  # ConsoleInformationLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn ConsoleControl(
        Command: i32,  // CONSOLECONTROL
        ConsoleInformation: *mut (),  // void*
        ConsoleInformationLength: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll")]
public static extern int ConsoleControl(int Command, IntPtr ConsoleInformation, uint ConsoleInformationLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ConsoleControl' -Namespace Win32 -PassThru
# $api::ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
#uselib "USER32.dll"
#func global ConsoleControl "ConsoleControl" sptr, sptr, sptr
; ConsoleControl Command, ConsoleInformation, ConsoleInformationLength   ; 戻り値は stat
; Command : CONSOLECONTROL -> "sptr"
; ConsoleInformation : void* -> "sptr"
; ConsoleInformationLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global ConsoleControl "ConsoleControl" int, sptr, int
; res = ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
; Command : CONSOLECONTROL -> "int"
; ConsoleInformation : void* -> "sptr"
; ConsoleInformationLength : DWORD -> "int"
; NTSTATUS ConsoleControl(CONSOLECONTROL Command, void* ConsoleInformation, DWORD ConsoleInformationLength)
#uselib "USER32.dll"
#cfunc global ConsoleControl "ConsoleControl" int, intptr, int
; res = ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
; Command : CONSOLECONTROL -> "int"
; ConsoleInformation : void* -> "intptr"
; ConsoleInformationLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procConsoleControl = user32.NewProc("ConsoleControl")
)

// Command (CONSOLECONTROL), ConsoleInformation (void*), ConsoleInformationLength (DWORD)
r1, _, err := procConsoleControl.Call(
	uintptr(Command),
	uintptr(ConsoleInformation),
	uintptr(ConsoleInformationLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function ConsoleControl(
  Command: Integer;   // CONSOLECONTROL
  ConsoleInformation: Pointer;   // void*
  ConsoleInformationLength: DWORD   // DWORD
): Integer; stdcall;
  external 'USER32.dll' name 'ConsoleControl';
result := DllCall("USER32\ConsoleControl"
    , "Int", Command   ; CONSOLECONTROL
    , "Ptr", ConsoleInformation   ; void*
    , "UInt", ConsoleInformationLength   ; DWORD
    , "Int")   ; return: NTSTATUS
●ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength) = DLL("USER32.dll", "int ConsoleControl(int, void*, dword)")
# 呼び出し: ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
# Command : CONSOLECONTROL -> "int"
# ConsoleInformation : void* -> "void*"
# ConsoleInformationLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。