Win32 API 日本語リファレンス
ホームUI.Shell › FindExecutableW

FindExecutableW

関数
ファイル(Unicode)に関連付けられた実行ファイルを検索する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HINSTANCE FindExecutableW(
    LPCWSTR lpFile,
    LPCWSTR lpDirectory,   // optional
    LPWSTR lpResult
);

パラメーター

名前方向
lpFileLPCWSTRin
lpDirectoryLPCWSTRinoptional
lpResultLPWSTRout

戻り値の型: HINSTANCE

各言語での呼び出し定義

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

HINSTANCE FindExecutableW(
    LPCWSTR lpFile,
    LPCWSTR lpDirectory,   // optional
    LPWSTR lpResult
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr FindExecutableW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpDirectory,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpResult   // LPWSTR out
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function FindExecutableW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpDirectory As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpResult As System.Text.StringBuilder   ' LPWSTR out
) As IntPtr
End Function
' lpFile : LPCWSTR
' lpDirectory : LPCWSTR optional
' lpResult : LPWSTR out
Declare PtrSafe Function FindExecutableW Lib "shell32" ( _
    ByVal lpFile As LongPtr, _
    ByVal lpDirectory As LongPtr, _
    ByVal lpResult As LongPtr) 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

FindExecutableW = ctypes.windll.shell32.FindExecutableW
FindExecutableW.restype = ctypes.c_void_p
FindExecutableW.argtypes = [
    wintypes.LPCWSTR,  # lpFile : LPCWSTR
    wintypes.LPCWSTR,  # lpDirectory : LPCWSTR optional
    wintypes.LPWSTR,  # lpResult : LPWSTR out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
FindExecutableW = Fiddle::Function.new(
  lib['FindExecutableW'],
  [
    Fiddle::TYPE_VOIDP,  # lpFile : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpDirectory : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpResult : LPWSTR out
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn FindExecutableW(
        lpFile: *const u16,  // LPCWSTR
        lpDirectory: *const u16,  // LPCWSTR optional
        lpResult: *mut u16  // LPWSTR out
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindExecutableW([MarshalAs(UnmanagedType.LPWStr)] string lpFile, [MarshalAs(UnmanagedType.LPWStr)] string lpDirectory, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_FindExecutableW' -Namespace Win32 -PassThru
# $api::FindExecutableW(lpFile, lpDirectory, lpResult)
#uselib "SHELL32.dll"
#func global FindExecutableW "FindExecutableW" wptr, wptr, wptr
; FindExecutableW lpFile, lpDirectory, varptr(lpResult)   ; 戻り値は stat
; lpFile : LPCWSTR -> "wptr"
; lpDirectory : LPCWSTR optional -> "wptr"
; lpResult : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global FindExecutableW "FindExecutableW" wstr, wstr, var
; res = FindExecutableW(lpFile, lpDirectory, lpResult)
; lpFile : LPCWSTR -> "wstr"
; lpDirectory : LPCWSTR optional -> "wstr"
; lpResult : LPWSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HINSTANCE FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
#uselib "SHELL32.dll"
#cfunc global FindExecutableW "FindExecutableW" wstr, wstr, var
; res = FindExecutableW(lpFile, lpDirectory, lpResult)
; lpFile : LPCWSTR -> "wstr"
; lpDirectory : LPCWSTR optional -> "wstr"
; lpResult : LPWSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procFindExecutableW = shell32.NewProc("FindExecutableW")
)

// lpFile (LPCWSTR), lpDirectory (LPCWSTR optional), lpResult (LPWSTR out)
r1, _, err := procFindExecutableW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFile))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpDirectory))),
	uintptr(lpResult),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HINSTANCE
function FindExecutableW(
  lpFile: PWideChar;   // LPCWSTR
  lpDirectory: PWideChar;   // LPCWSTR optional
  lpResult: PWideChar   // LPWSTR out
): THandle; stdcall;
  external 'SHELL32.dll' name 'FindExecutableW';
result := DllCall("SHELL32\FindExecutableW"
    , "WStr", lpFile   ; LPCWSTR
    , "WStr", lpDirectory   ; LPCWSTR optional
    , "Ptr", lpResult   ; LPWSTR out
    , "Ptr")   ; return: HINSTANCE
●FindExecutableW(lpFile, lpDirectory, lpResult) = DLL("SHELL32.dll", "void* FindExecutableW(char*, char*, char*)")
# 呼び出し: FindExecutableW(lpFile, lpDirectory, lpResult)
# lpFile : LPCWSTR -> "char*"
# lpDirectory : LPCWSTR optional -> "char*"
# lpResult : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。