ホーム › System.Diagnostics.Debug › FindFileInPath
FindFileInPath
関数検索パスとファイル識別子からファイルを探索する。
シグネチャ
// dbghelp.dll
#include <windows.h>
BOOL FindFileInPath(
HANDLE hprocess,
LPCSTR SearchPathA,
LPCSTR FileName,
void* id,
DWORD two,
DWORD three,
DWORD flags,
LPSTR FilePath
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hprocess | HANDLE | in |
| SearchPathA | LPCSTR | in |
| FileName | LPCSTR | in |
| id | void* | in |
| two | DWORD | in |
| three | DWORD | in |
| flags | DWORD | in |
| FilePath | LPSTR | out |
戻り値の型: 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 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 方式にも切替可。#uselib "dbghelp.dll" #cfunc global FindFileInPath "FindFileInPath" sptr, str, str, sptr, int, int, int, sptr ; res = FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, varptr(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 -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr ; res = FindFileInPath(hprocess, SearchPathA, FileName, id, two, three, flags, varptr(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 -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。