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