ホーム › System.Console › GetConsoleInputExeNameA
GetConsoleInputExeNameA
関数コンソール入力に関連付けられた実行ファイル名を取得する(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetConsoleInputExeNameA(
DWORD nBufferLength,
LPSTR lpBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| nBufferLength | DWORD | in | lpBufferの容量を文字数で示す。実行ファイル名を格納するのに十分な大きさを指定する。 |
| lpBuffer | LPSTR | out | 入力に関連付けられた実行ファイル名(ANSI)を受け取る文字列バッファ。 |
戻り値の型: 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 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetConsoleInputExeNameA "GetConsoleInputExeNameA" int, sptr ; res = GetConsoleInputExeNameA(nBufferLength, varptr(lpBuffer)) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; DWORD GetConsoleInputExeNameA(DWORD nBufferLength, LPSTR lpBuffer) #uselib "KERNEL32.dll" #cfunc global GetConsoleInputExeNameA "GetConsoleInputExeNameA" int, intptr ; res = GetConsoleInputExeNameA(nBufferLength, varptr(lpBuffer)) ; nBufferLength : DWORD -> "int" ; lpBuffer : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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)。const std = @import("std");
extern "kernel32" fn GetConsoleInputExeNameA(
nBufferLength: u32, // DWORD
lpBuffer: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) u32;proc GetConsoleInputExeNameA(
nBufferLength: uint32, # DWORD
lpBuffer: ptr char # LPSTR out
): uint32 {.importc: "GetConsoleInputExeNameA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
uint GetConsoleInputExeNameA(
uint nBufferLength, // DWORD
char* lpBuffer // LPSTR out
);ccall((:GetConsoleInputExeNameA, "KERNEL32.dll"), stdcall, UInt32,
(UInt32, Ptr{UInt8}),
nBufferLength, lpBuffer)
# nBufferLength : DWORD -> UInt32
# lpBuffer : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetConsoleInputExeNameA(
uint32_t nBufferLength,
char* lpBuffer);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetConsoleInputExeNameA(nBufferLength, lpBuffer)
-- nBufferLength : DWORD
-- lpBuffer : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetConsoleInputExeNameA = lib.func('__stdcall', 'GetConsoleInputExeNameA', 'uint32_t', ['uint32_t', 'char *']);
// GetConsoleInputExeNameA(nBufferLength, lpBuffer)
// nBufferLength : DWORD -> 'uint32_t'
// lpBuffer : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetConsoleInputExeNameA: { parameters: ["u32", "buffer"], result: "u32" },
});
// lib.symbols.GetConsoleInputExeNameA(nBufferLength, lpBuffer)
// nBufferLength : DWORD -> "u32"
// lpBuffer : LPSTR out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetConsoleInputExeNameA(
uint32_t nBufferLength,
char* lpBuffer);
C, "KERNEL32.dll");
// $ffi->GetConsoleInputExeNameA(nBufferLength, lpBuffer);
// nBufferLength : DWORD
// lpBuffer : LPSTR out
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.ASCII_OPTIONS);
int GetConsoleInputExeNameA(
int nBufferLength, // DWORD
byte[] lpBuffer // LPSTR out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetConsoleInputExeNameA = GetConsoleInputExeNameA(
nBufferLength : UInt32, # DWORD
lpBuffer : UInt8* # LPSTR out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetConsoleInputExeNameANative = Uint32 Function(Uint32, Pointer<Utf8>);
typedef GetConsoleInputExeNameADart = int Function(int, Pointer<Utf8>);
final GetConsoleInputExeNameA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetConsoleInputExeNameANative, GetConsoleInputExeNameADart>('GetConsoleInputExeNameA');
// nBufferLength : DWORD -> Uint32
// lpBuffer : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetConsoleInputExeNameA(
nBufferLength: DWORD; // DWORD
lpBuffer: PAnsiChar // LPSTR out
): DWORD; stdcall;
external 'KERNEL32.dll' name 'GetConsoleInputExeNameA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetConsoleInputExeNameA"
c_GetConsoleInputExeNameA :: Word32 -> CString -> IO Word32
-- nBufferLength : DWORD -> Word32
-- lpBuffer : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getconsoleinputexenamea =
foreign "GetConsoleInputExeNameA"
(uint32_t @-> string @-> returning uint32_t)
(* nBufferLength : DWORD -> uint32_t *)
(* lpBuffer : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetConsoleInputExeNameA" get-console-input-exe-name-a :convention :stdcall) :uint32
(n-buffer-length :uint32) ; DWORD
(lp-buffer :pointer)) ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetConsoleInputExeNameA = Win32::API::More->new('KERNEL32',
'DWORD GetConsoleInputExeNameA(DWORD nBufferLength, LPSTR lpBuffer)');
# my $ret = $GetConsoleInputExeNameA->Call($nBufferLength, $lpBuffer);
# nBufferLength : DWORD -> DWORD
# lpBuffer : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f GetConsoleInputExeNameW (Unicode版) — コンソール入力に関連付けられた実行ファイル名を取得する(Unicode版)。