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

GetConsoleCommandHistoryA

関数
指定した実行ファイルのコマンド履歴の内容を取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD GetConsoleCommandHistoryA(
    LPSTR Commands,
    DWORD CommandBufferLength,
    LPSTR ExeName
);

パラメーター

名前方向
CommandsLPSTRout
CommandBufferLengthDWORDin
ExeNameLPSTRin

戻り値の型: DWORD

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD GetConsoleCommandHistoryA(
    LPSTR Commands,
    DWORD CommandBufferLength,
    LPSTR ExeName
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint GetConsoleCommandHistoryA(
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Commands,   // LPSTR out
    uint CommandBufferLength,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string ExeName   // LPSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetConsoleCommandHistoryA(
    <MarshalAs(UnmanagedType.LPStr)> Commands As System.Text.StringBuilder,   ' LPSTR out
    CommandBufferLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> ExeName As String   ' LPSTR
) As UInteger
End Function
' Commands : LPSTR out
' CommandBufferLength : DWORD
' ExeName : LPSTR
Declare PtrSafe Function GetConsoleCommandHistoryA Lib "kernel32" ( _
    ByVal Commands As String, _
    ByVal CommandBufferLength As Long, _
    ByVal ExeName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetConsoleCommandHistoryA = ctypes.windll.kernel32.GetConsoleCommandHistoryA
GetConsoleCommandHistoryA.restype = wintypes.DWORD
GetConsoleCommandHistoryA.argtypes = [
    wintypes.LPSTR,  # Commands : LPSTR out
    wintypes.DWORD,  # CommandBufferLength : DWORD
    wintypes.LPCSTR,  # ExeName : LPSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetConsoleCommandHistoryA = Fiddle::Function.new(
  lib['GetConsoleCommandHistoryA'],
  [
    Fiddle::TYPE_VOIDP,  # Commands : LPSTR out
    -Fiddle::TYPE_INT,  # CommandBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # ExeName : LPSTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetConsoleCommandHistoryA(
        Commands: *mut u8,  // LPSTR out
        CommandBufferLength: u32,  // DWORD
        ExeName: *mut u8  // LPSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern uint GetConsoleCommandHistoryA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Commands, uint CommandBufferLength, [MarshalAs(UnmanagedType.LPStr)] string ExeName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetConsoleCommandHistoryA' -Namespace Win32 -PassThru
# $api::GetConsoleCommandHistoryA(Commands, CommandBufferLength, ExeName)
#uselib "KERNEL32.dll"
#func global GetConsoleCommandHistoryA "GetConsoleCommandHistoryA" sptr, sptr, sptr
; GetConsoleCommandHistoryA varptr(Commands), CommandBufferLength, ExeName   ; 戻り値は stat
; Commands : LPSTR out -> "sptr"
; CommandBufferLength : DWORD -> "sptr"
; ExeName : LPSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetConsoleCommandHistoryA "GetConsoleCommandHistoryA" var, int, str
; res = GetConsoleCommandHistoryA(Commands, CommandBufferLength, ExeName)
; Commands : LPSTR out -> "var"
; CommandBufferLength : DWORD -> "int"
; ExeName : LPSTR -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetConsoleCommandHistoryA(LPSTR Commands, DWORD CommandBufferLength, LPSTR ExeName)
#uselib "KERNEL32.dll"
#cfunc global GetConsoleCommandHistoryA "GetConsoleCommandHistoryA" var, int, str
; res = GetConsoleCommandHistoryA(Commands, CommandBufferLength, ExeName)
; Commands : LPSTR out -> "var"
; CommandBufferLength : DWORD -> "int"
; ExeName : LPSTR -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetConsoleCommandHistoryA = kernel32.NewProc("GetConsoleCommandHistoryA")
)

// Commands (LPSTR out), CommandBufferLength (DWORD), ExeName (LPSTR)
r1, _, err := procGetConsoleCommandHistoryA.Call(
	uintptr(Commands),
	uintptr(CommandBufferLength),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ExeName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetConsoleCommandHistoryA(
  Commands: PAnsiChar;   // LPSTR out
  CommandBufferLength: DWORD;   // DWORD
  ExeName: PAnsiChar   // LPSTR
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetConsoleCommandHistoryA';
result := DllCall("KERNEL32\GetConsoleCommandHistoryA"
    , "Ptr", Commands   ; LPSTR out
    , "UInt", CommandBufferLength   ; DWORD
    , "AStr", ExeName   ; LPSTR
    , "UInt")   ; return: DWORD
●GetConsoleCommandHistoryA(Commands, CommandBufferLength, ExeName) = DLL("KERNEL32.dll", "dword GetConsoleCommandHistoryA(char*, dword, char*)")
# 呼び出し: GetConsoleCommandHistoryA(Commands, CommandBufferLength, ExeName)
# Commands : LPSTR out -> "char*"
# CommandBufferLength : DWORD -> "dword"
# ExeName : LPSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。