FindExecutableA
関数ファイル(ANSI)に関連付けられた実行ファイルを検索する。
シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HINSTANCE FindExecutableA(
LPCSTR lpFile,
LPCSTR lpDirectory, // optional
LPSTR lpResult
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFile | LPCSTR | in |
| lpDirectory | LPCSTR | inoptional |
| lpResult | LPSTR | out |
戻り値の型: HINSTANCE
各言語での呼び出し定義
// SHELL32.dll (ANSI / -A)
#include <windows.h>
HINSTANCE FindExecutableA(
LPCSTR lpFile,
LPCSTR lpDirectory, // optional
LPSTR lpResult
);[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr FindExecutableA(
[MarshalAs(UnmanagedType.LPStr)] string lpFile, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpDirectory, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpResult // LPSTR out
);<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function FindExecutableA(
<MarshalAs(UnmanagedType.LPStr)> lpFile As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpDirectory As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> lpResult As System.Text.StringBuilder ' LPSTR out
) As IntPtr
End Function' lpFile : LPCSTR
' lpDirectory : LPCSTR optional
' lpResult : LPSTR out
Declare PtrSafe Function FindExecutableA Lib "shell32" ( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindExecutableA = ctypes.windll.shell32.FindExecutableA
FindExecutableA.restype = ctypes.c_void_p
FindExecutableA.argtypes = [
wintypes.LPCSTR, # lpFile : LPCSTR
wintypes.LPCSTR, # lpDirectory : LPCSTR optional
wintypes.LPSTR, # lpResult : LPSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
FindExecutableA = Fiddle::Function.new(
lib['FindExecutableA'],
[
Fiddle::TYPE_VOIDP, # lpFile : LPCSTR
Fiddle::TYPE_VOIDP, # lpDirectory : LPCSTR optional
Fiddle::TYPE_VOIDP, # lpResult : LPSTR out
],
Fiddle::TYPE_VOIDP)#[link(name = "shell32")]
extern "system" {
fn FindExecutableA(
lpFile: *const u8, // LPCSTR
lpDirectory: *const u8, // LPCSTR optional
lpResult: *mut u8 // LPSTR out
) -> *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 FindExecutableA([MarshalAs(UnmanagedType.LPStr)] string lpFile, [MarshalAs(UnmanagedType.LPStr)] string lpDirectory, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_FindExecutableA' -Namespace Win32 -PassThru
# $api::FindExecutableA(lpFile, lpDirectory, lpResult)#uselib "SHELL32.dll"
#func global FindExecutableA "FindExecutableA" sptr, sptr, sptr
; FindExecutableA lpFile, lpDirectory, varptr(lpResult) ; 戻り値は stat
; lpFile : LPCSTR -> "sptr"
; lpDirectory : LPCSTR optional -> "sptr"
; lpResult : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global FindExecutableA "FindExecutableA" str, str, var ; res = FindExecutableA(lpFile, lpDirectory, lpResult) ; lpFile : LPCSTR -> "str" ; lpDirectory : LPCSTR optional -> "str" ; lpResult : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global FindExecutableA "FindExecutableA" str, str, sptr ; res = FindExecutableA(lpFile, lpDirectory, varptr(lpResult)) ; lpFile : LPCSTR -> "str" ; lpDirectory : LPCSTR optional -> "str" ; lpResult : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HINSTANCE FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult) #uselib "SHELL32.dll" #cfunc global FindExecutableA "FindExecutableA" str, str, var ; res = FindExecutableA(lpFile, lpDirectory, lpResult) ; lpFile : LPCSTR -> "str" ; lpDirectory : LPCSTR optional -> "str" ; lpResult : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HINSTANCE FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult) #uselib "SHELL32.dll" #cfunc global FindExecutableA "FindExecutableA" str, str, intptr ; res = FindExecutableA(lpFile, lpDirectory, varptr(lpResult)) ; lpFile : LPCSTR -> "str" ; lpDirectory : LPCSTR optional -> "str" ; lpResult : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procFindExecutableA = shell32.NewProc("FindExecutableA")
)
// lpFile (LPCSTR), lpDirectory (LPCSTR optional), lpResult (LPSTR out)
r1, _, err := procFindExecutableA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFile))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpDirectory))),
uintptr(lpResult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HINSTANCEfunction FindExecutableA(
lpFile: PAnsiChar; // LPCSTR
lpDirectory: PAnsiChar; // LPCSTR optional
lpResult: PAnsiChar // LPSTR out
): THandle; stdcall;
external 'SHELL32.dll' name 'FindExecutableA';result := DllCall("SHELL32\FindExecutableA"
, "AStr", lpFile ; LPCSTR
, "AStr", lpDirectory ; LPCSTR optional
, "Ptr", lpResult ; LPSTR out
, "Ptr") ; return: HINSTANCE●FindExecutableA(lpFile, lpDirectory, lpResult) = DLL("SHELL32.dll", "void* FindExecutableA(char*, char*, char*)")
# 呼び出し: FindExecutableA(lpFile, lpDirectory, lpResult)
# lpFile : LPCSTR -> "char*"
# lpDirectory : LPCSTR optional -> "char*"
# lpResult : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。