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

SearchTreeForFileW

関数
ディレクトリツリーを再帰的に検索して指定ファイルを探す。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

// dbghelp.dll  (Unicode / -W)
#include <windows.h>

BOOL SearchTreeForFileW(
    LPCWSTR RootPath,
    LPCWSTR InputPathName,
    LPWSTR OutputPathBuffer
);

パラメーター

名前方向
RootPathLPCWSTRin
InputPathNameLPCWSTRin
OutputPathBufferLPWSTRout

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
function 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 版の利用を推奨。