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

ReadSavedStateGlobalVariable

関数
保存状態のグローバル変数の値を読み取る。
DLLVmSavedStateDumpProvider.dll呼出規約winapi

シグネチャ

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

HRESULT ReadSavedStateGlobalVariable(
    void* vmSavedStateDumpHandle,
    DWORD vpId,
    LPCSTR globalName,
    void* buffer,
    DWORD bufferSize
);

パラメーター

名前方向説明
vmSavedStateDumpHandlevoid*inout対象の保存状態ダンプハンドルを指定する。
vpIdDWORDinアドレス解決のコンテキストとなる仮想プロセッサのIDを指定する。
globalNameLPCSTRin読み取るグローバル変数名を指定するANSI文字列。
buffervoid*outグローバル変数の値を受け取る出力バッファへのポインタ。
bufferSizeDWORDinbufferのバイト単位のサイズを指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ReadSavedStateGlobalVariable(
    void* vmSavedStateDumpHandle,
    DWORD vpId,
    LPCSTR globalName,
    void* buffer,
    DWORD bufferSize
);
[DllImport("VmSavedStateDumpProvider.dll", ExactSpelling = true)]
static extern int ReadSavedStateGlobalVariable(
    IntPtr vmSavedStateDumpHandle,   // void* in/out
    uint vpId,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string globalName,   // LPCSTR
    IntPtr buffer,   // void* out
    uint bufferSize   // DWORD
);
<DllImport("VmSavedStateDumpProvider.dll", ExactSpelling:=True)>
Public Shared Function ReadSavedStateGlobalVariable(
    vmSavedStateDumpHandle As IntPtr,   ' void* in/out
    vpId As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> globalName As String,   ' LPCSTR
    buffer As IntPtr,   ' void* out
    bufferSize As UInteger   ' DWORD
) As Integer
End Function
' vmSavedStateDumpHandle : void* in/out
' vpId : DWORD
' globalName : LPCSTR
' buffer : void* out
' bufferSize : DWORD
Declare PtrSafe Function ReadSavedStateGlobalVariable Lib "vmsavedstatedumpprovider" ( _
    ByVal vmSavedStateDumpHandle As LongPtr, _
    ByVal vpId As Long, _
    ByVal globalName As String, _
    ByVal buffer As LongPtr, _
    ByVal bufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ReadSavedStateGlobalVariable = ctypes.windll.vmsavedstatedumpprovider.ReadSavedStateGlobalVariable
ReadSavedStateGlobalVariable.restype = ctypes.c_int
ReadSavedStateGlobalVariable.argtypes = [
    ctypes.POINTER(None),  # vmSavedStateDumpHandle : void* in/out
    wintypes.DWORD,  # vpId : DWORD
    wintypes.LPCSTR,  # globalName : LPCSTR
    ctypes.POINTER(None),  # buffer : void* out
    wintypes.DWORD,  # bufferSize : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('VmSavedStateDumpProvider.dll')
ReadSavedStateGlobalVariable = Fiddle::Function.new(
  lib['ReadSavedStateGlobalVariable'],
  [
    Fiddle::TYPE_VOIDP,  # vmSavedStateDumpHandle : void* in/out
    -Fiddle::TYPE_INT,  # vpId : DWORD
    Fiddle::TYPE_VOIDP,  # globalName : LPCSTR
    Fiddle::TYPE_VOIDP,  # buffer : void* out
    -Fiddle::TYPE_INT,  # bufferSize : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "vmsavedstatedumpprovider")]
extern "system" {
    fn ReadSavedStateGlobalVariable(
        vmSavedStateDumpHandle: *mut (),  // void* in/out
        vpId: u32,  // DWORD
        globalName: *const u8,  // LPCSTR
        buffer: *mut (),  // void* out
        bufferSize: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("VmSavedStateDumpProvider.dll")]
public static extern int ReadSavedStateGlobalVariable(IntPtr vmSavedStateDumpHandle, uint vpId, [MarshalAs(UnmanagedType.LPStr)] string globalName, IntPtr buffer, uint bufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'VmSavedStateDumpProvider_ReadSavedStateGlobalVariable' -Namespace Win32 -PassThru
# $api::ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
#uselib "VmSavedStateDumpProvider.dll"
#func global ReadSavedStateGlobalVariable "ReadSavedStateGlobalVariable" sptr, sptr, sptr, sptr, sptr
; ReadSavedStateGlobalVariable vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize   ; 戻り値は stat
; vmSavedStateDumpHandle : void* in/out -> "sptr"
; vpId : DWORD -> "sptr"
; globalName : LPCSTR -> "sptr"
; buffer : void* out -> "sptr"
; bufferSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "VmSavedStateDumpProvider.dll"
#cfunc global ReadSavedStateGlobalVariable "ReadSavedStateGlobalVariable" sptr, int, str, sptr, int
; res = ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
; vmSavedStateDumpHandle : void* in/out -> "sptr"
; vpId : DWORD -> "int"
; globalName : LPCSTR -> "str"
; buffer : void* out -> "sptr"
; bufferSize : DWORD -> "int"
; HRESULT ReadSavedStateGlobalVariable(void* vmSavedStateDumpHandle, DWORD vpId, LPCSTR globalName, void* buffer, DWORD bufferSize)
#uselib "VmSavedStateDumpProvider.dll"
#cfunc global ReadSavedStateGlobalVariable "ReadSavedStateGlobalVariable" intptr, int, str, intptr, int
; res = ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
; vmSavedStateDumpHandle : void* in/out -> "intptr"
; vpId : DWORD -> "int"
; globalName : LPCSTR -> "str"
; buffer : void* out -> "intptr"
; bufferSize : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	vmsavedstatedumpprovider = windows.NewLazySystemDLL("VmSavedStateDumpProvider.dll")
	procReadSavedStateGlobalVariable = vmsavedstatedumpprovider.NewProc("ReadSavedStateGlobalVariable")
)

// vmSavedStateDumpHandle (void* in/out), vpId (DWORD), globalName (LPCSTR), buffer (void* out), bufferSize (DWORD)
r1, _, err := procReadSavedStateGlobalVariable.Call(
	uintptr(vmSavedStateDumpHandle),
	uintptr(vpId),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(globalName))),
	uintptr(buffer),
	uintptr(bufferSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ReadSavedStateGlobalVariable(
  vmSavedStateDumpHandle: Pointer;   // void* in/out
  vpId: DWORD;   // DWORD
  globalName: PAnsiChar;   // LPCSTR
  buffer: Pointer;   // void* out
  bufferSize: DWORD   // DWORD
): Integer; stdcall;
  external 'VmSavedStateDumpProvider.dll' name 'ReadSavedStateGlobalVariable';
result := DllCall("VmSavedStateDumpProvider\ReadSavedStateGlobalVariable"
    , "Ptr", vmSavedStateDumpHandle   ; void* in/out
    , "UInt", vpId   ; DWORD
    , "AStr", globalName   ; LPCSTR
    , "Ptr", buffer   ; void* out
    , "UInt", bufferSize   ; DWORD
    , "Int")   ; return: HRESULT
●ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize) = DLL("VmSavedStateDumpProvider.dll", "int ReadSavedStateGlobalVariable(void*, dword, char*, void*, dword)")
# 呼び出し: ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
# vmSavedStateDumpHandle : void* in/out -> "void*"
# vpId : DWORD -> "dword"
# globalName : LPCSTR -> "char*"
# buffer : void* out -> "void*"
# bufferSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "vmsavedstatedumpprovider" fn ReadSavedStateGlobalVariable(
    vmSavedStateDumpHandle: ?*anyopaque, // void* in/out
    vpId: u32, // DWORD
    globalName: [*c]const u8, // LPCSTR
    buffer: ?*anyopaque, // void* out
    bufferSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc ReadSavedStateGlobalVariable(
    vmSavedStateDumpHandle: pointer,  # void* in/out
    vpId: uint32,  # DWORD
    globalName: cstring,  # LPCSTR
    buffer: pointer,  # void* out
    bufferSize: uint32  # DWORD
): int32 {.importc: "ReadSavedStateGlobalVariable", stdcall, dynlib: "VmSavedStateDumpProvider.dll".}
pragma(lib, "vmsavedstatedumpprovider");
extern(Windows)
int ReadSavedStateGlobalVariable(
    void* vmSavedStateDumpHandle,   // void* in/out
    uint vpId,   // DWORD
    const(char)* globalName,   // LPCSTR
    void* buffer,   // void* out
    uint bufferSize   // DWORD
);
ccall((:ReadSavedStateGlobalVariable, "VmSavedStateDumpProvider.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Cstring, Ptr{Cvoid}, UInt32),
      vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
# vmSavedStateDumpHandle : void* in/out -> Ptr{Cvoid}
# vpId : DWORD -> UInt32
# globalName : LPCSTR -> Cstring
# buffer : void* out -> Ptr{Cvoid}
# bufferSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ReadSavedStateGlobalVariable(
    void* vmSavedStateDumpHandle,
    uint32_t vpId,
    const char* globalName,
    void* buffer,
    uint32_t bufferSize);
]]
local vmsavedstatedumpprovider = ffi.load("vmsavedstatedumpprovider")
-- vmsavedstatedumpprovider.ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
-- vmSavedStateDumpHandle : void* in/out
-- vpId : DWORD
-- globalName : LPCSTR
-- buffer : void* out
-- bufferSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('VmSavedStateDumpProvider.dll');
const ReadSavedStateGlobalVariable = lib.func('__stdcall', 'ReadSavedStateGlobalVariable', 'int32_t', ['void *', 'uint32_t', 'str', 'void *', 'uint32_t']);
// ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
// vmSavedStateDumpHandle : void* in/out -> 'void *'
// vpId : DWORD -> 'uint32_t'
// globalName : LPCSTR -> 'str'
// buffer : void* out -> 'void *'
// bufferSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("VmSavedStateDumpProvider.dll", {
  ReadSavedStateGlobalVariable: { parameters: ["pointer", "u32", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize)
// vmSavedStateDumpHandle : void* in/out -> "pointer"
// vpId : DWORD -> "u32"
// globalName : LPCSTR -> "buffer"
// buffer : void* out -> "pointer"
// bufferSize : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ReadSavedStateGlobalVariable(
    void* vmSavedStateDumpHandle,
    uint32_t vpId,
    const char* globalName,
    void* buffer,
    uint32_t bufferSize);
C, "VmSavedStateDumpProvider.dll");
// $ffi->ReadSavedStateGlobalVariable(vmSavedStateDumpHandle, vpId, globalName, buffer, bufferSize);
// vmSavedStateDumpHandle : void* in/out
// vpId : DWORD
// globalName : LPCSTR
// buffer : void* out
// bufferSize : DWORD
// 構造体/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 Vmsavedstatedumpprovider extends StdCallLibrary {
    Vmsavedstatedumpprovider INSTANCE = Native.load("vmsavedstatedumpprovider", Vmsavedstatedumpprovider.class);
    int ReadSavedStateGlobalVariable(
        Pointer vmSavedStateDumpHandle,   // void* in/out
        int vpId,   // DWORD
        String globalName,   // LPCSTR
        Pointer buffer,   // void* out
        int bufferSize   // DWORD
    );
}
@[Link("vmsavedstatedumpprovider")]
lib LibVmSavedStateDumpProvider
  fun ReadSavedStateGlobalVariable = ReadSavedStateGlobalVariable(
    vmSavedStateDumpHandle : Void*,   # void* in/out
    vpId : UInt32,   # DWORD
    globalName : UInt8*,   # LPCSTR
    buffer : Void*,   # void* out
    bufferSize : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ReadSavedStateGlobalVariableNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Pointer<Void>, Uint32);
typedef ReadSavedStateGlobalVariableDart = int Function(Pointer<Void>, int, Pointer<Utf8>, Pointer<Void>, int);
final ReadSavedStateGlobalVariable = DynamicLibrary.open('VmSavedStateDumpProvider.dll')
    .lookupFunction<ReadSavedStateGlobalVariableNative, ReadSavedStateGlobalVariableDart>('ReadSavedStateGlobalVariable');
// vmSavedStateDumpHandle : void* in/out -> Pointer<Void>
// vpId : DWORD -> Uint32
// globalName : LPCSTR -> Pointer<Utf8>
// buffer : void* out -> Pointer<Void>
// bufferSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ReadSavedStateGlobalVariable(
  vmSavedStateDumpHandle: Pointer;   // void* in/out
  vpId: DWORD;   // DWORD
  globalName: PAnsiChar;   // LPCSTR
  buffer: Pointer;   // void* out
  bufferSize: DWORD   // DWORD
): Integer; stdcall;
  external 'VmSavedStateDumpProvider.dll' name 'ReadSavedStateGlobalVariable';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ReadSavedStateGlobalVariable"
  c_ReadSavedStateGlobalVariable :: Ptr () -> Word32 -> CString -> Ptr () -> Word32 -> IO Int32
