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

PdhCalculateCounterFromRawValue

関数
二つの生値からカウンター値を整形して算出する。
DLLpdh.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// pdh.dll
#include <windows.h>

DWORD PdhCalculateCounterFromRawValue(
    PDH_HCOUNTER hCounter,
    PDH_FMT dwFormat,
    PDH_RAW_COUNTER* rawValue1,
    PDH_RAW_COUNTER* rawValue2,
    PDH_FMT_COUNTERVALUE* fmtValue
);

パラメーター

名前方向
hCounterPDH_HCOUNTERin
dwFormatPDH_FMTin
rawValue1PDH_RAW_COUNTER*in
rawValue2PDH_RAW_COUNTER*in
fmtValuePDH_FMT_COUNTERVALUE*out

戻り値の型: DWORD

各言語での呼び出し定義

// pdh.dll
#include <windows.h>

DWORD PdhCalculateCounterFromRawValue(
    PDH_HCOUNTER hCounter,
    PDH_FMT dwFormat,
    PDH_RAW_COUNTER* rawValue1,
    PDH_RAW_COUNTER* rawValue2,
    PDH_FMT_COUNTERVALUE* fmtValue
);
[DllImport("pdh.dll", ExactSpelling = true)]
static extern uint PdhCalculateCounterFromRawValue(
    IntPtr hCounter,   // PDH_HCOUNTER
    uint dwFormat,   // PDH_FMT
    IntPtr rawValue1,   // PDH_RAW_COUNTER*
    IntPtr rawValue2,   // PDH_RAW_COUNTER*
    IntPtr fmtValue   // PDH_FMT_COUNTERVALUE* out
);
<DllImport("pdh.dll", ExactSpelling:=True)>
Public Shared Function PdhCalculateCounterFromRawValue(
    hCounter As IntPtr,   ' PDH_HCOUNTER
    dwFormat As UInteger,   ' PDH_FMT
    rawValue1 As IntPtr,   ' PDH_RAW_COUNTER*
    rawValue2 As IntPtr,   ' PDH_RAW_COUNTER*
    fmtValue As IntPtr   ' PDH_FMT_COUNTERVALUE* out
) As UInteger
End Function
' hCounter : PDH_HCOUNTER
' dwFormat : PDH_FMT
' rawValue1 : PDH_RAW_COUNTER*
' rawValue2 : PDH_RAW_COUNTER*
' fmtValue : PDH_FMT_COUNTERVALUE* out
Declare PtrSafe Function PdhCalculateCounterFromRawValue Lib "pdh" ( _
    ByVal hCounter As LongPtr, _
    ByVal dwFormat As Long, _
    ByVal rawValue1 As LongPtr, _
    ByVal rawValue2 As LongPtr, _
    ByVal fmtValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PdhCalculateCounterFromRawValue = ctypes.windll.pdh.PdhCalculateCounterFromRawValue
PdhCalculateCounterFromRawValue.restype = wintypes.DWORD
PdhCalculateCounterFromRawValue.argtypes = [
    wintypes.HANDLE,  # hCounter : PDH_HCOUNTER
    wintypes.DWORD,  # dwFormat : PDH_FMT
    ctypes.c_void_p,  # rawValue1 : PDH_RAW_COUNTER*
    ctypes.c_void_p,  # rawValue2 : PDH_RAW_COUNTER*
    ctypes.c_void_p,  # fmtValue : PDH_FMT_COUNTERVALUE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('pdh.dll')
PdhCalculateCounterFromRawValue = Fiddle::Function.new(
  lib['PdhCalculateCounterFromRawValue'],
  [
    Fiddle::TYPE_VOIDP,  # hCounter : PDH_HCOUNTER
    -Fiddle::TYPE_INT,  # dwFormat : PDH_FMT
    Fiddle::TYPE_VOIDP,  # rawValue1 : PDH_RAW_COUNTER*
    Fiddle::TYPE_VOIDP,  # rawValue2 : PDH_RAW_COUNTER*
    Fiddle::TYPE_VOIDP,  # fmtValue : PDH_FMT_COUNTERVALUE* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "pdh")]
extern "system" {
    fn PdhCalculateCounterFromRawValue(
        hCounter: *mut core::ffi::c_void,  // PDH_HCOUNTER
        dwFormat: u32,  // PDH_FMT
        rawValue1: *mut PDH_RAW_COUNTER,  // PDH_RAW_COUNTER*
        rawValue2: *mut PDH_RAW_COUNTER,  // PDH_RAW_COUNTER*
        fmtValue: *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 PdhCalculateCounterFromRawValue(IntPtr hCounter, uint dwFormat, IntPtr rawValue1, IntPtr rawValue2, IntPtr fmtValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhCalculateCounterFromRawValue' -Namespace Win32 -PassThru
# $api::PdhCalculateCounterFromRawValue(hCounter, dwFormat, rawValue1, rawValue2, fmtValue)
#uselib "pdh.dll"
#func global PdhCalculateCounterFromRawValue "PdhCalculateCounterFromRawValue" sptr, sptr, sptr, sptr, sptr
; PdhCalculateCounterFromRawValue hCounter, dwFormat, varptr(rawValue1), varptr(rawValue2), varptr(fmtValue)   ; 戻り値は stat
; hCounter : PDH_HCOUNTER -> "sptr"
; dwFormat : PDH_FMT -> "sptr"
; rawValue1 : PDH_RAW_COUNTER* -> "sptr"
; rawValue2 : PDH_RAW_COUNTER* -> "sptr"
; fmtValue : PDH_FMT_COUNTERVALUE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "pdh.dll"
#cfunc global PdhCalculateCounterFromRawValue "PdhCalculateCounterFromRawValue" sptr, int, var, var, var
; res = PdhCalculateCounterFromRawValue(hCounter, dwFormat, rawValue1, rawValue2, fmtValue)
; hCounter : PDH_HCOUNTER -> "sptr"
; dwFormat : PDH_FMT -> "int"
; rawValue1 : PDH_RAW_COUNTER* -> "var"
; rawValue2 : PDH_RAW_COUNTER* -> "var"
; fmtValue : PDH_FMT_COUNTERVALUE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD PdhCalculateCounterFromRawValue(PDH_HCOUNTER hCounter, PDH_FMT dwFormat, PDH_RAW_COUNTER* rawValue1, PDH_RAW_COUNTER* rawValue2, PDH_FMT_COUNTERVALUE* fmtValue)
#uselib "pdh.dll"
#cfunc global PdhCalculateCounterFromRawValue "PdhCalculateCounterFromRawValue" intptr, int, var, var, var
; res = PdhCalculateCounterFromRawValue(hCounter, dwFormat, rawValue1, rawValue2, fmtValue)
; hCounter : PDH_HCOUNTER -> "intptr"
; dwFormat : PDH_FMT -> "int"
; rawValue1 : PDH_RAW_COUNTER* -> "var"
; rawValue2 : PDH_RAW_COUNTER* -> "var"
; fmtValue : PDH_FMT_COUNTERVALUE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhCalculateCounterFromRawValue = pdh.NewProc("PdhCalculateCounterFromRawValue")
)

// hCounter (PDH_HCOUNTER), dwFormat (PDH_FMT), rawValue1 (PDH_RAW_COUNTER*), rawValue2 (PDH_RAW_COUNTER*), fmtValue (PDH_FMT_COUNTERVALUE* out)
r1, _, err := procPdhCalculateCounterFromRawValue.Call(
	uintptr(hCounter),
	uintptr(dwFormat),
	uintptr(rawValue1),
	uintptr(rawValue2),
	uintptr(fmtValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function PdhCalculateCounterFromRawValue(
  hCounter: THandle;   // PDH_HCOUNTER
  dwFormat: DWORD;   // PDH_FMT
  rawValue1: Pointer;   // PDH_RAW_COUNTER*
  rawValue2: Pointer;   // PDH_RAW_COUNTER*
  fmtValue: Pointer   // PDH_FMT_COUNTERVALUE* out
): DWORD; stdcall;
  external 'pdh.dll' name 'PdhCalculateCounterFromRawValue';
result := DllCall("pdh\PdhCalculateCounterFromRawValue"
    , "Ptr", hCounter   ; PDH_HCOUNTER
    , "UInt", dwFormat   ; PDH_FMT
    , "Ptr", rawValue1   ; PDH_RAW_COUNTER*
    , "Ptr", rawValue2   ; PDH_RAW_COUNTER*
    , "Ptr", fmtValue   ; PDH_FMT_COUNTERVALUE* out
    , "UInt")   ; return: DWORD
●PdhCalculateCounterFromRawValue(hCounter, dwFormat, rawValue1, rawValue2, fmtValue) = DLL("pdh.dll", "dword PdhCalculateCounterFromRawValue(void*, dword, void*, void*, void*)")
# 呼び出し: PdhCalculateCounterFromRawValue(hCounter, dwFormat, rawValue1, rawValue2, fmtValue)
# hCounter : PDH_HCOUNTER -> "void*"
# dwFormat : PDH_FMT -> "dword"
# rawValue1 : PDH_RAW_COUNTER* -> "void*"
# rawValue2 : PDH_RAW_COUNTER* -> "void*"
# fmtValue : PDH_FMT_COUNTERVALUE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。