Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › FindFileInSearchPath

FindFileInSearchPath

関数
指定した検索パス内からファイルを探索する。
DLLdbghelp.dll呼出規約winapi

シグネチャ

// dbghelp.dll
#include <windows.h>

BOOL FindFileInSearchPath(
    HANDLE hprocess,
    LPCSTR SearchPathA,
    LPCSTR FileName,
    DWORD one,
    DWORD two,
    DWORD three,
    LPSTR FilePath
);

パラメーター

名前方向
hprocessHANDLEin
SearchPathALPCSTRin
FileNameLPCSTRin
oneDWORDin
twoDWORDin
threeDWORDin
FilePathLPSTRout

戻り値の型: BOOL

各言語での呼び出し定義

// dbghelp.dll
#include <windows.h>

BOOL FindFileInSearchPath(
    HANDLE hprocess,
    LPCSTR SearchPathA,
    LPCSTR FileName,
    DWORD one,
    DWORD two,
    DWORD three,
    LPSTR FilePath
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", ExactSpelling = true)]
static extern bool FindFileInSearchPath(
    IntPtr hprocess,   // HANDLE
    [MarshalAs(UnmanagedType.LPStr)] string SearchPathA,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string FileName,   // LPCSTR
    uint one,   // DWORD
    uint two,   // DWORD
    uint three,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder FilePath   // LPSTR out
);
<DllImport("dbghelp.dll", ExactSpelling:=True)>
Public Shared Function FindFileInSearchPath(
    hprocess As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPStr)> SearchPathA As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> FileName As String,   ' LPCSTR
    one As UInteger,   ' DWORD
    two As UInteger,   ' DWORD
    three As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> FilePath As System.Text.StringBuilder   ' LPSTR out
) As Boolean
End Function
' hprocess : HANDLE
' SearchPathA : LPCSTR
' FileName : LPCSTR
' one : DWORD
' two : DWORD
' three : DWORD
' FilePath : LPSTR out
Declare PtrSafe Function FindFileInSearchPath Lib "dbghelp" ( _
    ByVal hprocess As LongPtr, _
    ByVal SearchPathA As String, _
    ByVal FileName As String, _
    ByVal one As Long, _
    ByVal two As Long, _
    ByVal three As Long, _
    ByVal FilePath As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindFileInSearchPath = ctypes.windll.dbghelp.FindFileInSearchPath
FindFileInSearchPath.restype = wintypes.BOOL
FindFileInSearchPath.argtypes = [
    wintypes.HANDLE,  # hprocess : HANDLE
    wintypes.LPCSTR,  # SearchPathA : LPCSTR
    wintypes.LPCSTR,  # FileName : LPCSTR
    wintypes.DWORD,  # one : DWORD
    wintypes.DWORD,  # two : DWORD
    wintypes.DWORD,  # three : DWORD
    wintypes.LPSTR,  # FilePath : LPSTR out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
FindFileInSearchPath = Fiddle::Function.new(
  lib['FindFileInSearchPath'],
  [
    Fiddle::TYPE_VOIDP,  # hprocess : HANDLE
    Fiddle::TYPE_VOIDP,  # SearchPathA : LPCSTR
    Fiddle::TYPE_VOIDP,  # FileName : LPCSTR
    -Fiddle::TYPE_INT,  # one : DWORD
    -Fiddle::TYPE_INT,  # two : DWORD
    -Fiddle::TYPE_INT,  # three : DWORD
    Fiddle::TYPE_VOIDP,  # FilePath : LPSTR out
  ],
  Fiddle::TYPE_INT)
#[link(name = "dbghelp")]
extern "system" {
    fn FindFileInSearchPath(
        hprocess: *mut core::ffi::c_void,  // HANDLE
        SearchPathA: *const u8,  // LPCSTR
        FileName: *const u8,  // LPCSTR
        one: u32,  // DWORD
        two: u32,  // DWORD
        three: u32,  // DWORD
        FilePath: *mut u8  // LPSTR out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll")]
public static extern bool FindFileInSearchPath(IntPtr hprocess, [MarshalAs(UnmanagedType.LPStr)] string SearchPathA, [MarshalAs(UnmanagedType.LPStr)] string FileName, uint one, uint two, uint three, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder FilePath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_FindFileInSearchPath' -Namespace Win32 -PassThru
# $api::FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
#uselib "dbghelp.dll"
#func global FindFileInSearchPath "FindFileInSearchPath" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; FindFileInSearchPath hprocess, SearchPathA, FileName, one, two, three, varptr(FilePath)   ; 戻り値は stat
; hprocess : HANDLE -> "sptr"
; SearchPathA : LPCSTR -> "sptr"
; FileName : LPCSTR -> "sptr"
; one : DWORD -> "sptr"
; two : DWORD -> "sptr"
; three : DWORD -> "sptr"
; FilePath : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dbghelp.dll"
#cfunc global FindFileInSearchPath "FindFileInSearchPath" sptr, str, str, int, int, int, var
; res = FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
; hprocess : HANDLE -> "sptr"
; SearchPathA : LPCSTR -> "str"
; FileName : LPCSTR -> "str"
; one : DWORD -> "int"
; two : DWORD -> "int"
; three : DWORD -> "int"
; FilePath : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL FindFileInSearchPath(HANDLE hprocess, LPCSTR SearchPathA, LPCSTR FileName, DWORD one, DWORD two, DWORD three, LPSTR FilePath)
#uselib "dbghelp.dll"
#cfunc global FindFileInSearchPath "FindFileInSearchPath" intptr, str, str, int, int, int, var
; res = FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
; hprocess : HANDLE -> "intptr"
; SearchPathA : LPCSTR -> "str"
; FileName : LPCSTR -> "str"
; one : DWORD -> "int"
; two : DWORD -> "int"
; three : DWORD -> "int"
; FilePath : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procFindFileInSearchPath = dbghelp.NewProc("FindFileInSearchPath")
)

// hprocess (HANDLE), SearchPathA (LPCSTR), FileName (LPCSTR), one (DWORD), two (DWORD), three (DWORD), FilePath (LPSTR out)
r1, _, err := procFindFileInSearchPath.Call(
	uintptr(hprocess),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SearchPathA))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
	uintptr(one),
	uintptr(two),
	uintptr(three),
	uintptr(FilePath),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function FindFileInSearchPath(
  hprocess: THandle;   // HANDLE
  SearchPathA: PAnsiChar;   // LPCSTR
  FileName: PAnsiChar;   // LPCSTR
  one: DWORD;   // DWORD
  two: DWORD;   // DWORD
  three: DWORD;   // DWORD
  FilePath: PAnsiChar   // LPSTR out
): BOOL; stdcall;
  external 'dbghelp.dll' name 'FindFileInSearchPath';
result := DllCall("dbghelp\FindFileInSearchPath"
    , "Ptr", hprocess   ; HANDLE
    , "AStr", SearchPathA   ; LPCSTR
    , "AStr", FileName   ; LPCSTR
    , "UInt", one   ; DWORD
    , "UInt", two   ; DWORD
    , "UInt", three   ; DWORD
    , "Ptr", FilePath   ; LPSTR out
    , "Int")   ; return: BOOL
●FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath) = DLL("dbghelp.dll", "bool FindFileInSearchPath(void*, char*, char*, dword, dword, dword, char*)")
# 呼び出し: FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
# hprocess : HANDLE -> "void*"
# SearchPathA : LPCSTR -> "char*"
# FileName : LPCSTR -> "char*"
# one : DWORD -> "dword"
# two : DWORD -> "dword"
# three : DWORD -> "dword"
# FilePath : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。