ホーム › System.Threading › WinExec
WinExec
関数指定のコマンドラインのアプリケーションを実行する(旧式)。
シグネチャ
// KERNEL32.dll
#include <windows.h>
DWORD WinExec(
LPCSTR lpCmdLine,
DWORD uCmdShow
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpCmdLine | LPCSTR | in |
| uCmdShow | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
DWORD WinExec(
LPCSTR lpCmdLine,
DWORD uCmdShow
);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern uint WinExec(
[MarshalAs(UnmanagedType.LPStr)] string lpCmdLine, // LPCSTR
uint uCmdShow // DWORD
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function WinExec(
<MarshalAs(UnmanagedType.LPStr)> lpCmdLine As String, ' LPCSTR
uCmdShow As UInteger ' DWORD
) As UInteger
End Function' lpCmdLine : LPCSTR
' uCmdShow : DWORD
Declare PtrSafe Function WinExec Lib "kernel32" ( _
ByVal lpCmdLine As String, _
ByVal uCmdShow As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WinExec = ctypes.windll.kernel32.WinExec
WinExec.restype = wintypes.DWORD
WinExec.argtypes = [
wintypes.LPCSTR, # lpCmdLine : LPCSTR
wintypes.DWORD, # uCmdShow : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
WinExec = Fiddle::Function.new(
lib['WinExec'],
[
Fiddle::TYPE_VOIDP, # lpCmdLine : LPCSTR
-Fiddle::TYPE_INT, # uCmdShow : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn WinExec(
lpCmdLine: *const u8, // LPCSTR
uCmdShow: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern uint WinExec([MarshalAs(UnmanagedType.LPStr)] string lpCmdLine, uint uCmdShow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_WinExec' -Namespace Win32 -PassThru
# $api::WinExec(lpCmdLine, uCmdShow)#uselib "KERNEL32.dll"
#func global WinExec "WinExec" sptr, sptr
; WinExec lpCmdLine, uCmdShow ; 戻り値は stat
; lpCmdLine : LPCSTR -> "sptr"
; uCmdShow : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global WinExec "WinExec" str, int
; res = WinExec(lpCmdLine, uCmdShow)
; lpCmdLine : LPCSTR -> "str"
; uCmdShow : DWORD -> "int"; DWORD WinExec(LPCSTR lpCmdLine, DWORD uCmdShow)
#uselib "KERNEL32.dll"
#cfunc global WinExec "WinExec" str, int
; res = WinExec(lpCmdLine, uCmdShow)
; lpCmdLine : LPCSTR -> "str"
; uCmdShow : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procWinExec = kernel32.NewProc("WinExec")
)
// lpCmdLine (LPCSTR), uCmdShow (DWORD)
r1, _, err := procWinExec.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpCmdLine))),
uintptr(uCmdShow),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction WinExec(
lpCmdLine: PAnsiChar; // LPCSTR
uCmdShow: DWORD // DWORD
): DWORD; stdcall;
external 'KERNEL32.dll' name 'WinExec';result := DllCall("KERNEL32\WinExec"
, "AStr", lpCmdLine ; LPCSTR
, "UInt", uCmdShow ; DWORD
, "UInt") ; return: DWORD●WinExec(lpCmdLine, uCmdShow) = DLL("KERNEL32.dll", "dword WinExec(char*, dword)")
# 呼び出し: WinExec(lpCmdLine, uCmdShow)
# lpCmdLine : LPCSTR -> "char*"
# uCmdShow : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。