ホーム › System.SubsystemForLinux › WslLaunchInteractive
WslLaunchInteractive
関数WSLディストリビューション上で対話的にコマンドを実行する。
シグネチャ
// Api-ms-win-wsl-api-l1-1-0.dll
#include <windows.h>
HRESULT WslLaunchInteractive(
LPCWSTR distributionName,
LPCWSTR command, // optional
BOOL useCurrentWorkingDirectory,
DWORD* exitCode
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| distributionName | LPCWSTR | in |
| command | LPCWSTR | inoptional |
| useCurrentWorkingDirectory | BOOL | in |
| exitCode | DWORD* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// Api-ms-win-wsl-api-l1-1-0.dll
#include <windows.h>
HRESULT WslLaunchInteractive(
LPCWSTR distributionName,
LPCWSTR command, // optional
BOOL useCurrentWorkingDirectory,
DWORD* exitCode
);[DllImport("Api-ms-win-wsl-api-l1-1-0.dll", ExactSpelling = true)]
static extern int WslLaunchInteractive(
[MarshalAs(UnmanagedType.LPWStr)] string distributionName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string command, // LPCWSTR optional
bool useCurrentWorkingDirectory, // BOOL
out uint exitCode // DWORD* out
);<DllImport("Api-ms-win-wsl-api-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function WslLaunchInteractive(
<MarshalAs(UnmanagedType.LPWStr)> distributionName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> command As String, ' LPCWSTR optional
useCurrentWorkingDirectory As Boolean, ' BOOL
<Out> ByRef exitCode As UInteger ' DWORD* out
) As Integer
End Function' distributionName : LPCWSTR
' command : LPCWSTR optional
' useCurrentWorkingDirectory : BOOL
' exitCode : DWORD* out
Declare PtrSafe Function WslLaunchInteractive Lib "api-ms-win-wsl-api-l1-1-0" ( _
ByVal distributionName As LongPtr, _
ByVal command As LongPtr, _
ByVal useCurrentWorkingDirectory As Long, _
ByRef exitCode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WslLaunchInteractive = ctypes.windll.LoadLibrary("Api-ms-win-wsl-api-l1-1-0.dll").WslLaunchInteractive
WslLaunchInteractive.restype = ctypes.c_int
WslLaunchInteractive.argtypes = [
wintypes.LPCWSTR, # distributionName : LPCWSTR
wintypes.LPCWSTR, # command : LPCWSTR optional
wintypes.BOOL, # useCurrentWorkingDirectory : BOOL
ctypes.POINTER(wintypes.DWORD), # exitCode : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('Api-ms-win-wsl-api-l1-1-0.dll')
WslLaunchInteractive = Fiddle::Function.new(
lib['WslLaunchInteractive'],
[
Fiddle::TYPE_VOIDP, # distributionName : LPCWSTR
Fiddle::TYPE_VOIDP, # command : LPCWSTR optional
Fiddle::TYPE_INT, # useCurrentWorkingDirectory : BOOL
Fiddle::TYPE_VOIDP, # exitCode : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-wsl-api-l1-1-0")]
extern "system" {
fn WslLaunchInteractive(
distributionName: *const u16, // LPCWSTR
command: *const u16, // LPCWSTR optional
useCurrentWorkingDirectory: i32, // BOOL
exitCode: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("Api-ms-win-wsl-api-l1-1-0.dll")]
public static extern int WslLaunchInteractive([MarshalAs(UnmanagedType.LPWStr)] string distributionName, [MarshalAs(UnmanagedType.LPWStr)] string command, bool useCurrentWorkingDirectory, out uint exitCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Api-ms-win-wsl-api-l1-1-0_WslLaunchInteractive' -Namespace Win32 -PassThru
# $api::WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, exitCode)#uselib "Api-ms-win-wsl-api-l1-1-0.dll"
#func global WslLaunchInteractive "WslLaunchInteractive" sptr, sptr, sptr, sptr
; WslLaunchInteractive distributionName, command, useCurrentWorkingDirectory, varptr(exitCode) ; 戻り値は stat
; distributionName : LPCWSTR -> "sptr"
; command : LPCWSTR optional -> "sptr"
; useCurrentWorkingDirectory : BOOL -> "sptr"
; exitCode : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "Api-ms-win-wsl-api-l1-1-0.dll" #cfunc global WslLaunchInteractive "WslLaunchInteractive" wstr, wstr, int, var ; res = WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, exitCode) ; distributionName : LPCWSTR -> "wstr" ; command : LPCWSTR optional -> "wstr" ; useCurrentWorkingDirectory : BOOL -> "int" ; exitCode : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "Api-ms-win-wsl-api-l1-1-0.dll" #cfunc global WslLaunchInteractive "WslLaunchInteractive" wstr, wstr, int, sptr ; res = WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, varptr(exitCode)) ; distributionName : LPCWSTR -> "wstr" ; command : LPCWSTR optional -> "wstr" ; useCurrentWorkingDirectory : BOOL -> "int" ; exitCode : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT WslLaunchInteractive(LPCWSTR distributionName, LPCWSTR command, BOOL useCurrentWorkingDirectory, DWORD* exitCode) #uselib "Api-ms-win-wsl-api-l1-1-0.dll" #cfunc global WslLaunchInteractive "WslLaunchInteractive" wstr, wstr, int, var ; res = WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, exitCode) ; distributionName : LPCWSTR -> "wstr" ; command : LPCWSTR optional -> "wstr" ; useCurrentWorkingDirectory : BOOL -> "int" ; exitCode : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT WslLaunchInteractive(LPCWSTR distributionName, LPCWSTR command, BOOL useCurrentWorkingDirectory, DWORD* exitCode) #uselib "Api-ms-win-wsl-api-l1-1-0.dll" #cfunc global WslLaunchInteractive "WslLaunchInteractive" wstr, wstr, int, intptr ; res = WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, varptr(exitCode)) ; distributionName : LPCWSTR -> "wstr" ; command : LPCWSTR optional -> "wstr" ; useCurrentWorkingDirectory : BOOL -> "int" ; exitCode : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_wsl_api_l1_1_0 = windows.NewLazySystemDLL("Api-ms-win-wsl-api-l1-1-0.dll")
procWslLaunchInteractive = api_ms_win_wsl_api_l1_1_0.NewProc("WslLaunchInteractive")
)
// distributionName (LPCWSTR), command (LPCWSTR optional), useCurrentWorkingDirectory (BOOL), exitCode (DWORD* out)
r1, _, err := procWslLaunchInteractive.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(distributionName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(command))),
uintptr(useCurrentWorkingDirectory),
uintptr(exitCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WslLaunchInteractive(
distributionName: PWideChar; // LPCWSTR
command: PWideChar; // LPCWSTR optional
useCurrentWorkingDirectory: BOOL; // BOOL
exitCode: Pointer // DWORD* out
): Integer; stdcall;
external 'Api-ms-win-wsl-api-l1-1-0.dll' name 'WslLaunchInteractive';result := DllCall("Api-ms-win-wsl-api-l1-1-0\WslLaunchInteractive"
, "WStr", distributionName ; LPCWSTR
, "WStr", command ; LPCWSTR optional
, "Int", useCurrentWorkingDirectory ; BOOL
, "Ptr", exitCode ; DWORD* out
, "Int") ; return: HRESULT●WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, exitCode) = DLL("Api-ms-win-wsl-api-l1-1-0.dll", "int WslLaunchInteractive(char*, char*, bool, void*)")
# 呼び出し: WslLaunchInteractive(distributionName, command, useCurrentWorkingDirectory, exitCode)
# distributionName : LPCWSTR -> "char*"
# command : LPCWSTR optional -> "char*"
# useCurrentWorkingDirectory : BOOL -> "bool"
# exitCode : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。