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

SearchTreeForFile

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

シグネチャ

// dbghelp.dll  (ANSI / -A)
#include <windows.h>

BOOL SearchTreeForFile(
    LPCSTR RootPath,
    LPCSTR InputPathName,
    LPSTR OutputPathBuffer
);

パラメーター

名前方向
RootPathLPCSTRin
InputPathNameLPCSTRin
OutputPathBufferLPSTRout

戻り値の型: BOOL

各言語での呼び出し定義

// dbghelp.dll  (ANSI / -A)
#include <windows.h>

BOOL SearchTreeForFile(
    LPCSTR RootPath,
    LPCSTR InputPathName,
    LPSTR OutputPathBuffer
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SearchTreeForFile(
    [MarshalAs(UnmanagedType.LPStr)] string RootPath,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string InputPathName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder OutputPathBuffer   // LPSTR out
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SearchTreeForFile(
    <MarshalAs(UnmanagedType.LPStr)> RootPath As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> InputPathName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> OutputPathBuffer As System.Text.StringBuilder   ' LPSTR out
) As Boolean
End Function
' RootPath : LPCSTR
' InputPathName : LPCSTR
' OutputPathBuffer : LPSTR out
Declare PtrSafe Function SearchTreeForFile Lib "dbghelp" ( _
    ByVal RootPath As String, _
    ByVal InputPathName As String, _
    ByVal OutputPathBuffer As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SearchTreeForFile = ctypes.windll.dbghelp.SearchTreeForFile
SearchTreeForFile.restype = wintypes.BOOL
SearchTreeForFile.argtypes = [
    wintypes.LPCSTR,  # RootPath : LPCSTR
    wintypes.LPCSTR,  # InputPathName : LPCSTR
    wintypes.LPSTR,  # OutputPathBuffer : LPSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SearchTreeForFile = Fiddle::Function.new(
  lib['SearchTreeForFile'],
  [
    Fiddle::TYPE_VOIDP,  # RootPath : LPCSTR
    Fiddle::TYPE_VOIDP,  # InputPathName : LPCSTR
    Fiddle::TYPE_VOIDP,  # OutputPathBuffer : LPSTR out
  ],
  Fiddle::TYPE_INT)
#[link(name = "dbghelp")]
extern "system" {
    fn SearchTreeForFile(
        RootPath: *const u8,  // LPCSTR
        InputPathName: *const u8,  // LPCSTR
        OutputPathBuffer: *mut u8  // LPSTR out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SearchTreeForFile([MarshalAs(UnmanagedType.LPStr)] string RootPath, [MarshalAs(UnmanagedType.LPStr)] string InputPathName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder OutputPathBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SearchTreeForFile' -Namespace Win32 -PassThru
# $api::SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer)
#uselib "dbghelp.dll"
#func global SearchTreeForFile "SearchTreeForFile" sptr, sptr, sptr
; SearchTreeForFile RootPath, InputPathName, varptr(OutputPathBuffer)   ; 戻り値は stat
; RootPath : LPCSTR -> "sptr"
; InputPathName : LPCSTR -> "sptr"
; OutputPathBuffer : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dbghelp.dll"
#cfunc global SearchTreeForFile "SearchTreeForFile" str, str, var
; res = SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer)
; RootPath : LPCSTR -> "str"
; InputPathName : LPCSTR -> "str"
; OutputPathBuffer : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SearchTreeForFile(LPCSTR RootPath, LPCSTR InputPathName, LPSTR OutputPathBuffer)
#uselib "dbghelp.dll"
#cfunc global SearchTreeForFile "SearchTreeForFile" str, str, var
; res = SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer)
; RootPath : LPCSTR -> "str"
; InputPathName : LPCSTR -> "str"
; OutputPathBuffer : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSearchTreeForFile = dbghelp.NewProc("SearchTreeForFile")
)

// RootPath (LPCSTR), InputPathName (LPCSTR), OutputPathBuffer (LPSTR out)
r1, _, err := procSearchTreeForFile.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(RootPath))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(InputPathName))),
	uintptr(OutputPathBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SearchTreeForFile(
  RootPath: PAnsiChar;   // LPCSTR
  InputPathName: PAnsiChar;   // LPCSTR
  OutputPathBuffer: PAnsiChar   // LPSTR out
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SearchTreeForFile';
result := DllCall("dbghelp\SearchTreeForFile"
    , "AStr", RootPath   ; LPCSTR
    , "AStr", InputPathName   ; LPCSTR
    , "Ptr", OutputPathBuffer   ; LPSTR out
    , "Int")   ; return: BOOL
●SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer) = DLL("dbghelp.dll", "bool SearchTreeForFile(char*, char*, char*)")
# 呼び出し: SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer)
# RootPath : LPCSTR -> "char*"
# InputPathName : LPCSTR -> "char*"
# OutputPathBuffer : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。