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

GetCommandLineW

関数
呼び出し元プロセスのコマンドライン文字列を取得する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

LPWSTR GetCommandLineW(void);

パラメーターなし。戻り値: LPWSTR

各言語での呼び出し定義

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

LPWSTR GetCommandLineW(void);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr GetCommandLineW();
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetCommandLineW() As IntPtr
End Function
Declare PtrSafe Function GetCommandLineW Lib "kernel32" () As LongPtr
' 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

GetCommandLineW = ctypes.windll.kernel32.GetCommandLineW
GetCommandLineW.restype = wintypes.LPWSTR
GetCommandLineW.argtypes = []
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetCommandLineW = Fiddle::Function.new(
  lib['GetCommandLineW'],
  [],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetCommandLineW() -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr GetCommandLineW();
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetCommandLineW' -Namespace Win32 -PassThru
# $api::GetCommandLineW()
#uselib "KERNEL32.dll"
#func global GetCommandLineW "GetCommandLineW"
; GetCommandLineW   ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetCommandLineW "GetCommandLineW"
; res = GetCommandLineW()
; LPWSTR GetCommandLineW()
#uselib "KERNEL32.dll"
#cfunc global GetCommandLineW "GetCommandLineW"
; res = GetCommandLineW()
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetCommandLineW = kernel32.NewProc("GetCommandLineW")
)

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