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

PdhEnumObjectsW

関数
マシン上のパフォーマンスオブジェクト一覧を列挙する。
DLLpdh.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD PdhEnumObjectsW(
    LPCWSTR szDataSource,   // optional
    LPCWSTR szMachineName,   // optional
    LPWSTR mszObjectList,   // optional
    DWORD* pcchBufferSize,
    PERF_DETAIL dwDetailLevel,
    BOOL bRefresh
);

パラメーター

名前方向
szDataSourceLPCWSTRinoptional
szMachineNameLPCWSTRinoptional
mszObjectListLPWSTRoutoptional
pcchBufferSizeDWORD*inout
dwDetailLevelPERF_DETAILin
bRefreshBOOLin

戻り値の型: DWORD

各言語での呼び出し定義

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

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

PdhEnumObjectsW = ctypes.windll.pdh.PdhEnumObjectsW
PdhEnumObjectsW.restype = wintypes.DWORD
PdhEnumObjectsW.argtypes = [
    wintypes.LPCWSTR,  # szDataSource : LPCWSTR optional
    wintypes.LPCWSTR,  # szMachineName : LPCWSTR optional
    wintypes.LPWSTR,  # mszObjectList : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchBufferSize : DWORD* in/out
    wintypes.DWORD,  # dwDetailLevel : PERF_DETAIL
    wintypes.BOOL,  # bRefresh : BOOL
]
require 'fiddle'
require 'fiddle/import'

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

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhEnumObjectsW = pdh.NewProc("PdhEnumObjectsW")
)

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