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

FindFileInPath

関数
検索パスとファイル識別子からファイルを探索する。
DLLdbghelp.dll呼出規約winapi

シグネチャ

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

BOOL FindFileInPath(
    HANDLE hprocess,
    LPCSTR SearchPathA,
    LPCSTR FileName,
    void* id,
    DWORD two,
    DWORD three,
    DWORD flags,
    LPSTR FilePath
);

パラメーター

名前方向説明
hprocessHANDLEin検索コンテキストとなるプロセスのハンドル。
SearchPathALPCSTRinファイルを探す検索パスを指すANSI文字列。NULL可。
FileNameLPCSTRin検索対象のファイル名を指すANSI文字列。
idvoid*inシンボル照合に使う識別子(タイムスタンプやGUID等)へのポインタ。
twoDWORDin照合に使う第2の値(サイズ等)。flagsの解釈に依存する。
threeDWORDin照合に使う第3の値。flagsの解釈に依存する。
flagsDWORDinid・two・threeの解釈方法を指定するフラグ。SSRVOPT_系の値。
FilePathLPSTRout見つかったファイルの完全パスを受け取る出力バッファ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL FindFileInPath(
    HANDLE hprocess,
    LPCSTR SearchPathA,
    LPCSTR FileName,
    void* id,
    DWORD two,
    DWORD three,
    DWORD flags,
    LPSTR FilePath
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", ExactSpelling = true)]
static extern bool FindFileInPath(
    IntPtr hprocess,   // HANDLE
    [MarshalAs(UnmanagedType.LPStr)] string SearchPathA,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string FileName,   // LPCSTR
    IntPtr id,   // void*
    uint two,   // DWORD
    uint three,   // DWORD
    uint flags,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder FilePath   // LPSTR out
);
<DllImport("dbghelp.dll", ExactSpelling:=True)>
Public Shared Function FindFileInPath(
    hprocess As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPStr)> SearchPathA As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> FileName As String,   ' LPCSTR
    id As IntPtr,   ' void*
    two As UInteger,   ' DWORD
    three As UInteger,   ' DWORD
    flags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> FilePath As System.Text.StringBuilder   ' LPSTR out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hprocess : HANDLE
' SearchPathA : LPCSTR
' FileName : LPCSTR
' id : void*
' two : DWORD
' three : DWORD
' flags : DWORD
' FilePath : LPSTR out
Declare PtrSafe Function FindFileInPath Lib "dbghelp" ( _
    ByVal hprocess As LongPtr, _
    ByVal SearchPathA As String, _
    ByVal FileName As String, _
    ByVal id As LongPtr, _
    ByVal two As Long, _
    ByVal three As Long, _
    ByVal flags 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

FindFileInPath = ctypes.windll.dbghelp.FindFileInPath
FindFileInPath.restype = wintypes.BOOL
FindFileInPath.argtypes = [
    wintypes.HANDLE,  # hprocess : HANDLE
    wintypes.LPCSTR,  # SearchPathA : LPCSTR
    wintypes.LPCSTR,  # FileName : LPCSTR
    ctypes.POINTER(None),  # id : void*
    wintypes.DWORD,  # two : DWORD
    wintypes.DWORD,  # three : DWORD
    wintypes.DWORD,  # flags : DWORD
    wintypes.LPSTR,  # FilePath : LPSTR out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procFindFileInPath = dbghelp.NewProc("FindFileInPath")
)

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

extern "dbghelp" fn FindFileInPath(
    hprocess: ?*anyopaque, // HANDLE
    SearchPathA: [*c]const u8, // LPCSTR
    FileName: [*c]const u8, // LPCSTR
    id: ?*anyopaque, // void*
    two: u32, // DWORD
    three: u32, // DWORD
    flags: u32, // DWORD
    FilePath: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) i32;
proc FindFileInPath(
    hprocess: pointer,  # HANDLE
    SearchPathA: cstring,  # LPCSTR
    FileName: cstring,  # LPCSTR
    id: pointer,  # void*
    two: uint32,  # DWORD
    three: uint32,  # DWORD
    flags: uint32,  # DWORD
    FilePath: ptr char  # LPSTR out
): int32 {.importc: "FindFileInPath", stdcall, dynlib: "dbghelp.dll".}
pragma(lib, "dbghelp");
extern(Windows)
int FindFileInPath(
    void* hprocess,   // HANDLE
    const(char)* SearchPathA,   // LPCSTR
    const(char)* FileName,   // LPCSTR
    void* id,   // void*
    uint two,   // DWORD
    uint three,   // DWORD
    uint flags,   // DWORD
    char* FilePath   // LPSTR out
);
ccall((:FindFileInPath, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, Cstring, Ptr{Cvoid}, UInt32, UInt32, UInt32, Ptr{UInt8}),
      hprocess, SearchPathA, FileName, id, two, three, flags, FilePath)
# hprocess : HANDLE -> Ptr{Cvoid}
# SearchPathA : LPCSTR -> Cstring
# FileName : LPCSTR -> Cstring
# id : void* -> Ptr{Cvoid}
# two : DWORD -> UInt32
# three : DWORD -> UInt32
# flags : DWORD -> UInt32
# FilePath : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t FindFileInPath(
    void* hprocess,
    const char* SearchPathA,
    const char* FileName,
    void* id,
    uint32_t two,
    uint32_t three,
    uint32_t flags,
    char* FilePath);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, FilePath)
