ホーム › System.Console › ConsoleControl
ConsoleControl
関数コンソールサブシステムへ制御コマンドを送る内部関数。
シグネチャ
// USER32.dll
#include <windows.h>
NTSTATUS ConsoleControl(
CONSOLECONTROL Command,
void* ConsoleInformation,
DWORD ConsoleInformationLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Command | CONSOLECONTROL | in | 実行するコンソール制御コマンドを示すCONSOLECONTROL列挙値。 |
| ConsoleInformation | void* | in | コマンドに対応する入出力データ構造体へのポインタ。 |
| ConsoleInformationLength | DWORD | in | ConsoleInformationが指すデータのサイズ(バイト)。 |
戻り値の型: 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 // NTSTATUSfunction 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)。const std = @import("std");
extern "user32" fn ConsoleControl(
Command: i32, // CONSOLECONTROL
ConsoleInformation: ?*anyopaque, // void*
ConsoleInformationLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc ConsoleControl(
Command: int32, # CONSOLECONTROL
ConsoleInformation: pointer, # void*
ConsoleInformationLength: uint32 # DWORD
): int32 {.importc: "ConsoleControl", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int ConsoleControl(
int Command, // CONSOLECONTROL
void* ConsoleInformation, // void*
uint ConsoleInformationLength // DWORD
);ccall((:ConsoleControl, "USER32.dll"), stdcall, Int32,
(Int32, Ptr{Cvoid}, UInt32),
Command, ConsoleInformation, ConsoleInformationLength)
# Command : CONSOLECONTROL -> Int32
# ConsoleInformation : void* -> Ptr{Cvoid}
# ConsoleInformationLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ConsoleControl(
int32_t Command,
void* ConsoleInformation,
uint32_t ConsoleInformationLength);
]]
local user32 = ffi.load("user32")
-- user32.ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
-- Command : CONSOLECONTROL
-- ConsoleInformation : void*
-- ConsoleInformationLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const ConsoleControl = lib.func('__stdcall', 'ConsoleControl', 'int32_t', ['int32_t', 'void *', 'uint32_t']);
// ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
// Command : CONSOLECONTROL -> 'int32_t'
// ConsoleInformation : void* -> 'void *'
// ConsoleInformationLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
ConsoleControl: { parameters: ["i32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength)
// Command : CONSOLECONTROL -> "i32"
// ConsoleInformation : void* -> "pointer"
// ConsoleInformationLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ConsoleControl(
int32_t Command,
void* ConsoleInformation,
uint32_t ConsoleInformationLength);
C, "USER32.dll");
// $ffi->ConsoleControl(Command, ConsoleInformation, ConsoleInformationLength);
// Command : CONSOLECONTROL
// ConsoleInformation : void*
// ConsoleInformationLength : DWORD
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
int ConsoleControl(
int Command, // CONSOLECONTROL
Pointer ConsoleInformation, // void*
int ConsoleInformationLength // DWORD
);
}@[Link("user32")]
lib LibUSER32
fun ConsoleControl = ConsoleControl(
Command : Int32, # CONSOLECONTROL
ConsoleInformation : Void*, # void*
ConsoleInformationLength : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ConsoleControlNative = Int32 Function(Int32, Pointer<Void>, Uint32);
typedef ConsoleControlDart = int Function(int, Pointer<Void>, int);
final ConsoleControl = DynamicLibrary.open('USER32.dll')
.lookupFunction<ConsoleControlNative, ConsoleControlDart>('ConsoleControl');
// Command : CONSOLECONTROL -> Int32
// ConsoleInformation : void* -> Pointer<Void>
// ConsoleInformationLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConsoleControl(
Command: Integer; // CONSOLECONTROL
ConsoleInformation: Pointer; // void*
ConsoleInformationLength: DWORD // DWORD
): Integer; stdcall;
external 'USER32.dll' name 'ConsoleControl';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConsoleControl"
c_ConsoleControl :: Int32 -> Ptr () -> Word32 -> IO Int32
-- Command : CONSOLECONTROL -> Int32
-- ConsoleInformation : void* -> Ptr ()
-- ConsoleInformationLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let consolecontrol =
foreign "ConsoleControl"
(int32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* Command : CONSOLECONTROL -> int32_t *)
(* ConsoleInformation : void* -> (ptr void) *)
(* ConsoleInformationLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("ConsoleControl" console-control :convention :stdcall) :int32
(command :int32) ; CONSOLECONTROL
(console-information :pointer) ; void*
(console-information-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConsoleControl = Win32::API::More->new('USER32',
'int ConsoleControl(int Command, LPVOID ConsoleInformation, DWORD ConsoleInformationLength)');
# my $ret = $ConsoleControl->Call($Command, $ConsoleInformation, $ConsoleInformationLength);
# Command : CONSOLECONTROL -> int
# ConsoleInformation : void* -> LPVOID
# ConsoleInformationLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型