ShellExecuteA
関数ファイルやプログラム(ANSI)に対し操作を実行する。
シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HINSTANCE ShellExecuteA(
HWND hwnd, // optional
LPCSTR lpOperation, // optional
LPCSTR lpFile,
LPCSTR lpParameters, // optional
LPCSTR lpDirectory, // optional
SHOW_WINDOW_CMD nShowCmd
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | inoptional |
| lpOperation | LPCSTR | inoptional |
| lpFile | LPCSTR | in |
| lpParameters | LPCSTR | inoptional |
| lpDirectory | LPCSTR | inoptional |
| nShowCmd | SHOW_WINDOW_CMD | in |
戻り値の型: HINSTANCE
各言語での呼び出し定義
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HINSTANCE ShellExecuteA(
HWND hwnd, // optional
LPCSTR lpOperation, // optional
LPCSTR lpFile,
LPCSTR lpParameters, // optional
LPCSTR lpDirectory, // optional
SHOW_WINDOW_CMD nShowCmd
);[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr ShellExecuteA(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPStr)] string lpOperation, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string lpFile, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpParameters, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string lpDirectory, // LPCSTR optional
int nShowCmd // SHOW_WINDOW_CMD
);<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ShellExecuteA(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPStr)> lpOperation As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> lpFile As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpParameters As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> lpDirectory As String, ' LPCSTR optional
nShowCmd As Integer ' SHOW_WINDOW_CMD
) As IntPtr
End Function' hwnd : HWND optional
' lpOperation : LPCSTR optional
' lpFile : LPCSTR
' lpParameters : LPCSTR optional
' lpDirectory : LPCSTR optional
' nShowCmd : SHOW_WINDOW_CMD
Declare PtrSafe Function ShellExecuteA Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ShellExecuteA = ctypes.windll.shell32.ShellExecuteA
ShellExecuteA.restype = ctypes.c_void_p
ShellExecuteA.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPCSTR, # lpOperation : LPCSTR optional
wintypes.LPCSTR, # lpFile : LPCSTR
wintypes.LPCSTR, # lpParameters : LPCSTR optional
wintypes.LPCSTR, # lpDirectory : LPCSTR optional
ctypes.c_int, # nShowCmd : SHOW_WINDOW_CMD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
ShellExecuteA = Fiddle::Function.new(
lib['ShellExecuteA'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # lpOperation : LPCSTR optional
Fiddle::TYPE_VOIDP, # lpFile : LPCSTR
Fiddle::TYPE_VOIDP, # lpParameters : LPCSTR optional
Fiddle::TYPE_VOIDP, # lpDirectory : LPCSTR optional
Fiddle::TYPE_INT, # nShowCmd : SHOW_WINDOW_CMD
],
Fiddle::TYPE_VOIDP)#[link(name = "shell32")]
extern "system" {
fn ShellExecuteA(
hwnd: *mut core::ffi::c_void, // HWND optional
lpOperation: *const u8, // LPCSTR optional
lpFile: *const u8, // LPCSTR
lpParameters: *const u8, // LPCSTR optional
lpDirectory: *const u8, // LPCSTR optional
nShowCmd: i32 // SHOW_WINDOW_CMD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr ShellExecuteA(IntPtr hwnd, [MarshalAs(UnmanagedType.LPStr)] string lpOperation, [MarshalAs(UnmanagedType.LPStr)] string lpFile, [MarshalAs(UnmanagedType.LPStr)] string lpParameters, [MarshalAs(UnmanagedType.LPStr)] string lpDirectory, int nShowCmd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_ShellExecuteA' -Namespace Win32 -PassThru
# $api::ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)#uselib "SHELL32.dll"
#func global ShellExecuteA "ShellExecuteA" sptr, sptr, sptr, sptr, sptr, sptr
; ShellExecuteA hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; lpOperation : LPCSTR optional -> "sptr"
; lpFile : LPCSTR -> "sptr"
; lpParameters : LPCSTR optional -> "sptr"
; lpDirectory : LPCSTR optional -> "sptr"
; nShowCmd : SHOW_WINDOW_CMD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global ShellExecuteA "ShellExecuteA" sptr, str, str, str, str, int
; res = ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
; hwnd : HWND optional -> "sptr"
; lpOperation : LPCSTR optional -> "str"
; lpFile : LPCSTR -> "str"
; lpParameters : LPCSTR optional -> "str"
; lpDirectory : LPCSTR optional -> "str"
; nShowCmd : SHOW_WINDOW_CMD -> "int"; HINSTANCE ShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, SHOW_WINDOW_CMD nShowCmd)
#uselib "SHELL32.dll"
#cfunc global ShellExecuteA "ShellExecuteA" intptr, str, str, str, str, int
; res = ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
; hwnd : HWND optional -> "intptr"
; lpOperation : LPCSTR optional -> "str"
; lpFile : LPCSTR -> "str"
; lpParameters : LPCSTR optional -> "str"
; lpDirectory : LPCSTR optional -> "str"
; nShowCmd : SHOW_WINDOW_CMD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procShellExecuteA = shell32.NewProc("ShellExecuteA")
)
// hwnd (HWND optional), lpOperation (LPCSTR optional), lpFile (LPCSTR), lpParameters (LPCSTR optional), lpDirectory (LPCSTR optional), nShowCmd (SHOW_WINDOW_CMD)
r1, _, err := procShellExecuteA.Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpOperation))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFile))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpParameters))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpDirectory))),
uintptr(nShowCmd),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HINSTANCEfunction ShellExecuteA(
hwnd: THandle; // HWND optional
lpOperation: PAnsiChar; // LPCSTR optional
lpFile: PAnsiChar; // LPCSTR
lpParameters: PAnsiChar; // LPCSTR optional
lpDirectory: PAnsiChar; // LPCSTR optional
nShowCmd: Integer // SHOW_WINDOW_CMD
): THandle; stdcall;
external 'SHELL32.dll' name 'ShellExecuteA';result := DllCall("SHELL32\ShellExecuteA"
, "Ptr", hwnd ; HWND optional
, "AStr", lpOperation ; LPCSTR optional
, "AStr", lpFile ; LPCSTR
, "AStr", lpParameters ; LPCSTR optional
, "AStr", lpDirectory ; LPCSTR optional
, "Int", nShowCmd ; SHOW_WINDOW_CMD
, "Ptr") ; return: HINSTANCE●ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) = DLL("SHELL32.dll", "void* ShellExecuteA(void*, char*, char*, char*, char*, int)")
# 呼び出し: ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
# hwnd : HWND optional -> "void*"
# lpOperation : LPCSTR optional -> "char*"
# lpFile : LPCSTR -> "char*"
# lpParameters : LPCSTR optional -> "char*"
# lpDirectory : LPCSTR optional -> "char*"
# nShowCmd : SHOW_WINDOW_CMD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。