ホーム › System.Performance › PdhEnumObjectItemsA
PdhEnumObjectItemsA
関数オブジェクトのカウンターとインスタンスを列挙する(ANSI版)。
シグネチャ
// pdh.dll (ANSI / -A)
#include <windows.h>
DWORD PdhEnumObjectItemsA(
LPCSTR szDataSource, // optional
LPCSTR szMachineName, // optional
LPCSTR szObjectName,
LPSTR mszCounterList, // optional
DWORD* pcchCounterListLength,
LPSTR mszInstanceList, // optional
DWORD* pcchInstanceListLength,
PERF_DETAIL dwDetailLevel,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| szDataSource | LPCSTR | inoptional |
| szMachineName | LPCSTR | inoptional |
| szObjectName | LPCSTR | in |
| mszCounterList | LPSTR | outoptional |
| pcchCounterListLength | DWORD* | inout |
| mszInstanceList | LPSTR | outoptional |
| pcchInstanceListLength | DWORD* | inout |
| dwDetailLevel | PERF_DETAIL | in |
| dwFlags | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// pdh.dll (ANSI / -A)
#include <windows.h>
DWORD PdhEnumObjectItemsA(
LPCSTR szDataSource, // optional
LPCSTR szMachineName, // optional
LPCSTR szObjectName,
LPSTR mszCounterList, // optional
DWORD* pcchCounterListLength,
LPSTR mszInstanceList, // optional
DWORD* pcchInstanceListLength,
PERF_DETAIL dwDetailLevel,
DWORD dwFlags
);[DllImport("pdh.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint PdhEnumObjectItemsA(
[MarshalAs(UnmanagedType.LPStr)] string szDataSource, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string szMachineName, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string szObjectName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszCounterList, // LPSTR optional, out
ref uint pcchCounterListLength, // DWORD* in/out
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszInstanceList, // LPSTR optional, out
ref uint pcchInstanceListLength, // DWORD* in/out
uint dwDetailLevel, // PERF_DETAIL
uint dwFlags // DWORD
);<DllImport("pdh.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PdhEnumObjectItemsA(
<MarshalAs(UnmanagedType.LPStr)> szDataSource As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> szMachineName As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> szObjectName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> mszCounterList As System.Text.StringBuilder, ' LPSTR optional, out
ByRef pcchCounterListLength As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPStr)> mszInstanceList As System.Text.StringBuilder, ' LPSTR optional, out
ByRef pcchInstanceListLength As UInteger, ' DWORD* in/out
dwDetailLevel As UInteger, ' PERF_DETAIL
dwFlags As UInteger ' DWORD
) As UInteger
End Function' szDataSource : LPCSTR optional
' szMachineName : LPCSTR optional
' szObjectName : LPCSTR
' mszCounterList : LPSTR optional, out
' pcchCounterListLength : DWORD* in/out
' mszInstanceList : LPSTR optional, out
' pcchInstanceListLength : DWORD* in/out
' dwDetailLevel : PERF_DETAIL
' dwFlags : DWORD
Declare PtrSafe Function PdhEnumObjectItemsA Lib "pdh" ( _
ByVal szDataSource As String, _
ByVal szMachineName As String, _
ByVal szObjectName As String, _
ByVal mszCounterList As String, _
ByRef pcchCounterListLength As Long, _
ByVal mszInstanceList As String, _
ByRef pcchInstanceListLength As Long, _
ByVal dwDetailLevel As Long, _
ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PdhEnumObjectItemsA = ctypes.windll.pdh.PdhEnumObjectItemsA
PdhEnumObjectItemsA.restype = wintypes.DWORD
PdhEnumObjectItemsA.argtypes = [
wintypes.LPCSTR, # szDataSource : LPCSTR optional
wintypes.LPCSTR, # szMachineName : LPCSTR optional
wintypes.LPCSTR, # szObjectName : LPCSTR
wintypes.LPSTR, # mszCounterList : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchCounterListLength : DWORD* in/out
wintypes.LPSTR, # mszInstanceList : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # pcchInstanceListLength : DWORD* in/out
wintypes.DWORD, # dwDetailLevel : PERF_DETAIL
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('pdh.dll')
PdhEnumObjectItemsA = Fiddle::Function.new(
lib['PdhEnumObjectItemsA'],
[
Fiddle::TYPE_VOIDP, # szDataSource : LPCSTR optional
Fiddle::TYPE_VOIDP, # szMachineName : LPCSTR optional
Fiddle::TYPE_VOIDP, # szObjectName : LPCSTR
Fiddle::TYPE_VOIDP, # mszCounterList : LPSTR optional, out
Fiddle::TYPE_VOIDP, # pcchCounterListLength : DWORD* in/out
Fiddle::TYPE_VOIDP, # mszInstanceList : LPSTR optional, out
Fiddle::TYPE_VOIDP, # pcchInstanceListLength : DWORD* in/out
-Fiddle::TYPE_INT, # dwDetailLevel : PERF_DETAIL
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "pdh")]
extern "system" {
fn PdhEnumObjectItemsA(
szDataSource: *const u8, // LPCSTR optional
szMachineName: *const u8, // LPCSTR optional
szObjectName: *const u8, // LPCSTR
mszCounterList: *mut u8, // LPSTR optional, out
pcchCounterListLength: *mut u32, // DWORD* in/out
mszInstanceList: *mut u8, // LPSTR optional, out
pcchInstanceListLength: *mut u32, // DWORD* in/out
dwDetailLevel: u32, // PERF_DETAIL
dwFlags: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("pdh.dll", CharSet = CharSet.Ansi)]
public static extern uint PdhEnumObjectItemsA([MarshalAs(UnmanagedType.LPStr)] string szDataSource, [MarshalAs(UnmanagedType.LPStr)] string szMachineName, [MarshalAs(UnmanagedType.LPStr)] string szObjectName, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszCounterList, ref uint pcchCounterListLength, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder mszInstanceList, ref uint pcchInstanceListLength, uint dwDetailLevel, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhEnumObjectItemsA' -Namespace Win32 -PassThru
# $api::PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags)#uselib "pdh.dll"
#func global PdhEnumObjectItemsA "PdhEnumObjectItemsA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; PdhEnumObjectItemsA szDataSource, szMachineName, szObjectName, varptr(mszCounterList), varptr(pcchCounterListLength), varptr(mszInstanceList), varptr(pcchInstanceListLength), dwDetailLevel, dwFlags ; 戻り値は stat
; szDataSource : LPCSTR optional -> "sptr"
; szMachineName : LPCSTR optional -> "sptr"
; szObjectName : LPCSTR -> "sptr"
; mszCounterList : LPSTR optional, out -> "sptr"
; pcchCounterListLength : DWORD* in/out -> "sptr"
; mszInstanceList : LPSTR optional, out -> "sptr"
; pcchInstanceListLength : DWORD* in/out -> "sptr"
; dwDetailLevel : PERF_DETAIL -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "pdh.dll" #cfunc global PdhEnumObjectItemsA "PdhEnumObjectItemsA" str, str, str, var, var, var, var, int, int ; res = PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags) ; szDataSource : LPCSTR optional -> "str" ; szMachineName : LPCSTR optional -> "str" ; szObjectName : LPCSTR -> "str" ; mszCounterList : LPSTR optional, out -> "var" ; pcchCounterListLength : DWORD* in/out -> "var" ; mszInstanceList : LPSTR optional, out -> "var" ; pcchInstanceListLength : DWORD* in/out -> "var" ; dwDetailLevel : PERF_DETAIL -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "pdh.dll" #cfunc global PdhEnumObjectItemsA "PdhEnumObjectItemsA" str, str, str, sptr, sptr, sptr, sptr, int, int ; res = PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, varptr(mszCounterList), varptr(pcchCounterListLength), varptr(mszInstanceList), varptr(pcchInstanceListLength), dwDetailLevel, dwFlags) ; szDataSource : LPCSTR optional -> "str" ; szMachineName : LPCSTR optional -> "str" ; szObjectName : LPCSTR -> "str" ; mszCounterList : LPSTR optional, out -> "sptr" ; pcchCounterListLength : DWORD* in/out -> "sptr" ; mszInstanceList : LPSTR optional, out -> "sptr" ; pcchInstanceListLength : DWORD* in/out -> "sptr" ; dwDetailLevel : PERF_DETAIL -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PdhEnumObjectItemsA(LPCSTR szDataSource, LPCSTR szMachineName, LPCSTR szObjectName, LPSTR mszCounterList, DWORD* pcchCounterListLength, LPSTR mszInstanceList, DWORD* pcchInstanceListLength, PERF_DETAIL dwDetailLevel, DWORD dwFlags) #uselib "pdh.dll" #cfunc global PdhEnumObjectItemsA "PdhEnumObjectItemsA" str, str, str, var, var, var, var, int, int ; res = PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags) ; szDataSource : LPCSTR optional -> "str" ; szMachineName : LPCSTR optional -> "str" ; szObjectName : LPCSTR -> "str" ; mszCounterList : LPSTR optional, out -> "var" ; pcchCounterListLength : DWORD* in/out -> "var" ; mszInstanceList : LPSTR optional, out -> "var" ; pcchInstanceListLength : DWORD* in/out -> "var" ; dwDetailLevel : PERF_DETAIL -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PdhEnumObjectItemsA(LPCSTR szDataSource, LPCSTR szMachineName, LPCSTR szObjectName, LPSTR mszCounterList, DWORD* pcchCounterListLength, LPSTR mszInstanceList, DWORD* pcchInstanceListLength, PERF_DETAIL dwDetailLevel, DWORD dwFlags) #uselib "pdh.dll" #cfunc global PdhEnumObjectItemsA "PdhEnumObjectItemsA" str, str, str, intptr, intptr, intptr, intptr, int, int ; res = PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, varptr(mszCounterList), varptr(pcchCounterListLength), varptr(mszInstanceList), varptr(pcchInstanceListLength), dwDetailLevel, dwFlags) ; szDataSource : LPCSTR optional -> "str" ; szMachineName : LPCSTR optional -> "str" ; szObjectName : LPCSTR -> "str" ; mszCounterList : LPSTR optional, out -> "intptr" ; pcchCounterListLength : DWORD* in/out -> "intptr" ; mszInstanceList : LPSTR optional, out -> "intptr" ; pcchInstanceListLength : DWORD* in/out -> "intptr" ; dwDetailLevel : PERF_DETAIL -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
pdh = windows.NewLazySystemDLL("pdh.dll")
procPdhEnumObjectItemsA = pdh.NewProc("PdhEnumObjectItemsA")
)
// szDataSource (LPCSTR optional), szMachineName (LPCSTR optional), szObjectName (LPCSTR), mszCounterList (LPSTR optional, out), pcchCounterListLength (DWORD* in/out), mszInstanceList (LPSTR optional, out), pcchInstanceListLength (DWORD* in/out), dwDetailLevel (PERF_DETAIL), dwFlags (DWORD)
r1, _, err := procPdhEnumObjectItemsA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(szDataSource))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szMachineName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(szObjectName))),
uintptr(mszCounterList),
uintptr(pcchCounterListLength),
uintptr(mszInstanceList),
uintptr(pcchInstanceListLength),
uintptr(dwDetailLevel),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PdhEnumObjectItemsA(
szDataSource: PAnsiChar; // LPCSTR optional
szMachineName: PAnsiChar; // LPCSTR optional
szObjectName: PAnsiChar; // LPCSTR
mszCounterList: PAnsiChar; // LPSTR optional, out
pcchCounterListLength: Pointer; // DWORD* in/out
mszInstanceList: PAnsiChar; // LPSTR optional, out
pcchInstanceListLength: Pointer; // DWORD* in/out
dwDetailLevel: DWORD; // PERF_DETAIL
dwFlags: DWORD // DWORD
): DWORD; stdcall;
external 'pdh.dll' name 'PdhEnumObjectItemsA';result := DllCall("pdh\PdhEnumObjectItemsA"
, "AStr", szDataSource ; LPCSTR optional
, "AStr", szMachineName ; LPCSTR optional
, "AStr", szObjectName ; LPCSTR
, "Ptr", mszCounterList ; LPSTR optional, out
, "Ptr", pcchCounterListLength ; DWORD* in/out
, "Ptr", mszInstanceList ; LPSTR optional, out
, "Ptr", pcchInstanceListLength ; DWORD* in/out
, "UInt", dwDetailLevel ; PERF_DETAIL
, "UInt", dwFlags ; DWORD
, "UInt") ; return: DWORD●PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags) = DLL("pdh.dll", "dword PdhEnumObjectItemsA(char*, char*, char*, char*, void*, char*, void*, dword, dword)")
# 呼び出し: PdhEnumObjectItemsA(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags)
# szDataSource : LPCSTR optional -> "char*"
# szMachineName : LPCSTR optional -> "char*"
# szObjectName : LPCSTR -> "char*"
# mszCounterList : LPSTR optional, out -> "char*"
# pcchCounterListLength : DWORD* in/out -> "void*"
# mszInstanceList : LPSTR optional, out -> "char*"
# pcchInstanceListLength : DWORD* in/out -> "void*"
# dwDetailLevel : PERF_DETAIL -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。