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

PdhExpandCounterPathW

関数
ワイルドカードを含むパスを完全なパス一覧に展開する。
DLLpdh.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD PdhExpandCounterPathW(
    LPCWSTR szWildCardPath,
    LPWSTR mszExpandedPathList,   // optional
    DWORD* pcchPathListLength
);

パラメーター

名前方向
szWildCardPathLPCWSTRin
mszExpandedPathListLPWSTRoutoptional
pcchPathListLengthDWORD*inout

戻り値の型: DWORD

各言語での呼び出し定義

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

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

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

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

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhExpandCounterPathW = pdh.NewProc("PdhExpandCounterPathW")
)

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