ホーム › System.Hypervisor › WHvGetPartitionCounters
WHvGetPartitionCounters
関数パーティションのパフォーマンスカウンタ情報を取得する。
シグネチャ
// WinHvPlatform.dll
#include <windows.h>
HRESULT WHvGetPartitionCounters(
WHV_PARTITION_HANDLE Partition,
WHV_PARTITION_COUNTER_SET CounterSet,
void* Buffer,
DWORD BufferSizeInBytes,
DWORD* BytesWritten // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Partition | WHV_PARTITION_HANDLE | in | 対象パーティションのハンドルを指定する。 |
| CounterSet | WHV_PARTITION_COUNTER_SET | in | 取得するパーティション単位のカウンタセットの種類を指定する列挙値。 |
| Buffer | void* | out | カウンタ値を受け取る出力バッファへのポインタ。 |
| BufferSizeInBytes | DWORD | in | Bufferが指すバッファのバイト単位のサイズを指定する。 |
| BytesWritten | DWORD* | outoptional | 実際に書き込まれたバイト数を受け取る出力ポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// WinHvPlatform.dll
#include <windows.h>
HRESULT WHvGetPartitionCounters(
WHV_PARTITION_HANDLE Partition,
WHV_PARTITION_COUNTER_SET CounterSet,
void* Buffer,
DWORD BufferSizeInBytes,
DWORD* BytesWritten // optional
);[DllImport("WinHvPlatform.dll", ExactSpelling = true)]
static extern int WHvGetPartitionCounters(
IntPtr Partition, // WHV_PARTITION_HANDLE
int CounterSet, // WHV_PARTITION_COUNTER_SET
IntPtr Buffer, // void* out
uint BufferSizeInBytes, // DWORD
IntPtr BytesWritten // DWORD* optional, out
);<DllImport("WinHvPlatform.dll", ExactSpelling:=True)>
Public Shared Function WHvGetPartitionCounters(
Partition As IntPtr, ' WHV_PARTITION_HANDLE
CounterSet As Integer, ' WHV_PARTITION_COUNTER_SET
Buffer As IntPtr, ' void* out
BufferSizeInBytes As UInteger, ' DWORD
BytesWritten As IntPtr ' DWORD* optional, out
) As Integer
End Function' Partition : WHV_PARTITION_HANDLE
' CounterSet : WHV_PARTITION_COUNTER_SET
' Buffer : void* out
' BufferSizeInBytes : DWORD
' BytesWritten : DWORD* optional, out
Declare PtrSafe Function WHvGetPartitionCounters Lib "winhvplatform" ( _
ByVal Partition As LongPtr, _
ByVal CounterSet As Long, _
ByVal Buffer As LongPtr, _
ByVal BufferSizeInBytes As Long, _
ByVal BytesWritten As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WHvGetPartitionCounters = ctypes.windll.winhvplatform.WHvGetPartitionCounters
WHvGetPartitionCounters.restype = ctypes.c_int
WHvGetPartitionCounters.argtypes = [
ctypes.c_ssize_t, # Partition : WHV_PARTITION_HANDLE
ctypes.c_int, # CounterSet : WHV_PARTITION_COUNTER_SET
ctypes.POINTER(None), # Buffer : void* out
wintypes.DWORD, # BufferSizeInBytes : DWORD
ctypes.POINTER(wintypes.DWORD), # BytesWritten : DWORD* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WinHvPlatform.dll')
WHvGetPartitionCounters = Fiddle::Function.new(
lib['WHvGetPartitionCounters'],
[
Fiddle::TYPE_INTPTR_T, # Partition : WHV_PARTITION_HANDLE
Fiddle::TYPE_INT, # CounterSet : WHV_PARTITION_COUNTER_SET
Fiddle::TYPE_VOIDP, # Buffer : void* out
-Fiddle::TYPE_INT, # BufferSizeInBytes : DWORD
Fiddle::TYPE_VOIDP, # BytesWritten : DWORD* optional, out
],
Fiddle::TYPE_INT)#[link(name = "winhvplatform")]
extern "system" {
fn WHvGetPartitionCounters(
Partition: isize, // WHV_PARTITION_HANDLE
CounterSet: i32, // WHV_PARTITION_COUNTER_SET
Buffer: *mut (), // void* out
BufferSizeInBytes: u32, // DWORD
BytesWritten: *mut u32 // DWORD* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WinHvPlatform.dll")]
public static extern int WHvGetPartitionCounters(IntPtr Partition, int CounterSet, IntPtr Buffer, uint BufferSizeInBytes, IntPtr BytesWritten);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinHvPlatform_WHvGetPartitionCounters' -Namespace Win32 -PassThru
# $api::WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)#uselib "WinHvPlatform.dll"
#func global WHvGetPartitionCounters "WHvGetPartitionCounters" sptr, sptr, sptr, sptr, sptr
; WHvGetPartitionCounters Partition, CounterSet, Buffer, BufferSizeInBytes, varptr(BytesWritten) ; 戻り値は stat
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; CounterSet : WHV_PARTITION_COUNTER_SET -> "sptr"
; Buffer : void* out -> "sptr"
; BufferSizeInBytes : DWORD -> "sptr"
; BytesWritten : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WinHvPlatform.dll" #cfunc global WHvGetPartitionCounters "WHvGetPartitionCounters" sptr, int, sptr, int, var ; res = WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten) ; Partition : WHV_PARTITION_HANDLE -> "sptr" ; CounterSet : WHV_PARTITION_COUNTER_SET -> "int" ; Buffer : void* out -> "sptr" ; BufferSizeInBytes : DWORD -> "int" ; BytesWritten : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WinHvPlatform.dll" #cfunc global WHvGetPartitionCounters "WHvGetPartitionCounters" sptr, int, sptr, int, sptr ; res = WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, varptr(BytesWritten)) ; Partition : WHV_PARTITION_HANDLE -> "sptr" ; CounterSet : WHV_PARTITION_COUNTER_SET -> "int" ; Buffer : void* out -> "sptr" ; BufferSizeInBytes : DWORD -> "int" ; BytesWritten : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT WHvGetPartitionCounters(WHV_PARTITION_HANDLE Partition, WHV_PARTITION_COUNTER_SET CounterSet, void* Buffer, DWORD BufferSizeInBytes, DWORD* BytesWritten) #uselib "WinHvPlatform.dll" #cfunc global WHvGetPartitionCounters "WHvGetPartitionCounters" intptr, int, intptr, int, var ; res = WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten) ; Partition : WHV_PARTITION_HANDLE -> "intptr" ; CounterSet : WHV_PARTITION_COUNTER_SET -> "int" ; Buffer : void* out -> "intptr" ; BufferSizeInBytes : DWORD -> "int" ; BytesWritten : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT WHvGetPartitionCounters(WHV_PARTITION_HANDLE Partition, WHV_PARTITION_COUNTER_SET CounterSet, void* Buffer, DWORD BufferSizeInBytes, DWORD* BytesWritten) #uselib "WinHvPlatform.dll" #cfunc global WHvGetPartitionCounters "WHvGetPartitionCounters" intptr, int, intptr, int, intptr ; res = WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, varptr(BytesWritten)) ; Partition : WHV_PARTITION_HANDLE -> "intptr" ; CounterSet : WHV_PARTITION_COUNTER_SET -> "int" ; Buffer : void* out -> "intptr" ; BufferSizeInBytes : DWORD -> "int" ; BytesWritten : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winhvplatform = windows.NewLazySystemDLL("WinHvPlatform.dll")
procWHvGetPartitionCounters = winhvplatform.NewProc("WHvGetPartitionCounters")
)
// Partition (WHV_PARTITION_HANDLE), CounterSet (WHV_PARTITION_COUNTER_SET), Buffer (void* out), BufferSizeInBytes (DWORD), BytesWritten (DWORD* optional, out)
r1, _, err := procWHvGetPartitionCounters.Call(
uintptr(Partition),
uintptr(CounterSet),
uintptr(Buffer),
uintptr(BufferSizeInBytes),
uintptr(BytesWritten),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WHvGetPartitionCounters(
Partition: NativeInt; // WHV_PARTITION_HANDLE
CounterSet: Integer; // WHV_PARTITION_COUNTER_SET
Buffer: Pointer; // void* out
BufferSizeInBytes: DWORD; // DWORD
BytesWritten: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'WinHvPlatform.dll' name 'WHvGetPartitionCounters';result := DllCall("WinHvPlatform\WHvGetPartitionCounters"
, "Ptr", Partition ; WHV_PARTITION_HANDLE
, "Int", CounterSet ; WHV_PARTITION_COUNTER_SET
, "Ptr", Buffer ; void* out
, "UInt", BufferSizeInBytes ; DWORD
, "Ptr", BytesWritten ; DWORD* optional, out
, "Int") ; return: HRESULT●WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten) = DLL("WinHvPlatform.dll", "int WHvGetPartitionCounters(int, int, void*, dword, void*)")
# 呼び出し: WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)
# Partition : WHV_PARTITION_HANDLE -> "int"
# CounterSet : WHV_PARTITION_COUNTER_SET -> "int"
# Buffer : void* out -> "void*"
# BufferSizeInBytes : DWORD -> "dword"
# BytesWritten : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winhvplatform" fn WHvGetPartitionCounters(
Partition: isize, // WHV_PARTITION_HANDLE
CounterSet: i32, // WHV_PARTITION_COUNTER_SET
Buffer: ?*anyopaque, // void* out
BufferSizeInBytes: u32, // DWORD
BytesWritten: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc WHvGetPartitionCounters(
Partition: int, # WHV_PARTITION_HANDLE
CounterSet: int32, # WHV_PARTITION_COUNTER_SET
Buffer: pointer, # void* out
BufferSizeInBytes: uint32, # DWORD
BytesWritten: ptr uint32 # DWORD* optional, out
): int32 {.importc: "WHvGetPartitionCounters", stdcall, dynlib: "WinHvPlatform.dll".}pragma(lib, "winhvplatform");
extern(Windows)
int WHvGetPartitionCounters(
ptrdiff_t Partition, // WHV_PARTITION_HANDLE
int CounterSet, // WHV_PARTITION_COUNTER_SET
void* Buffer, // void* out
uint BufferSizeInBytes, // DWORD
uint* BytesWritten // DWORD* optional, out
);ccall((:WHvGetPartitionCounters, "WinHvPlatform.dll"), stdcall, Int32,
(Int, Int32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)
# Partition : WHV_PARTITION_HANDLE -> Int
# CounterSet : WHV_PARTITION_COUNTER_SET -> Int32
# Buffer : void* out -> Ptr{Cvoid}
# BufferSizeInBytes : DWORD -> UInt32
# BytesWritten : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WHvGetPartitionCounters(
intptr_t Partition,
int32_t CounterSet,
void* Buffer,
uint32_t BufferSizeInBytes,
uint32_t* BytesWritten);
]]
local winhvplatform = ffi.load("winhvplatform")
-- winhvplatform.WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)
-- Partition : WHV_PARTITION_HANDLE
-- CounterSet : WHV_PARTITION_COUNTER_SET
-- Buffer : void* out
-- BufferSizeInBytes : DWORD
-- BytesWritten : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WinHvPlatform.dll');
const WHvGetPartitionCounters = lib.func('__stdcall', 'WHvGetPartitionCounters', 'int32_t', ['intptr_t', 'int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)
// Partition : WHV_PARTITION_HANDLE -> 'intptr_t'
// CounterSet : WHV_PARTITION_COUNTER_SET -> 'int32_t'
// Buffer : void* out -> 'void *'
// BufferSizeInBytes : DWORD -> 'uint32_t'
// BytesWritten : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WinHvPlatform.dll", {
WHvGetPartitionCounters: { parameters: ["isize", "i32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten)
// Partition : WHV_PARTITION_HANDLE -> "isize"
// CounterSet : WHV_PARTITION_COUNTER_SET -> "i32"
// Buffer : void* out -> "pointer"
// BufferSizeInBytes : DWORD -> "u32"
// BytesWritten : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WHvGetPartitionCounters(
intptr_t Partition,
int32_t CounterSet,
void* Buffer,
uint32_t BufferSizeInBytes,
uint32_t* BytesWritten);
C, "WinHvPlatform.dll");
// $ffi->WHvGetPartitionCounters(Partition, CounterSet, Buffer, BufferSizeInBytes, BytesWritten);
// Partition : WHV_PARTITION_HANDLE
// CounterSet : WHV_PARTITION_COUNTER_SET
// Buffer : void* out
// BufferSizeInBytes : DWORD
// BytesWritten : DWORD* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Winhvplatform extends StdCallLibrary {
Winhvplatform INSTANCE = Native.load("winhvplatform", Winhvplatform.class);
int WHvGetPartitionCounters(
long Partition, // WHV_PARTITION_HANDLE
int CounterSet, // WHV_PARTITION_COUNTER_SET
Pointer Buffer, // void* out
int BufferSizeInBytes, // DWORD
IntByReference BytesWritten // DWORD* optional, out
);
}@[Link("winhvplatform")]
lib LibWinHvPlatform
fun WHvGetPartitionCounters = WHvGetPartitionCounters(
Partition : LibC::SSizeT, # WHV_PARTITION_HANDLE
CounterSet : Int32, # WHV_PARTITION_COUNTER_SET
Buffer : Void*, # void* out
BufferSizeInBytes : UInt32, # DWORD
BytesWritten : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WHvGetPartitionCountersNative = Int32 Function(IntPtr, Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef WHvGetPartitionCountersDart = int Function(int, int, Pointer<Void>, int, Pointer<Uint32>);
final WHvGetPartitionCounters = DynamicLibrary.open('WinHvPlatform.dll')
.lookupFunction<WHvGetPartitionCountersNative, WHvGetPartitionCountersDart>('WHvGetPartitionCounters');
// Partition : WHV_PARTITION_HANDLE -> IntPtr
// CounterSet : WHV_PARTITION_COUNTER_SET -> Int32
// Buffer : void* out -> Pointer<Void>
// BufferSizeInBytes : DWORD -> Uint32
// BytesWritten : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WHvGetPartitionCounters(
Partition: NativeInt; // WHV_PARTITION_HANDLE
CounterSet: Integer; // WHV_PARTITION_COUNTER_SET
Buffer: Pointer; // void* out
BufferSizeInBytes: DWORD; // DWORD
BytesWritten: Pointer // DWORD* optional, out
): Integer; stdcall;
external 'WinHvPlatform.dll' name 'WHvGetPartitionCounters';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WHvGetPartitionCounters"
c_WHvGetPartitionCounters :: CIntPtr -> Int32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- Partition : WHV_PARTITION_HANDLE -> CIntPtr
-- CounterSet : WHV_PARTITION_COUNTER_SET -> Int32
-- Buffer : void* out -> Ptr ()
-- BufferSizeInBytes : DWORD -> Word32
-- BytesWritten : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let whvgetpartitioncounters =
foreign "WHvGetPartitionCounters"
(intptr_t @-> int32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* Partition : WHV_PARTITION_HANDLE -> intptr_t *)
(* CounterSet : WHV_PARTITION_COUNTER_SET -> int32_t *)
(* Buffer : void* out -> (ptr void) *)
(* BufferSizeInBytes : DWORD -> uint32_t *)
(* BytesWritten : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winhvplatform (t "WinHvPlatform.dll"))
(cffi:use-foreign-library winhvplatform)
(cffi:defcfun ("WHvGetPartitionCounters" whv-get-partition-counters :convention :stdcall) :int32
(partition :int64) ; WHV_PARTITION_HANDLE
(counter-set :int32) ; WHV_PARTITION_COUNTER_SET
(buffer :pointer) ; void* out
(buffer-size-in-bytes :uint32) ; DWORD
(bytes-written :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WHvGetPartitionCounters = Win32::API::More->new('WinHvPlatform',
'int WHvGetPartitionCounters(LPARAM Partition, int CounterSet, LPVOID Buffer, DWORD BufferSizeInBytes, LPVOID BytesWritten)');
# my $ret = $WHvGetPartitionCounters->Call($Partition, $CounterSet, $Buffer, $BufferSizeInBytes, $BytesWritten);
# Partition : WHV_PARTITION_HANDLE -> LPARAM
# CounterSet : WHV_PARTITION_COUNTER_SET -> int
# Buffer : void* out -> LPVOID
# BufferSizeInBytes : DWORD -> DWORD
# BytesWritten : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。