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

GetConsoleInputExeNameW

関数
コンソール入力に関連付けられた実行ファイル名を取得する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

DWORD GetConsoleInputExeNameW(
    DWORD nBufferLength,
    LPWSTR lpBuffer
);

パラメーター

名前方向
nBufferLengthDWORDin
lpBufferLPWSTRout

戻り値の型: DWORD

各言語での呼び出し定義

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

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

GetConsoleInputExeNameW = ctypes.windll.kernel32.GetConsoleInputExeNameW
GetConsoleInputExeNameW.restype = wintypes.DWORD
GetConsoleInputExeNameW.argtypes = [
    wintypes.DWORD,  # nBufferLength : DWORD
    wintypes.LPWSTR,  # lpBuffer : LPWSTR out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetConsoleInputExeNameW = kernel32.NewProc("GetConsoleInputExeNameW")
)

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