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

EnumDirTreeW

関数
ディレクトリツリーを列挙し一致ファイルをコールバックへ通知する。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL EnumDirTreeW(
    HANDLE hProcess,   // optional
    LPCWSTR RootPath,
    LPCWSTR InputPathName,
    LPWSTR OutputPathBuffer,   // optional
    PENUMDIRTREE_CALLBACKW cb,   // optional
    void* data   // optional
);

パラメーター

名前方向説明
hProcessHANDLEinoptionalプロセスのハンドル。このハンドルは、事前に SymInitialize 関数に渡されている必要があります。
RootPathLPCWSTRin関数がファイルの検索を開始するパス。
InputPathNameLPCWSTRin検索対象のファイル名。部分的なパスを指定することもできます。
OutputPathBufferLPWSTRoutoptional

ファイルの完全なパスを受け取るバッファーへのポインター。関数が失敗した場合、または一致するファイルが見つからなかった場合でも、このバッファーには最後に見つかった完全なパスが格納されます。

このパラメーターは省略可能であり、NULL を指定できます。

cbPENUMDIRTREE_CALLBACKWinoptionalアプリケーション定義のコールバック関数、または NULL。詳細については、 EnumDirTreeProc を参照してください。
datavoid*inoptionalユーザー定義のデータ、または NULL。この値はコールバック関数に渡されます。

戻り値の型: BOOL

公式ドキュメント

EnumDirTreeW (Unicode) 関数は、指定したディレクトリツリー内で指定したファイルが出現する箇所をすべて列挙します。

戻り値

関数が成功した場合、戻り値は TRUE です。

関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出してください。

解説(Remarks)

SymRegisterCallbackProc64 コールバック関数を登録すると、検索をキャンセルできます。ファイル操作のたびに、 EnumDirTree はこのコールバック関数を CBA_DEFERRED_SYMBOL_LOAD_CANCEL を指定して呼び出します。コールバック関数が TRUE を返すと、 EnumDirTree は検索をキャンセルします。

この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性が高くなります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。

この関数の Unicode バージョンを呼び出すには、DBGHELP_TRANSLATE_TCHAR を定義してください。

メモ

