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

HdvWriteGuestMemory

関数
ゲスト物理メモリへデータを書き込む。
DLLvmdevicehost.dll呼出規約winapi

シグネチャ

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

HRESULT HdvWriteGuestMemory(
    void* requestor,
    ULONGLONG guestPhysicalAddress,
    DWORD byteCount,
    const BYTE* buffer
);

パラメーター

名前方向
requestorvoid*in
guestPhysicalAddressULONGLONGin
byteCountDWORDin
bufferBYTE*in

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT HdvWriteGuestMemory(
    void* requestor,
    ULONGLONG guestPhysicalAddress,
    DWORD byteCount,
    const BYTE* buffer
);
[DllImport("vmdevicehost.dll", ExactSpelling = true)]
static extern int HdvWriteGuestMemory(
    IntPtr requestor,   // void*
    ulong guestPhysicalAddress,   // ULONGLONG
    uint byteCount,   // DWORD
    IntPtr buffer   // BYTE*
);
<DllImport("vmdevicehost.dll", ExactSpelling:=True)>
Public Shared Function HdvWriteGuestMemory(
    requestor As IntPtr,   ' void*
    guestPhysicalAddress As ULong,   ' ULONGLONG
    byteCount As UInteger,   ' DWORD
    buffer As IntPtr   ' BYTE*
) As Integer
End Function
' requestor : void*
' guestPhysicalAddress : ULONGLONG
' byteCount : DWORD
' buffer : BYTE*
Declare PtrSafe Function HdvWriteGuestMemory Lib "vmdevicehost" ( _
    ByVal requestor As LongPtr, _
    ByVal guestPhysicalAddress As LongLong, _
    ByVal byteCount As Long, _
    ByVal buffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HdvWriteGuestMemory = ctypes.windll.vmdevicehost.HdvWriteGuestMemory
HdvWriteGuestMemory.restype = ctypes.c_int
HdvWriteGuestMemory.argtypes = [
    ctypes.POINTER(None),  # requestor : void*
    ctypes.c_ulonglong,  # guestPhysicalAddress : ULONGLONG
    wintypes.DWORD,  # byteCount : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # buffer : BYTE*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('vmdevicehost.dll')
HdvWriteGuestMemory = Fiddle::Function.new(
  lib['HdvWriteGuestMemory'],
  [
    Fiddle::TYPE_VOIDP,  # requestor : void*
    -Fiddle::TYPE_LONG_LONG,  # guestPhysicalAddress : ULONGLONG
    -Fiddle::TYPE_INT,  # byteCount : DWORD
    Fiddle::TYPE_VOIDP,  # buffer : BYTE*
  ],
  Fiddle::TYPE_INT)
#[link(name = "vmdevicehost")]
extern "system" {
    fn HdvWriteGuestMemory(
        requestor: *mut (),  // void*
        guestPhysicalAddress: u64,  // ULONGLONG
        byteCount: u32,  // DWORD
        buffer: *const u8  // BYTE*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("vmdevicehost.dll")]
public static extern int HdvWriteGuestMemory(IntPtr requestor, ulong guestPhysicalAddress, uint byteCount, IntPtr buffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'vmdevicehost_HdvWriteGuestMemory' -Namespace Win32 -PassThru
# $api::HdvWriteGuestMemory(requestor, guestPhysicalAddress, byteCount, buffer)
#uselib "vmdevicehost.dll"
#func global HdvWriteGuestMemory "HdvWriteGuestMemory" sptr, sptr, sptr, sptr
; HdvWriteGuestMemory requestor, guestPhysicalAddress, byteCount, varptr(buffer)   ; 戻り値は stat
; requestor : void* -> "sptr"
; guestPhysicalAddress : ULONGLONG -> "sptr"
; byteCount : DWORD -> "sptr"
; buffer : BYTE* -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "vmdevicehost.dll"
#cfunc global HdvWriteGuestMemory "HdvWriteGuestMemory" sptr, int64, int, var
; res = HdvWriteGuestMemory(requestor, guestPhysicalAddress, byteCount, buffer)
; requestor : void* -> "sptr"
; guestPhysicalAddress : ULONGLONG -> "int64"
; byteCount : DWORD -> "int"
; buffer : BYTE* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; HRESULT HdvWriteGuestMemory(void* requestor, ULONGLONG guestPhysicalAddress, DWORD byteCount, BYTE* buffer)
#uselib "vmdevicehost.dll"
#cfunc global HdvWriteGuestMemory "HdvWriteGuestMemory" intptr, int64, int, var
; res = HdvWriteGuestMemory(requestor, guestPhysicalAddress, byteCount, buffer)
; requestor : void* -> "intptr"
; guestPhysicalAddress : ULONGLONG -> "int64"
; byteCount : DWORD -> "int"
; buffer : BYTE* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	vmdevicehost = windows.NewLazySystemDLL("vmdevicehost.dll")
	procHdvWriteGuestMemory = vmdevicehost.NewProc("HdvWriteGuestMemory")
)

// requestor (void*), guestPhysicalAddress (ULONGLONG), byteCount (DWORD), buffer (BYTE*)
r1, _, err := procHdvWriteGuestMemory.Call(
	uintptr(requestor),
	uintptr(guestPhysicalAddress),
	uintptr(byteCount),
	uintptr(buffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function HdvWriteGuestMemory(
  requestor: Pointer;   // void*
  guestPhysicalAddress: UInt64;   // ULONGLONG
  byteCount: DWORD;   // DWORD
  buffer: Pointer   // BYTE*
): Integer; stdcall;
  external 'vmdevicehost.dll' name 'HdvWriteGuestMemory';
result := DllCall("vmdevicehost\HdvWriteGuestMemory"
    , "Ptr", requestor   ; void*
    , "Int64", guestPhysicalAddress   ; ULONGLONG
    , "UInt", byteCount   ; DWORD
    , "Ptr", buffer   ; BYTE*
    , "Int")   ; return: HRESULT
●HdvWriteGuestMemory(requestor, guestPhysicalAddress, byteCount, buffer) = DLL("vmdevicehost.dll", "int HdvWriteGuestMemory(void*, qword, dword, void*)")
# 呼び出し: HdvWriteGuestMemory(requestor, guestPhysicalAddress, byteCount, buffer)
# requestor : void* -> "void*"
# guestPhysicalAddress : ULONGLONG -> "qword"
# byteCount : DWORD -> "dword"
# buffer : BYTE* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。