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

GetConsoleCommandHistoryW

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

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetConsoleCommandHistoryW(
    LPWSTR Commands,
    DWORD CommandBufferLength,
    LPWSTR ExeName
);

パラメーター

名前方向
CommandsLPWSTRout
CommandBufferLengthDWORDin
ExeNameLPWSTRin

戻り値の型: DWORD

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetConsoleCommandHistoryW(
    LPWSTR Commands,
    DWORD CommandBufferLength,
    LPWSTR ExeName
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint GetConsoleCommandHistoryW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Commands,   // LPWSTR out
    uint CommandBufferLength,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string ExeName   // LPWSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetConsoleCommandHistoryW(
    <MarshalAs(UnmanagedType.LPWStr)> Commands As System.Text.StringBuilder,   ' LPWSTR out
    CommandBufferLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> ExeName As String   ' LPWSTR
) As UInteger
End Function
' Commands : LPWSTR out
' CommandBufferLength : DWORD
' ExeName : LPWSTR
Declare PtrSafe Function GetConsoleCommandHistoryW Lib "kernel32" ( _
    ByVal Commands As LongPtr, _
    ByVal CommandBufferLength As Long, _
    ByVal ExeName As LongPtr) 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

GetConsoleCommandHistoryW = ctypes.windll.kernel32.GetConsoleCommandHistoryW
GetConsoleCommandHistoryW.restype = wintypes.DWORD
GetConsoleCommandHistoryW.argtypes = [
    wintypes.LPWSTR,  # Commands : LPWSTR out
    wintypes.DWORD,  # CommandBufferLength : DWORD
    wintypes.LPCWSTR,  # ExeName : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetConsoleCommandHistoryW = kernel32.NewProc("GetConsoleCommandHistoryW")
)

// Commands (LPWSTR out), CommandBufferLength (DWORD), ExeName (LPWSTR)
r1, _, err := procGetConsoleCommandHistoryW.Call(
	uintptr(Commands),
	uintptr(CommandBufferLength),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ExeName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetConsoleCommandHistoryW(
  Commands: PWideChar;   // LPWSTR out
  CommandBufferLength: DWORD;   // DWORD
  ExeName: PWideChar   // LPWSTR
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetConsoleCommandHistoryW';
result := DllCall("KERNEL32\GetConsoleCommandHistoryW"
    , "Ptr", Commands   ; LPWSTR out
    , "UInt", CommandBufferLength   ; DWORD
    , "WStr", ExeName   ; LPWSTR
    , "UInt")   ; return: DWORD
●GetConsoleCommandHistoryW(Commands, CommandBufferLength, ExeName) = DLL("KERNEL32.dll", "dword GetConsoleCommandHistoryW(char*, dword, char*)")
# 呼び出し: GetConsoleCommandHistoryW(Commands, CommandBufferLength, ExeName)
# Commands : LPWSTR out -> "char*"
# CommandBufferLength : DWORD -> "dword"
# ExeName : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。