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

GetConsoleInputExeNameA

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

シグネチャ

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

DWORD GetConsoleInputExeNameA(
    DWORD nBufferLength,
    LPSTR lpBuffer
);

パラメーター

名前方向
nBufferLengthDWORDin
lpBufferLPSTRout

戻り値の型: DWORD

各言語での呼び出し定義

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

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetConsoleInputExeNameA = kernel32.NewProc("GetConsoleInputExeNameA")
)

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