Win32 API 日本語リファレンス
ホームSystem.Performance › PdhExpandWildCardPathW

PdhExpandWildCardPathW

関数
データソース指定でワイルドカードパスを完全パスに展開する。
DLLpdh.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD PdhExpandWildCardPathW(
    LPCWSTR szDataSource,   // optional
    LPCWSTR szWildCardPath,
    LPWSTR mszExpandedPathList,   // optional
    DWORD* pcchPathListLength,
    DWORD dwFlags
);

パラメーター

名前方向説明
szDataSourceLPCWSTRinoptional

ログファイルの名前を格納したnull終端文字列です。この関数は、ログファイル内で定義されているパフォーマンスオブジェクトおよびカウンターを使用して、szWildCardPath パラメーターで指定されたパスを展開します。

NULL の場合、この関数は szWildCardPath で指定されたコンピューターを検索します。

szWildCardPathLPCWSTRin

展開するカウンターパスを指定するnull終端文字列です。カウンターパスの最大長は PDH_MAX_COUNTER_PATH です。

szDataSource パラメーターが NULL の場合、この関数はパスで指定されたコンピューターを検索して一致を探します。パスにコンピューターが指定されていない場合は、ローカルコンピューターを検索します。

mszExpandedPathListLPWSTRoutoptionalszWildCardPath のワイルドカード指定に一致するnull終端カウンターパスのリストを受け取る、呼び出し側が割り当てたバッファーです。リストは 2 つの NULL 文字で終端されます。pcchPathListLength が 0 の場合は NULL を設定してください。
pcchPathListLengthDWORD*inout

mszExpandedPathList バッファーのサイズ(TCHAR 単位)です。入力時に 0 でオブジェクトが存在する場合、この関数は PDH_MORE_DATA を返し、このパラメーターに必要なバッファーサイズを設定します。バッファーが必要なサイズより大きい場合、この関数はこのパラメーターに実際に使用されたバッファーのサイズを設定します。入力時に指定したサイズが 0 より大きく必要なサイズより小さい場合、返されたサイズに基づいてバッファーを再割り当てしないでください。

Windows XP では、必要なサイズに 1 を加算する必要があります。
dwFlagsDWORDin

展開しないワイルドカード文字を示すフラグです。1 つ以上のフラグを指定できます。

意味
PDH_NOEXPANDCOUNTERS
パスにカウンター名のワイルドカード文字が含まれている場合でも、カウンター名を展開しません。
PDH_NOEXPANDINSTANCES
パスに親インスタンス、インスタンス名、またはインスタンスインデックスのワイルドカード文字が含まれている場合でも、インスタンス名を展開しません。
PDH_REFRESHCOUNTERS
カウンターリストを更新します。

戻り値の型: DWORD

公式ドキュメント

指定されたコンピューターまたはログファイルを調べ、ワイルドカード文字を含む指定されたカウンターパスに一致するカウンターパスを返します。データソースへのハンドルを使用するには、PdhExpandWildCardPathH 関数を使用してください。(Unicode)

戻り値

関数が成功した場合は ERROR_SUCCESS を返します。

関数が失敗した場合、戻り値は システムエラーコードまたは PDH エラーコードです。

戻り値 説明
PDH_MORE_DATA
mszExpandedPathList バッファーがパスのリストを格納するのに十分な大きさではありません。pcchPathListLength が入力時に 0 の場合、この戻り値が想定されます。入力時に指定したサイズが 0 より大きく必要なサイズより小さい場合、返されたサイズに基づいてバッファーを再割り当てしないでください。
PDH_INVALID_ARGUMENT
パラメーターが無効です。たとえば、一部のリリースでは、入力時に指定したサイズが 0 より大きく必要なサイズより小さい場合にこのエラーを受け取ることがあります。
PDH_INVALID_PATH
指定されたオブジェクトにインスタンスが含まれていません。
PDH_MEMORY_ALLOCATION_FAILURE
この関数をサポートするためのメモリを割り当てることができません。
PDH_CSTATUS_NO_OBJECT
コンピューターまたはログファイル内で指定されたオブジェクトが見つかりません。