dbghelp.h ヘッダーは、EnumDirTree を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在させて使用すると、不一致が発生し、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL EnumDirTreeW(
    HANDLE hProcess,   // optional
    LPCWSTR RootPath,
    LPCWSTR InputPathName,
    LPWSTR OutputPathBuffer,   // optional
    PENUMDIRTREE_CALLBACKW cb,   // optional
    void* data   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool EnumDirTreeW(
    IntPtr hProcess,   // HANDLE optional
    [MarshalAs(UnmanagedType.LPWStr)] string RootPath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string InputPathName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder OutputPathBuffer,   // LPWSTR optional, out
    IntPtr cb,   // PENUMDIRTREE_CALLBACKW optional
    IntPtr data   // void* optional
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EnumDirTreeW(
    hProcess As IntPtr,   ' HANDLE optional
    <MarshalAs(UnmanagedType.LPWStr)> RootPath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> InputPathName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> OutputPathBuffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    cb As IntPtr,   ' PENUMDIRTREE_CALLBACKW optional
    data As IntPtr   ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hProcess : HANDLE optional
' RootPath : LPCWSTR
' InputPathName : LPCWSTR
' OutputPathBuffer : LPWSTR optional, out
' cb : PENUMDIRTREE_CALLBACKW optional
' data : void* optional
Declare PtrSafe Function EnumDirTreeW Lib "dbghelp" ( _
    ByVal hProcess As LongPtr, _
    ByVal RootPath As LongPtr, _
    ByVal InputPathName As LongPtr, _
    ByVal OutputPathBuffer As LongPtr, _
    ByVal cb As LongPtr, _
    ByVal data 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

EnumDirTreeW = ctypes.windll.dbghelp.EnumDirTreeW
EnumDirTreeW.restype = wintypes.BOOL
EnumDirTreeW.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE optional
    wintypes.LPCWSTR,  # RootPath : LPCWSTR
    wintypes.LPCWSTR,  # InputPathName : LPCWSTR
    wintypes.LPWSTR,  # OutputPathBuffer : LPWSTR optional, out
    ctypes.c_void_p,  # cb : PENUMDIRTREE_CALLBACKW optional
    ctypes.POINTER(None),  # data : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
EnumDirTreeW = Fiddle::Function.new(
  lib['EnumDirTreeW'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE optional
    Fiddle::TYPE_VOIDP,  # RootPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # InputPathName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # OutputPathBuffer : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # cb : PENUMDIRTREE_CALLBACKW optional
    Fiddle::TYPE_VOIDP,  # data : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "dbghelp")]
extern "system" {
    fn EnumDirTreeW(
        hProcess: *mut core::ffi::c_void,  // HANDLE optional
        RootPath: *const u16,  // LPCWSTR
        InputPathName: *const u16,  // LPCWSTR
        OutputPathBuffer: *mut u16,  // LPWSTR optional, out
        cb: *const core::ffi::c_void,  // PENUMDIRTREE_CALLBACKW optional
        data: *mut ()  // void* optional
    ) -> 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 EnumDirTreeW(IntPtr hProcess, [MarshalAs(UnmanagedType.LPWStr)] string RootPath, [MarshalAs(UnmanagedType.LPWStr)] string InputPathName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder OutputPathBuffer, IntPtr cb, IntPtr data);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_EnumDirTreeW' -Namespace Win32 -PassThru
# $api::EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
#uselib "dbghelp.dll"
#func global EnumDirTreeW "EnumDirTreeW" wptr, wptr, wptr, wptr, wptr, wptr
; EnumDirTreeW hProcess, RootPath, InputPathName, varptr(OutputPathBuffer), cb, data   ; 戻り値は stat
; hProcess : HANDLE optional -> "wptr"
; RootPath : LPCWSTR -> "wptr"
; InputPathName : LPCWSTR -> "wptr"
; OutputPathBuffer : LPWSTR optional, out -> "wptr"
; cb : PENUMDIRTREE_CALLBACKW optional -> "wptr"
; data : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dbghelp.dll"
#cfunc global EnumDirTreeW "EnumDirTreeW" sptr, wstr, wstr, var, sptr, sptr
; res = EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
; hProcess : HANDLE optional -> "sptr"
; RootPath : LPCWSTR -> "wstr"
; InputPathName : LPCWSTR -> "wstr"
; OutputPathBuffer : LPWSTR optional, out -> "var"
; cb : PENUMDIRTREE_CALLBACKW optional -> "sptr"
; data : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL EnumDirTreeW(HANDLE hProcess, LPCWSTR RootPath, LPCWSTR InputPathName, LPWSTR OutputPathBuffer, PENUMDIRTREE_CALLBACKW cb, void* data)
#uselib "dbghelp.dll"
#cfunc global EnumDirTreeW "EnumDirTreeW" intptr, wstr, wstr, var, intptr, intptr
; res = EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
; hProcess : HANDLE optional -> "intptr"
; RootPath : LPCWSTR -> "wstr"
; InputPathName : LPCWSTR -> "wstr"
; OutputPathBuffer : LPWSTR optional, out -> "var"
; cb : PENUMDIRTREE_CALLBACKW optional -> "intptr"
; data : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procEnumDirTreeW = dbghelp.NewProc("EnumDirTreeW")
)

// hProcess (HANDLE optional), RootPath (LPCWSTR), InputPathName (LPCWSTR), OutputPathBuffer (LPWSTR optional, out), cb (PENUMDIRTREE_CALLBACKW optional), data (void* optional)
r1, _, err := procEnumDirTreeW.Call(
	uintptr(hProcess),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(RootPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InputPathName))),
	uintptr(OutputPathBuffer),
	uintptr(cb),
	uintptr(data),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function EnumDirTreeW(
  hProcess: THandle;   // HANDLE optional
  RootPath: PWideChar;   // LPCWSTR
  InputPathName: PWideChar;   // LPCWSTR
  OutputPathBuffer: PWideChar;   // LPWSTR optional, out
  cb: Pointer;   // PENUMDIRTREE_CALLBACKW optional
  data: Pointer   // void* optional
): BOOL; stdcall;
  external 'dbghelp.dll' name 'EnumDirTreeW';
result := DllCall("dbghelp\EnumDirTreeW"
    , "Ptr", hProcess   ; HANDLE optional
    , "WStr", RootPath   ; LPCWSTR
    , "WStr", InputPathName   ; LPCWSTR
    , "Ptr", OutputPathBuffer   ; LPWSTR optional, out
    , "Ptr", cb   ; PENUMDIRTREE_CALLBACKW optional
    , "Ptr", data   ; void* optional
    , "Int")   ; return: BOOL
●EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data) = DLL("dbghelp.dll", "bool EnumDirTreeW(void*, char*, char*, char*, void*, void*)")
# 呼び出し: EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
# hProcess : HANDLE optional -> "void*"
# RootPath : LPCWSTR -> "char*"
# InputPathName : LPCWSTR -> "char*"
# OutputPathBuffer : LPWSTR optional, out -> "char*"
# cb : PENUMDIRTREE_CALLBACKW optional -> "void*"
# data : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "dbghelp" fn EnumDirTreeW(
    hProcess: ?*anyopaque, // HANDLE optional
    RootPath: [*c]const u16, // LPCWSTR
    InputPathName: [*c]const u16, // LPCWSTR
    OutputPathBuffer: [*c]u16, // LPWSTR optional, out
    cb: ?*anyopaque, // PENUMDIRTREE_CALLBACKW optional
    data: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc EnumDirTreeW(
    hProcess: pointer,  # HANDLE optional
    RootPath: WideCString,  # LPCWSTR
    InputPathName: WideCString,  # LPCWSTR
    OutputPathBuffer: ptr uint16,  # LPWSTR optional, out
    cb: pointer,  # PENUMDIRTREE_CALLBACKW optional
    data: pointer  # void* optional
): int32 {.importc: "EnumDirTreeW", stdcall, dynlib: "dbghelp.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "dbghelp");
extern(Windows)
int EnumDirTreeW(
    void* hProcess,   // HANDLE optional
    const(wchar)* RootPath,   // LPCWSTR
    const(wchar)* InputPathName,   // LPCWSTR
    wchar* OutputPathBuffer,   // LPWSTR optional, out
    void* cb,   // PENUMDIRTREE_CALLBACKW optional
    void* data   // void* optional
);
ccall((:EnumDirTreeW, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Cwstring, Ptr{UInt16}, Ptr{Cvoid}, Ptr{Cvoid}),
      hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
# hProcess : HANDLE optional -> Ptr{Cvoid}
# RootPath : LPCWSTR -> Cwstring
# InputPathName : LPCWSTR -> Cwstring
# OutputPathBuffer : LPWSTR optional, out -> Ptr{UInt16}
# cb : PENUMDIRTREE_CALLBACKW optional -> Ptr{Cvoid}
# data : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t EnumDirTreeW(
    void* hProcess,
    const uint16_t* RootPath,
    const uint16_t* InputPathName,
    uint16_t* OutputPathBuffer,
    void* cb,
    void* data);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
-- hProcess : HANDLE optional
-- RootPath : LPCWSTR
-- InputPathName : LPCWSTR
-- OutputPathBuffer : LPWSTR optional, out
-- cb : PENUMDIRTREE_CALLBACKW optional
-- data : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const EnumDirTreeW = lib.func('__stdcall', 'EnumDirTreeW', 'int32_t', ['void *', 'str16', 'str16', 'uint16_t *', 'void *', 'void *']);
// EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
// hProcess : HANDLE optional -> 'void *'
// RootPath : LPCWSTR -> 'str16'
// InputPathName : LPCWSTR -> 'str16'
// OutputPathBuffer : LPWSTR optional, out -> 'uint16_t *'
// cb : PENUMDIRTREE_CALLBACKW optional -> 'void *'
// data : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("dbghelp.dll", {
  EnumDirTreeW: { parameters: ["pointer", "buffer", "buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data)
// hProcess : HANDLE optional -> "pointer"
// RootPath : LPCWSTR -> "buffer"
// InputPathName : LPCWSTR -> "buffer"
// OutputPathBuffer : LPWSTR optional, out -> "buffer"
// cb : PENUMDIRTREE_CALLBACKW optional -> "pointer"
// data : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t EnumDirTreeW(
    void* hProcess,
    const uint16_t* RootPath,
    const uint16_t* InputPathName,
    uint16_t* OutputPathBuffer,
    void* cb,
    void* data);
C, "dbghelp.dll");
// $ffi->EnumDirTreeW(hProcess, RootPath, InputPathName, OutputPathBuffer, cb, data);
// hProcess : HANDLE optional
// RootPath : LPCWSTR
// InputPathName : LPCWSTR
// OutputPathBuffer : LPWSTR optional, out
// cb : PENUMDIRTREE_CALLBACKW optional
// data : void* optional
// 構造体/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, W32APIOptions.UNICODE_OPTIONS);
    boolean EnumDirTreeW(
        Pointer hProcess,   // HANDLE optional
        WString RootPath,   // LPCWSTR
        WString InputPathName,   // LPCWSTR
        char[] OutputPathBuffer,   // LPWSTR optional, out
        Callback cb,   // PENUMDIRTREE_CALLBACKW optional
        Pointer data   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("dbghelp")]
lib Libdbghelp
  fun EnumDirTreeW = EnumDirTreeW(
    hProcess : Void*,   # HANDLE optional
    RootPath : UInt16*,   # LPCWSTR
    InputPathName : UInt16*,   # LPCWSTR
    OutputPathBuffer : UInt16*,   # LPWSTR optional, out
    cb : Void*,   # PENUMDIRTREE_CALLBACKW optional
    data : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef EnumDirTreeWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef EnumDirTreeWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final EnumDirTreeW = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<EnumDirTreeWNative, EnumDirTreeWDart>('EnumDirTreeW');
// hProcess : HANDLE optional -> Pointer<Void>
// RootPath : LPCWSTR -> Pointer<Utf16>
// InputPathName : LPCWSTR -> Pointer<Utf16>
// OutputPathBuffer : LPWSTR optional, out -> Pointer<Utf16>
// cb : PENUMDIRTREE_CALLBACKW optional -> Pointer<Void>
// data : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function EnumDirTreeW(
  hProcess: THandle;   // HANDLE optional
  RootPath: PWideChar;   // LPCWSTR
  InputPathName: PWideChar;   // LPCWSTR
  OutputPathBuffer: PWideChar;   // LPWSTR optional, out
  cb: Pointer;   // PENUMDIRTREE_CALLBACKW optional
  data: Pointer   // void* optional
): BOOL; stdcall;
  external 'dbghelp.dll' name 'EnumDirTreeW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "EnumDirTreeW"
  c_EnumDirTreeW :: Ptr () -> CWString -> CWString -> CWString -> Ptr () -> Ptr () -> IO CInt
-- hProcess : HANDLE optional -> Ptr ()
-- RootPath : LPCWSTR -> CWString
-- InputPathName : LPCWSTR -> CWString
-- OutputPathBuffer : LPWSTR optional, out -> CWString
-- cb : PENUMDIRTREE_CALLBACKW optional -> Ptr ()
-- data : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let enumdirtreew =
  foreign "EnumDirTreeW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hProcess : HANDLE optional -> (ptr void) *)
(* RootPath : LPCWSTR -> (ptr uint16_t) *)
(* InputPathName : LPCWSTR -> (ptr uint16_t) *)
(* OutputPathBuffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* cb : PENUMDIRTREE_CALLBACKW optional -> (ptr void) *)
(* data : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("EnumDirTreeW" enum-dir-tree-w :convention :stdcall) :int32
  (h-process :pointer)   ; HANDLE optional
  (root-path (:string :encoding :utf-16le))   ; LPCWSTR
  (input-path-name (:string :encoding :utf-16le))   ; LPCWSTR
  (output-path-buffer :pointer)   ; LPWSTR optional, out
  (cb :pointer)   ; PENUMDIRTREE_CALLBACKW optional
  (data :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $EnumDirTreeW = Win32::API::More->new('dbghelp',
    'BOOL EnumDirTreeW(HANDLE hProcess, LPCWSTR RootPath, LPCWSTR InputPathName, LPWSTR OutputPathBuffer, LPVOID cb, LPVOID data)');
# my $ret = $EnumDirTreeW->Call($hProcess, $RootPath, $InputPathName, $OutputPathBuffer, $cb, $data);
# hProcess : HANDLE optional -> HANDLE
# RootPath : LPCWSTR -> LPCWSTR
# InputPathName : LPCWSTR -> LPCWSTR
# OutputPathBuffer : LPWSTR optional, out -> LPWSTR
# cb : PENUMDIRTREE_CALLBACKW optional -> LPVOID
# data : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

使用する型