ホーム › System.Diagnostics.Debug › SearchTreeForFileW
SearchTreeForFileW
関数ディレクトリツリーを再帰的に検索して指定ファイルを探す。
シグネチャ
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SearchTreeForFileW(
LPCWSTR RootPath,
LPCWSTR InputPathName,
LPWSTR OutputPathBuffer
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| RootPath | LPCWSTR | in |
| InputPathName | LPCWSTR | in |
| OutputPathBuffer | LPWSTR | out |
戻り値の型: BOOL
各言語での呼び出し定義
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SearchTreeForFileW(
LPCWSTR RootPath,
LPCWSTR InputPathName,
LPWSTR OutputPathBuffer
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SearchTreeForFileW(
[MarshalAs(UnmanagedType.LPWStr)] string RootPath, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string InputPathName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder OutputPathBuffer // LPWSTR out
);<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SearchTreeForFileW(
<MarshalAs(UnmanagedType.LPWStr)> RootPath As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> InputPathName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> OutputPathBuffer As System.Text.StringBuilder ' LPWSTR out
) As Boolean
End Function' RootPath : LPCWSTR
' InputPathName : LPCWSTR
' OutputPathBuffer : LPWSTR out
Declare PtrSafe Function SearchTreeForFileW Lib "dbghelp" ( _
ByVal RootPath As LongPtr, _
ByVal InputPathName As LongPtr, _
ByVal OutputPathBuffer As LongPtr) As Long
' 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
SearchTreeForFileW = ctypes.windll.dbghelp.SearchTreeForFileW
SearchTreeForFileW.restype = wintypes.BOOL
SearchTreeForFileW.argtypes = [
wintypes.LPCWSTR, # RootPath : LPCWSTR
wintypes.LPCWSTR, # InputPathName : LPCWSTR
wintypes.LPWSTR, # OutputPathBuffer : LPWSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
SearchTreeForFileW = Fiddle::Function.new(
lib['SearchTreeForFileW'],
[
Fiddle::TYPE_VOIDP, # RootPath : LPCWSTR
Fiddle::TYPE_VOIDP, # InputPathName : LPCWSTR
Fiddle::TYPE_VOIDP, # OutputPathBuffer : LPWSTR out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dbghelp")]
extern "system" {
fn SearchTreeForFileW(
RootPath: *const u16, // LPCWSTR
InputPathName: *const u16, // LPCWSTR
OutputPathBuffer: *mut u16 // LPWSTR out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SearchTreeForFileW([MarshalAs(UnmanagedType.LPWStr)] string RootPath, [MarshalAs(UnmanagedType.LPWStr)] string InputPathName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder OutputPathBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SearchTreeForFileW' -Namespace Win32 -PassThru
# $api::SearchTreeForFileW(RootPath, InputPathName, OutputPathBuffer)#uselib "dbghelp.dll"
#func global SearchTreeForFileW "SearchTreeForFileW" wptr, wptr, wptr
; SearchTreeForFileW RootPath, InputPathName, varptr(OutputPathBuffer) ; 戻り値は stat
; RootPath : LPCWSTR -> "wptr"
; InputPathName : LPCWSTR -> "wptr"
; OutputPathBuffer : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global SearchTreeForFileW "SearchTreeForFileW" wstr, wstr, var ; res = SearchTreeForFileW(RootPath, InputPathName, OutputPathBuffer) ; RootPath : LPCWSTR -> "wstr" ; InputPathName : LPCWSTR -> "wstr" ; OutputPathBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global SearchTreeForFileW "SearchTreeForFileW" wstr, wstr, sptr ; res = SearchTreeForFileW(RootPath, InputPathName, varptr(OutputPathBuffer)) ; RootPath : LPCWSTR -> "wstr" ; InputPathName : LPCWSTR -> "wstr" ; OutputPathBuffer : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SearchTreeForFileW(LPCWSTR RootPath, LPCWSTR InputPathName, LPWSTR OutputPathBuffer) #uselib "dbghelp.dll" #cfunc global SearchTreeForFileW "SearchTreeForFileW" wstr, wstr, var ; res = SearchTreeForFileW(RootPath, InputPathName, OutputPathBuffer) ; RootPath : LPCWSTR -> "wstr" ; InputPathName : LPCWSTR -> "wstr" ; OutputPathBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SearchTreeForFileW(LPCWSTR RootPath, LPCWSTR InputPathName, LPWSTR OutputPathBuffer) #uselib "dbghelp.dll" #cfunc global SearchTreeForFileW "SearchTreeForFileW" wstr, wstr, intptr ; res = SearchTreeForFileW(RootPath, InputPathName, varptr(OutputPathBuffer)) ; RootPath : LPCWSTR -> "wstr" ; InputPathName : LPCWSTR -> "wstr" ; OutputPathBuffer : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procSearchTreeForFileW = dbghelp.NewProc("SearchTreeForFileW")
)
// RootPath (LPCWSTR), InputPathName (LPCWSTR), OutputPathBuffer (LPWSTR out)
r1, _, err := procSearchTreeForFileW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(RootPath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InputPathName))),
uintptr(OutputPathBuffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SearchTreeForFileW(
RootPath: PWideChar; // LPCWSTR
InputPathName: PWideChar; // LPCWSTR
OutputPathBuffer: PWideChar // LPWSTR out
): BOOL; stdcall;
external 'dbghelp.dll' name 'SearchTreeForFileW';result := DllCall("dbghelp\SearchTreeForFileW"
, "WStr", RootPath ; LPCWSTR
, "WStr", InputPathName ; LPCWSTR
, "Ptr", OutputPathBuffer ; LPWSTR out
, "Int") ; return: BOOL●SearchTreeForFileW(RootPath, InputPathName, OutputPathBuffer) = DLL("dbghelp.dll", "bool SearchTreeForFileW(char*, char*, char*)")
# 呼び出し: SearchTreeForFileW(RootPath, InputPathName, OutputPathBuffer)
# RootPath : LPCWSTR -> "char*"
# InputPathName : LPCWSTR -> "char*"
# OutputPathBuffer : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。