解説(Remarks)

この関数は 2 回呼び出す必要があります。1 回目は必要なバッファーサイズを取得するため(mszExpandedPathListNULL に、pcchPathListLength を 0 に設定)、2 回目はデータを取得するためです。

PdhExpandWildCardPathPdhExpandCounterPath と次の点で異なります。

  1. どのワイルドカード文字を展開するかを制御できます。
  2. ログファイルの内容をカウンター名のソースとして使用できます。
一般的なカウンターパスの形式は次のとおりです。

\computer\object(parent/instance#index)\counter

カウンターパスの parent、instance、index、および counter コンポーネントには、有効な名前またはワイルドカード文字のいずれかを含めることができます。computer、parent、instance、および index コンポーネントは、すべてのカウンターに必要なわけではありません。

可能な形式のリストは次のとおりです。

ワイルドカード文字としてアスタリスク (*) を使用します。たとえば、\object(*)\counter のようにします。

親名にワイルドカード文字が指定されている場合、指定された instance フィールドおよび counter フィールドに一致する、指定オブジェクトのすべてのインスタンスが返されます。たとえば、\object(*/instance)\counter のようにします。

インスタンス名にワイルドカード文字が指定されている場合、指定されたインデックスに対応するすべてのインスタンス名がワイルドカード文字に一致すれば、指定オブジェクトおよび親オブジェクトのすべてのインスタンスが返されます。たとえば、\object(parent/*)\counter のようにします。オブジェクトにインスタンスが含まれていない場合は、エラーが発生します。

カウンター名にワイルドカード文字が指定されている場合、指定オブジェクトのすべてのカウンターが返されます。

カウンターパス文字列の部分一致(たとえば "pro*")がサポートされています。

Windows Vista より前: 部分的なワイルドカード一致はサポートされていません。

メモ

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

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

各言語での呼び出し定義

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

DWORD PdhExpandWildCardPathW(
    LPCWSTR szDataSource,   // optional
    LPCWSTR szWildCardPath,
    LPWSTR mszExpandedPathList,   // optional
    DWORD* pcchPathListLength,
    DWORD dwFlags
);
[DllImport("pdh.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint PdhExpandWildCardPathW(
    [MarshalAs(UnmanagedType.LPWStr)] string szDataSource,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string szWildCardPath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder mszExpandedPathList,   // LPWSTR optional, out
    ref uint pcchPathListLength,   // DWORD* in/out
    uint dwFlags   // DWORD
);
<DllImport("pdh.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PdhExpandWildCardPathW(
    <MarshalAs(UnmanagedType.LPWStr)> szDataSource As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> szWildCardPath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> mszExpandedPathList As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef pcchPathListLength As UInteger,   ' DWORD* in/out
    dwFlags As UInteger   ' DWORD
) As UInteger
End Function
' szDataSource : LPCWSTR optional
' szWildCardPath : LPCWSTR
' mszExpandedPathList : LPWSTR optional, out
' pcchPathListLength : DWORD* in/out
' dwFlags : DWORD
Declare PtrSafe Function PdhExpandWildCardPathW Lib "pdh" ( _
    ByVal szDataSource As LongPtr, _
    ByVal szWildCardPath As LongPtr, _
    ByVal mszExpandedPathList As LongPtr, _
    ByRef pcchPathListLength As Long, _
    ByVal dwFlags As Long) 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

PdhExpandWildCardPathW = ctypes.windll.pdh.PdhExpandWildCardPathW
PdhExpandWildCardPathW.restype = wintypes.DWORD
PdhExpandWildCardPathW.argtypes = [
    wintypes.LPCWSTR,  # szDataSource : LPCWSTR optional
    wintypes.LPCWSTR,  # szWildCardPath : LPCWSTR
    wintypes.LPWSTR,  # mszExpandedPathList : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchPathListLength : DWORD* in/out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('pdh.dll')
PdhExpandWildCardPathW = Fiddle::Function.new(
  lib['PdhExpandWildCardPathW'],
  [
    Fiddle::TYPE_VOIDP,  # szDataSource : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # szWildCardPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # mszExpandedPathList : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchPathListLength : DWORD* in/out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "pdh")]
extern "system" {
    fn PdhExpandWildCardPathW(
        szDataSource: *const u16,  // LPCWSTR optional
        szWildCardPath: *const u16,  // LPCWSTR
        mszExpandedPathList: *mut u16,  // LPWSTR optional, out
        pcchPathListLength: *mut u32,  // DWORD* in/out
        dwFlags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("pdh.dll", CharSet = CharSet.Unicode)]
public static extern uint PdhExpandWildCardPathW([MarshalAs(UnmanagedType.LPWStr)] string szDataSource, [MarshalAs(UnmanagedType.LPWStr)] string szWildCardPath, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder mszExpandedPathList, ref uint pcchPathListLength, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhExpandWildCardPathW' -Namespace Win32 -PassThru
# $api::PdhExpandWildCardPathW(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags)
#uselib "pdh.dll"
#func global PdhExpandWildCardPathW "PdhExpandWildCardPathW" wptr, wptr, wptr, wptr, wptr
; PdhExpandWildCardPathW szDataSource, szWildCardPath, varptr(mszExpandedPathList), varptr(pcchPathListLength), dwFlags   ; 戻り値は stat
; szDataSource : LPCWSTR optional -> "wptr"
; szWildCardPath : LPCWSTR -> "wptr"
; mszExpandedPathList : LPWSTR optional, out -> "wptr"
; pcchPathListLength : DWORD* in/out -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "pdh.dll"
#cfunc global PdhExpandWildCardPathW "PdhExpandWildCardPathW" wstr, wstr, var, var, int
; res = PdhExpandWildCardPathW(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags)
; szDataSource : LPCWSTR optional -> "wstr"
; szWildCardPath : LPCWSTR -> "wstr"
; mszExpandedPathList : LPWSTR optional, out -> "var"
; pcchPathListLength : DWORD* in/out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD PdhExpandWildCardPathW(LPCWSTR szDataSource, LPCWSTR szWildCardPath, LPWSTR mszExpandedPathList, DWORD* pcchPathListLength, DWORD dwFlags)
#uselib "pdh.dll"
#cfunc global PdhExpandWildCardPathW "PdhExpandWildCardPathW" wstr, wstr, var, var, int
; res = PdhExpandWildCardPathW(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags)
; szDataSource : LPCWSTR optional -> "wstr"
; szWildCardPath : LPCWSTR -> "wstr"
; mszExpandedPathList : LPWSTR optional, out -> "var"
; pcchPathListLength : DWORD* in/out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhExpandWildCardPathW = pdh.NewProc("PdhExpandWildCardPathW")
)

// szDataSource (LPCWSTR optional), szWildCardPath (LPCWSTR), mszExpandedPathList (LPWSTR optional, out), pcchPathListLength (DWORD* in/out), dwFlags (DWORD)
r1, _, err := procPdhExpandWildCardPathW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szDataSource))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szWildCardPath))),
	uintptr(mszExpandedPathList),
	uintptr(pcchPathListLength),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function PdhExpandWildCardPathW(
  szDataSource: PWideChar;   // LPCWSTR optional
  szWildCardPath: PWideChar;   // LPCWSTR
  mszExpandedPathList: PWideChar;   // LPWSTR optional, out
  pcchPathListLength: Pointer;   // DWORD* in/out
  dwFlags: DWORD   // DWORD
): DWORD; stdcall;
  external 'pdh.dll' name 'PdhExpandWildCardPathW';
result := DllCall("pdh\PdhExpandWildCardPathW"
    , "WStr", szDataSource   ; LPCWSTR optional
    , "WStr", szWildCardPath   ; LPCWSTR
    , "Ptr", mszExpandedPathList   ; LPWSTR optional, out
    , "Ptr", pcchPathListLength   ; DWORD* in/out
    , "UInt", dwFlags   ; DWORD
    , "UInt")   ; return: DWORD
●PdhExpandWildCardPathW(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags) = DLL("pdh.dll", "dword PdhExpandWildCardPathW(char*, char*, char*, void*, dword)")
# 呼び出し: PdhExpandWildCardPathW(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags)
# szDataSource : LPCWSTR optional -> "char*"
# szWildCardPath : LPCWSTR -> "char*"
# mszExpandedPathList : LPWSTR optional, out -> "char*"
# pcchPathListLength : DWORD* in/out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

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

typedef PdhExpandWildCardPathWNative = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Uint32);
typedef PdhExpandWildCardPathWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, int);
final PdhExpandWildCardPathW = DynamicLibrary.open('pdh.dll')
    .lookupFunction<PdhExpandWildCardPathWNative, PdhExpandWildCardPathWDart>('PdhExpandWildCardPathW');
// szDataSource : LPCWSTR optional -> Pointer<Utf16>
// szWildCardPath : LPCWSTR -> Pointer<Utf16>
// mszExpandedPathList : LPWSTR optional, out -> Pointer<Utf16>
// pcchPathListLength : DWORD* in/out -> Pointer<Uint32>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PdhExpandWildCardPathW(
  szDataSource: PWideChar;   // LPCWSTR optional
  szWildCardPath: PWideChar;   // LPCWSTR
  mszExpandedPathList: PWideChar;   // LPWSTR optional, out
  pcchPathListLength: Pointer;   // DWORD* in/out
  dwFlags: DWORD   // DWORD
): DWORD; stdcall;
  external 'pdh.dll' name 'PdhExpandWildCardPathW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PdhExpandWildCardPathW"
  c_PdhExpandWildCardPathW :: CWString -> CWString -> CWString -> Ptr Word32 -> Word32 -> IO Word32
-- szDataSource : LPCWSTR optional -> CWString
-- szWildCardPath : LPCWSTR -> CWString
-- mszExpandedPathList : LPWSTR optional, out -> CWString
-- pcchPathListLength : DWORD* in/out -> Ptr Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pdhexpandwildcardpathw =
  foreign "PdhExpandWildCardPathW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> uint32_t @-> returning uint32_t)
(* szDataSource : LPCWSTR optional -> (ptr uint16_t) *)
(* szWildCardPath : LPCWSTR -> (ptr uint16_t) *)
(* mszExpandedPathList : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchPathListLength : DWORD* in/out -> (ptr uint32_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library pdh (t "pdh.dll"))
(cffi:use-foreign-library pdh)

(cffi:defcfun ("PdhExpandWildCardPathW" pdh-expand-wild-card-path-w :convention :stdcall) :uint32
  (sz-data-source (:string :encoding :utf-16le))   ; LPCWSTR optional
  (sz-wild-card-path (:string :encoding :utf-16le))   ; LPCWSTR
  (msz-expanded-path-list :pointer)   ; LPWSTR optional, out
  (pcch-path-list-length :pointer)   ; DWORD* in/out
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PdhExpandWildCardPathW = Win32::API::More->new('pdh',
    'DWORD PdhExpandWildCardPathW(LPCWSTR szDataSource, LPCWSTR szWildCardPath, LPWSTR mszExpandedPathList, LPVOID pcchPathListLength, DWORD dwFlags)');
# my $ret = $PdhExpandWildCardPathW->Call($szDataSource, $szWildCardPath, $mszExpandedPathList, $pcchPathListLength, $dwFlags);
# szDataSource : LPCWSTR optional -> LPCWSTR
# szWildCardPath : LPCWSTR -> LPCWSTR
# mszExpandedPathList : LPWSTR optional, out -> LPWSTR
# pcchPathListLength : DWORD* in/out -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い