-- hprocess : HANDLE
-- SearchPathA : LPCSTR
-- FileName : LPCSTR
-- id : void*
-- two : DWORD
-- three : DWORD
-- flags : DWORD
-- FilePath : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const FindFileInPath = lib.func('__stdcall', 'FindFileInPath', 'int32_t', ['void *', 'str', 'str', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'char *']);
// FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, FilePath)
// hprocess : HANDLE -> 'void *'
// SearchPathA : LPCSTR -> 'str'
// FileName : LPCSTR -> 'str'
// id : void* -> 'void *'
// two : DWORD -> 'uint32_t'
// three : DWORD -> 'uint32_t'
// flags : DWORD -> 'uint32_t'
// FilePath : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  FindFileInPath: { parameters: ["pointer", "buffer", "buffer", "pointer", "u32", "u32", "u32", "buffer"], result: "i32" },
});
// lib.symbols.FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, FilePath)
// hprocess : HANDLE -> "pointer"
// SearchPathA : LPCSTR -> "buffer"
// FileName : LPCSTR -> "buffer"
// id : void* -> "pointer"
// two : DWORD -> "u32"
// three : DWORD -> "u32"
// flags : DWORD -> "u32"
// FilePath : LPSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t FindFileInPath(
    void* hprocess,
    const char* SearchPathA,
    const char* FileName,
    void* id,
    uint32_t two,
    uint32_t three,
    uint32_t flags,
    char* FilePath);
C, "dbghelp.dll");
// $ffi->FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, FilePath);
// hprocess : HANDLE
// SearchPathA : LPCSTR
// FileName : LPCSTR
// id : void*
// two : DWORD
// three : DWORD
// flags : DWORD
// FilePath : LPSTR out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Dbghelp extends StdCallLibrary {
    Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class);
    boolean FindFileInPath(
        Pointer hprocess,   // HANDLE
        String SearchPathA,   // LPCSTR
        String FileName,   // LPCSTR
        Pointer id,   // void*
        int two,   // DWORD
        int three,   // DWORD
        int flags,   // DWORD
        byte[] FilePath   // LPSTR out
    );
}
@[Link("dbghelp")]
lib Libdbghelp
  fun FindFileInPath = FindFileInPath(
    hprocess : Void*,   # HANDLE
    SearchPathA : UInt8*,   # LPCSTR
    FileName : UInt8*,   # LPCSTR
    id : Void*,   # void*
    two : UInt32,   # DWORD
    three : UInt32,   # DWORD
    flags : UInt32,   # DWORD
    FilePath : UInt8*   # LPSTR out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef FindFileInPathNative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, Uint32, Uint32, Uint32, Pointer<Utf8>);
typedef FindFileInPathDart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, int, int, int, Pointer<Utf8>);
final FindFileInPath = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<FindFileInPathNative, FindFileInPathDart>('FindFileInPath');
// hprocess : HANDLE -> Pointer<Void>
// SearchPathA : LPCSTR -> Pointer<Utf8>
// FileName : LPCSTR -> Pointer<Utf8>
// id : void* -> Pointer<Void>
// two : DWORD -> Uint32
// three : DWORD -> Uint32
// flags : DWORD -> Uint32
// FilePath : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FindFileInPath(
  hprocess: THandle;   // HANDLE
  SearchPathA: PAnsiChar;   // LPCSTR
  FileName: PAnsiChar;   // LPCSTR
  id: Pointer;   // void*
  two: DWORD;   // DWORD
  three: DWORD;   // DWORD
  flags: DWORD;   // DWORD
  FilePath: PAnsiChar   // LPSTR out
): BOOL; stdcall;
  external 'dbghelp.dll' name 'FindFileInPath';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "FindFileInPath"
  c_FindFileInPath :: Ptr () -> CString -> CString -> Ptr () -> Word32 -> Word32 -> Word32 -> CString -> IO CInt
-- hprocess : HANDLE -> Ptr ()
-- SearchPathA : LPCSTR -> CString
-- FileName : LPCSTR -> CString
-- id : void* -> Ptr ()
-- two : DWORD -> Word32
-- three : DWORD -> Word32
-- flags : DWORD -> Word32
-- FilePath : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let findfileinpath =
  foreign "FindFileInPath"
    ((ptr void) @-> string @-> string @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> string @-> returning int32_t)
(* hprocess : HANDLE -> (ptr void) *)
(* SearchPathA : LPCSTR -> string *)
(* FileName : LPCSTR -> string *)
(* id : void* -> (ptr void) *)
(* two : DWORD -> uint32_t *)
(* three : DWORD -> uint32_t *)
(* flags : DWORD -> uint32_t *)
(* FilePath : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("FindFileInPath" find-file-in-path :convention :stdcall) :int32
  (hprocess :pointer)   ; HANDLE
  (search-path-a :string)   ; LPCSTR
  (file-name :string)   ; LPCSTR
  (id :pointer)   ; void*
  (two :uint32)   ; DWORD
  (three :uint32)   ; DWORD
  (flags :uint32)   ; DWORD
  (file-path :pointer))   ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FindFileInPath = Win32::API::More->new('dbghelp',
    'BOOL FindFileInPath(HANDLE hprocess, LPCSTR SearchPathA, LPCSTR FileName, LPVOID id, DWORD two, DWORD three, DWORD flags, LPSTR FilePath)');
# my $ret = $FindFileInPath->Call($hprocess, $SearchPathA, $FileName, $id, $two, $three, $flags, $FilePath);
# hprocess : HANDLE -> HANDLE
# SearchPathA : LPCSTR -> LPCSTR
# FileName : LPCSTR -> LPCSTR
# id : void* -> LPVOID
# two : DWORD -> DWORD
# three : DWORD -> DWORD
# flags : DWORD -> DWORD
# FilePath : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。