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ファイルを探す検索パスを指すANSI文字列。
FileNameLPCSTRin検索対象のファイル名を指すANSI文字列。
oneDWORDin照合に使う第1の値(識別子等)。
twoDWORDin照合に使う第2の値(サイズ等)。
threeDWORDin照合に使う第3の値。
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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "dbghelp" fn FindFileInSearchPath(
    hprocess: ?*anyopaque, // HANDLE
    SearchPathA: [*c]const u8, // LPCSTR
    FileName: [*c]const u8, // LPCSTR
    one: u32, // DWORD
    two: u32, // DWORD
    three: u32, // DWORD
    FilePath: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) i32;
proc FindFileInSearchPath(
    hprocess: pointer,  # HANDLE
    SearchPathA: cstring,  # LPCSTR
    FileName: cstring,  # LPCSTR
    one: uint32,  # DWORD
    two: uint32,  # DWORD
    three: uint32,  # DWORD
    FilePath: ptr char  # LPSTR out
): int32 {.importc: "FindFileInSearchPath", stdcall, dynlib: "dbghelp.dll".}
pragma(lib, "dbghelp");
extern(Windows)
int FindFileInSearchPath(
    void* hprocess,   // HANDLE
    const(char)* SearchPathA,   // LPCSTR
    const(char)* FileName,   // LPCSTR
    uint one,   // DWORD
    uint two,   // DWORD
    uint three,   // DWORD
    char* FilePath   // LPSTR out
);
ccall((:FindFileInSearchPath, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, Cstring, UInt32, UInt32, UInt32, Ptr{UInt8}),
      hprocess, SearchPathA, FileName, one, two, three, FilePath)
# hprocess : HANDLE -> Ptr{Cvoid}
# SearchPathA : LPCSTR -> Cstring
# FileName : LPCSTR -> Cstring
# one : DWORD -> UInt32
# two : DWORD -> UInt32
# three : DWORD -> UInt32
# FilePath : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t FindFileInSearchPath(
    void* hprocess,
    const char* SearchPathA,
    const char* FileName,
    uint32_t one,
    uint32_t two,
    uint32_t three,
    char* FilePath);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
-- hprocess : HANDLE
-- SearchPathA : LPCSTR
-- FileName : LPCSTR
-- one : DWORD
-- two : DWORD
-- three : DWORD
-- FilePath : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const FindFileInSearchPath = lib.func('__stdcall', 'FindFileInSearchPath', 'int32_t', ['void *', 'str', 'str', 'uint32_t', 'uint32_t', 'uint32_t', 'char *']);
// FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
// hprocess : HANDLE -> 'void *'
// SearchPathA : LPCSTR -> 'str'
// FileName : LPCSTR -> 'str'
// one : DWORD -> 'uint32_t'
// two : DWORD -> 'uint32_t'
// three : DWORD -> 'uint32_t'
// FilePath : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  FindFileInSearchPath: { parameters: ["pointer", "buffer", "buffer", "u32", "u32", "u32", "buffer"], result: "i32" },
});
// lib.symbols.FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath)
// hprocess : HANDLE -> "pointer"
// SearchPathA : LPCSTR -> "buffer"
// FileName : LPCSTR -> "buffer"
// one : DWORD -> "u32"
// two : DWORD -> "u32"
// three : DWORD -> "u32"
// FilePath : LPSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t FindFileInSearchPath(
    void* hprocess,
    const char* SearchPathA,
    const char* FileName,
    uint32_t one,
    uint32_t two,
    uint32_t three,
    char* FilePath);
C, "dbghelp.dll");
// $ffi->FindFileInSearchPath(hprocess, SearchPathA, FileName, one, two, three, FilePath);
// hprocess : HANDLE
// SearchPathA : LPCSTR
// FileName : LPCSTR
// one : DWORD
// two : DWORD
// three : 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 FindFileInSearchPath(
        Pointer hprocess,   // HANDLE
        String SearchPathA,   // LPCSTR
        String FileName,   // LPCSTR
        int one,   // DWORD
        int two,   // DWORD
        int three,   // DWORD
        byte[] FilePath   // LPSTR out
    );
}
@[Link("dbghelp")]
lib Libdbghelp
  fun FindFileInSearchPath = FindFileInSearchPath(
    hprocess : Void*,   # HANDLE
    SearchPathA : UInt8*,   # LPCSTR
    FileName : UInt8*,   # LPCSTR
    one : UInt32,   # DWORD
    two : UInt32,   # DWORD
    three : 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 FindFileInSearchPathNative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Uint32, Uint32, Pointer<Utf8>);
typedef FindFileInSearchPathDart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, int, int, int, Pointer<Utf8>);
final FindFileInSearchPath = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<FindFileInSearchPathNative, FindFileInSearchPathDart>('FindFileInSearchPath');
// hprocess : HANDLE -> Pointer<Void>
// SearchPathA : LPCSTR -> Pointer<Utf8>
// FileName : LPCSTR -> Pointer<Utf8>
// one : DWORD -> Uint32
// two : DWORD -> Uint32
// three : DWORD -> Uint32
// FilePath : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let findfileinsearchpath =
  foreign "FindFileInSearchPath"
    ((ptr void) @-> string @-> string @-> uint32_t @-> uint32_t @-> uint32_t @-> string @-> returning int32_t)
(* hprocess : HANDLE -> (ptr void) *)
(* SearchPathA : LPCSTR -> string *)
(* FileName : LPCSTR -> string *)
(* one : DWORD -> uint32_t *)
(* two : DWORD -> uint32_t *)
(* three : 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 ("FindFileInSearchPath" find-file-in-search-path :convention :stdcall) :int32
  (hprocess :pointer)   ; HANDLE
  (search-path-a :string)   ; LPCSTR
  (file-name :string)   ; LPCSTR
  (one :uint32)   ; DWORD
  (two :uint32)   ; DWORD
  (three :uint32)   ; DWORD
  (file-path :pointer))   ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FindFileInSearchPath = Win32::API::More->new('dbghelp',
    'BOOL FindFileInSearchPath(HANDLE hprocess, LPCSTR SearchPathA, LPCSTR FileName, DWORD one, DWORD two, DWORD three, LPSTR FilePath)');
# my $ret = $FindFileInSearchPath->Call($hprocess, $SearchPathA, $FileName, $one, $two, $three, $FilePath);
# hprocess : HANDLE -> HANDLE
# SearchPathA : LPCSTR -> LPCSTR
# FileName : LPCSTR -> LPCSTR
# one : DWORD -> DWORD
# two : DWORD -> DWORD
# three : DWORD -> DWORD
# FilePath : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。