-- vmSavedStateDumpHandle : void* in/out -> Ptr ()
-- vpId : DWORD -> Word32
-- globalName : LPCSTR -> CString
-- buffer : void* out -> Ptr ()
-- bufferSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let readsavedstateglobalvariable =
  foreign "ReadSavedStateGlobalVariable"
    ((ptr void) @-> uint32_t @-> string @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* vmSavedStateDumpHandle : void* in/out -> (ptr void) *)
(* vpId : DWORD -> uint32_t *)
(* globalName : LPCSTR -> string *)
(* buffer : void* out -> (ptr void) *)
(* bufferSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library vmsavedstatedumpprovider (t "VmSavedStateDumpProvider.dll"))
(cffi:use-foreign-library vmsavedstatedumpprovider)

(cffi:defcfun ("ReadSavedStateGlobalVariable" read-saved-state-global-variable :convention :stdcall) :int32
  (vm-saved-state-dump-handle :pointer)   ; void* in/out
  (vp-id :uint32)   ; DWORD
  (global-name :string)   ; LPCSTR
  (buffer :pointer)   ; void* out
  (buffer-size :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ReadSavedStateGlobalVariable = Win32::API::More->new('VmSavedStateDumpProvider',
    'int ReadSavedStateGlobalVariable(LPVOID vmSavedStateDumpHandle, DWORD vpId, LPCSTR globalName, LPVOID buffer, DWORD bufferSize)');
# my $ret = $ReadSavedStateGlobalVariable->Call($vmSavedStateDumpHandle, $vpId, $globalName, $buffer, $bufferSize);
# vmSavedStateDumpHandle : void* in/out -> LPVOID
# vpId : DWORD -> DWORD
# globalName : LPCSTR -> LPCSTR
# buffer : void* out -> LPVOID
# bufferSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。