ホーム › System.Performance › PdhGetFormattedCounterValue
PdhGetFormattedCounterValue
関数カウンターの値を指定形式に整形して取得する。
シグネチャ
// pdh.dll
#include <windows.h>
DWORD PdhGetFormattedCounterValue(
PDH_HCOUNTER hCounter,
PDH_FMT dwFormat,
DWORD* lpdwType, // optional
PDH_FMT_COUNTERVALUE* pValue
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hCounter | PDH_HCOUNTER | in |
| dwFormat | PDH_FMT | in |
| lpdwType | DWORD* | outoptional |
| pValue | PDH_FMT_COUNTERVALUE* | out |
戻り値の型: DWORD
各言語での呼び出し定義
// pdh.dll
#include <windows.h>
DWORD PdhGetFormattedCounterValue(
PDH_HCOUNTER hCounter,
PDH_FMT dwFormat,
DWORD* lpdwType, // optional
PDH_FMT_COUNTERVALUE* pValue
);[DllImport("pdh.dll", ExactSpelling = true)]
static extern uint PdhGetFormattedCounterValue(
IntPtr hCounter, // PDH_HCOUNTER
uint dwFormat, // PDH_FMT
IntPtr lpdwType, // DWORD* optional, out
IntPtr pValue // PDH_FMT_COUNTERVALUE* out
);<DllImport("pdh.dll", ExactSpelling:=True)>
Public Shared Function PdhGetFormattedCounterValue(
hCounter As IntPtr, ' PDH_HCOUNTER
dwFormat As UInteger, ' PDH_FMT
lpdwType As IntPtr, ' DWORD* optional, out
pValue As IntPtr ' PDH_FMT_COUNTERVALUE* out
) As UInteger
End Function' hCounter : PDH_HCOUNTER
' dwFormat : PDH_FMT
' lpdwType : DWORD* optional, out
' pValue : PDH_FMT_COUNTERVALUE* out
Declare PtrSafe Function PdhGetFormattedCounterValue Lib "pdh" ( _
ByVal hCounter As LongPtr, _
ByVal dwFormat As Long, _
ByVal lpdwType As LongPtr, _
ByVal pValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PdhGetFormattedCounterValue = ctypes.windll.pdh.PdhGetFormattedCounterValue
PdhGetFormattedCounterValue.restype = wintypes.DWORD
PdhGetFormattedCounterValue.argtypes = [
wintypes.HANDLE, # hCounter : PDH_HCOUNTER
wintypes.DWORD, # dwFormat : PDH_FMT
ctypes.POINTER(wintypes.DWORD), # lpdwType : DWORD* optional, out
ctypes.c_void_p, # pValue : PDH_FMT_COUNTERVALUE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('pdh.dll')
PdhGetFormattedCounterValue = Fiddle::Function.new(
lib['PdhGetFormattedCounterValue'],
[
Fiddle::TYPE_VOIDP, # hCounter : PDH_HCOUNTER
-Fiddle::TYPE_INT, # dwFormat : PDH_FMT
Fiddle::TYPE_VOIDP, # lpdwType : DWORD* optional, out
Fiddle::TYPE_VOIDP, # pValue : PDH_FMT_COUNTERVALUE* out
],
-Fiddle::TYPE_INT)#[link(name = "pdh")]
extern "system" {
fn PdhGetFormattedCounterValue(
hCounter: *mut core::ffi::c_void, // PDH_HCOUNTER
dwFormat: u32, // PDH_FMT
lpdwType: *mut u32, // DWORD* optional, out
pValue: *mut PDH_FMT_COUNTERVALUE // PDH_FMT_COUNTERVALUE* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("pdh.dll")]
public static extern uint PdhGetFormattedCounterValue(IntPtr hCounter, uint dwFormat, IntPtr lpdwType, IntPtr pValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhGetFormattedCounterValue' -Namespace Win32 -PassThru
# $api::PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue)#uselib "pdh.dll"
#func global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" sptr, sptr, sptr, sptr
; PdhGetFormattedCounterValue hCounter, dwFormat, varptr(lpdwType), varptr(pValue) ; 戻り値は stat
; hCounter : PDH_HCOUNTER -> "sptr"
; dwFormat : PDH_FMT -> "sptr"
; lpdwType : DWORD* optional, out -> "sptr"
; pValue : PDH_FMT_COUNTERVALUE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "pdh.dll" #cfunc global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" sptr, int, var, var ; res = PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue) ; hCounter : PDH_HCOUNTER -> "sptr" ; dwFormat : PDH_FMT -> "int" ; lpdwType : DWORD* optional, out -> "var" ; pValue : PDH_FMT_COUNTERVALUE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "pdh.dll" #cfunc global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" sptr, int, sptr, sptr ; res = PdhGetFormattedCounterValue(hCounter, dwFormat, varptr(lpdwType), varptr(pValue)) ; hCounter : PDH_HCOUNTER -> "sptr" ; dwFormat : PDH_FMT -> "int" ; lpdwType : DWORD* optional, out -> "sptr" ; pValue : PDH_FMT_COUNTERVALUE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PdhGetFormattedCounterValue(PDH_HCOUNTER hCounter, PDH_FMT dwFormat, DWORD* lpdwType, PDH_FMT_COUNTERVALUE* pValue) #uselib "pdh.dll" #cfunc global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" intptr, int, var, var ; res = PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue) ; hCounter : PDH_HCOUNTER -> "intptr" ; dwFormat : PDH_FMT -> "int" ; lpdwType : DWORD* optional, out -> "var" ; pValue : PDH_FMT_COUNTERVALUE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PdhGetFormattedCounterValue(PDH_HCOUNTER hCounter, PDH_FMT dwFormat, DWORD* lpdwType, PDH_FMT_COUNTERVALUE* pValue) #uselib "pdh.dll" #cfunc global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" intptr, int, intptr, intptr ; res = PdhGetFormattedCounterValue(hCounter, dwFormat, varptr(lpdwType), varptr(pValue)) ; hCounter : PDH_HCOUNTER -> "intptr" ; dwFormat : PDH_FMT -> "int" ; lpdwType : DWORD* optional, out -> "intptr" ; pValue : PDH_FMT_COUNTERVALUE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
pdh = windows.NewLazySystemDLL("pdh.dll")
procPdhGetFormattedCounterValue = pdh.NewProc("PdhGetFormattedCounterValue")
)
// hCounter (PDH_HCOUNTER), dwFormat (PDH_FMT), lpdwType (DWORD* optional, out), pValue (PDH_FMT_COUNTERVALUE* out)
r1, _, err := procPdhGetFormattedCounterValue.Call(
uintptr(hCounter),
uintptr(dwFormat),
uintptr(lpdwType),
uintptr(pValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PdhGetFormattedCounterValue(
hCounter: THandle; // PDH_HCOUNTER
dwFormat: DWORD; // PDH_FMT
lpdwType: Pointer; // DWORD* optional, out
pValue: Pointer // PDH_FMT_COUNTERVALUE* out
): DWORD; stdcall;
external 'pdh.dll' name 'PdhGetFormattedCounterValue';result := DllCall("pdh\PdhGetFormattedCounterValue"
, "Ptr", hCounter ; PDH_HCOUNTER
, "UInt", dwFormat ; PDH_FMT
, "Ptr", lpdwType ; DWORD* optional, out
, "Ptr", pValue ; PDH_FMT_COUNTERVALUE* out
, "UInt") ; return: DWORD●PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue) = DLL("pdh.dll", "dword PdhGetFormattedCounterValue(void*, dword, void*, void*)")
# 呼び出し: PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue)
# hCounter : PDH_HCOUNTER -> "void*"
# dwFormat : PDH_FMT -> "dword"
# lpdwType : DWORD* optional, out -> "void*"
# pValue : PDH_FMT_COUNTERVALUE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。