Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › RangeMapWrite

RangeMapWrite

関数
範囲マップ経由でオフセット位置にデータを書き込む。
DLLdbghelp.dll呼出規約winapi

シグネチャ

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

BOOL RangeMapWrite(
    void* RmapHandle,
    ULONGLONG Offset,
    void* Buffer,
    DWORD RequestBytes,
    DWORD Flags,
    DWORD* DoneBytes   // optional
);

パラメーター

名前方向説明
RmapHandlevoid*in書き込み先のレンジマップのハンドル。
OffsetULONGLONGin書き込みを開始するマップ内オフセット。
Buffervoid*in書き込むデータを格納した入力バッファ。
RequestBytesDWORDin書き込みを要求するバイト数。
FlagsDWORDin書き込み動作を制御するフラグ。
DoneBytesDWORD*outoptional実際に書き込めたバイト数を受け取る出力ポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RangeMapWrite(
    void* RmapHandle,
    ULONGLONG Offset,
    void* Buffer,
    DWORD RequestBytes,
    DWORD Flags,
    DWORD* DoneBytes   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", ExactSpelling = true)]
static extern bool RangeMapWrite(
    IntPtr RmapHandle,   // void*
    ulong Offset,   // ULONGLONG
    IntPtr Buffer,   // void*
    uint RequestBytes,   // DWORD
    uint Flags,   // DWORD
    IntPtr DoneBytes   // DWORD* optional, out
);
<DllImport("dbghelp.dll", ExactSpelling:=True)>
Public Shared Function RangeMapWrite(
    RmapHandle As IntPtr,   ' void*
    Offset As ULong,   ' ULONGLONG
    Buffer As IntPtr,   ' void*
    RequestBytes As UInteger,   ' DWORD
    Flags As UInteger,   ' DWORD
    DoneBytes As IntPtr   ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' RmapHandle : void*
' Offset : ULONGLONG
' Buffer : void*
' RequestBytes : DWORD
' Flags : DWORD
' DoneBytes : DWORD* optional, out
Declare PtrSafe Function RangeMapWrite Lib "dbghelp" ( _
    ByVal RmapHandle As LongPtr, _
    ByVal Offset As LongLong, _
    ByVal Buffer As LongPtr, _
    ByVal RequestBytes As Long, _
    ByVal Flags As Long, _
    ByVal DoneBytes As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RangeMapWrite = ctypes.windll.dbghelp.RangeMapWrite
RangeMapWrite.restype = wintypes.BOOL
RangeMapWrite.argtypes = [
    ctypes.POINTER(None),  # RmapHandle : void*
    ctypes.c_ulonglong,  # Offset : ULONGLONG
    ctypes.POINTER(None),  # Buffer : void*
    wintypes.DWORD,  # RequestBytes : DWORD
    wintypes.DWORD,  # Flags : DWORD
    ctypes.POINTER(wintypes.DWORD),  # DoneBytes : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procRangeMapWrite = dbghelp.NewProc("RangeMapWrite")
)

// RmapHandle (void*), Offset (ULONGLONG), Buffer (void*), RequestBytes (DWORD), Flags (DWORD), DoneBytes (DWORD* optional, out)
r1, _, err := procRangeMapWrite.Call(
	uintptr(RmapHandle),
	uintptr(Offset),
	uintptr(Buffer),
	uintptr(RequestBytes),
	uintptr(Flags),
	uintptr(DoneBytes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function RangeMapWrite(
  RmapHandle: Pointer;   // void*
  Offset: UInt64;   // ULONGLONG
  Buffer: Pointer;   // void*
  RequestBytes: DWORD;   // DWORD
  Flags: DWORD;   // DWORD
  DoneBytes: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'dbghelp.dll' name 'RangeMapWrite';
result := DllCall("dbghelp\RangeMapWrite"
    , "Ptr", RmapHandle   ; void*
    , "Int64", Offset   ; ULONGLONG
    , "Ptr", Buffer   ; void*
    , "UInt", RequestBytes   ; DWORD
    , "UInt", Flags   ; DWORD
    , "Ptr", DoneBytes   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes) = DLL("dbghelp.dll", "bool RangeMapWrite(void*, qword, void*, dword, dword, void*)")
# 呼び出し: RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes)
# RmapHandle : void* -> "void*"
# Offset : ULONGLONG -> "qword"
# Buffer : void* -> "void*"
# RequestBytes : DWORD -> "dword"
# Flags : DWORD -> "dword"
# DoneBytes : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "dbghelp" fn RangeMapWrite(
    RmapHandle: ?*anyopaque, // void*
    Offset: u64, // ULONGLONG
    Buffer: ?*anyopaque, // void*
    RequestBytes: u32, // DWORD
    Flags: u32, // DWORD
    DoneBytes: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc RangeMapWrite(
    RmapHandle: pointer,  # void*
    Offset: uint64,  # ULONGLONG
    Buffer: pointer,  # void*
    RequestBytes: uint32,  # DWORD
    Flags: uint32,  # DWORD
    DoneBytes: ptr uint32  # DWORD* optional, out
): int32 {.importc: "RangeMapWrite", stdcall, dynlib: "dbghelp.dll".}
pragma(lib, "dbghelp");
extern(Windows)
int RangeMapWrite(
    void* RmapHandle,   // void*
    ulong Offset,   // ULONGLONG
    void* Buffer,   // void*
    uint RequestBytes,   // DWORD
    uint Flags,   // DWORD
    uint* DoneBytes   // DWORD* optional, out
);
ccall((:RangeMapWrite, "dbghelp.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt64, Ptr{Cvoid}, UInt32, UInt32, Ptr{UInt32}),
      RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes)
# RmapHandle : void* -> Ptr{Cvoid}
# Offset : ULONGLONG -> UInt64
# Buffer : void* -> Ptr{Cvoid}
# RequestBytes : DWORD -> UInt32
# Flags : DWORD -> UInt32
# DoneBytes : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RangeMapWrite(
    void* RmapHandle,
    uint64_t Offset,
    void* Buffer,
    uint32_t RequestBytes,
    uint32_t Flags,
    uint32_t* DoneBytes);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes)
-- RmapHandle : void*
-- Offset : ULONGLONG
-- Buffer : void*
-- RequestBytes : DWORD
-- Flags : DWORD
-- DoneBytes : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const RangeMapWrite = lib.func('__stdcall', 'RangeMapWrite', 'int32_t', ['void *', 'uint64_t', 'void *', 'uint32_t', 'uint32_t', 'uint32_t *']);
// RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes)
// RmapHandle : void* -> 'void *'
// Offset : ULONGLONG -> 'uint64_t'
// Buffer : void* -> 'void *'
// RequestBytes : DWORD -> 'uint32_t'
// Flags : DWORD -> 'uint32_t'
// DoneBytes : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  RangeMapWrite: { parameters: ["pointer", "u64", "pointer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes)
// RmapHandle : void* -> "pointer"
// Offset : ULONGLONG -> "u64"
// Buffer : void* -> "pointer"
// RequestBytes : DWORD -> "u32"
// Flags : DWORD -> "u32"
// DoneBytes : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RangeMapWrite(
    void* RmapHandle,
    uint64_t Offset,
    void* Buffer,
    uint32_t RequestBytes,
    uint32_t Flags,
    uint32_t* DoneBytes);
C, "dbghelp.dll");
// $ffi->RangeMapWrite(RmapHandle, Offset, Buffer, RequestBytes, Flags, DoneBytes);
// RmapHandle : void*
// Offset : ULONGLONG
// Buffer : void*
// RequestBytes : DWORD
// Flags : DWORD
// DoneBytes : 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 Dbghelp extends StdCallLibrary {
    Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class);
    boolean RangeMapWrite(
        Pointer RmapHandle,   // void*
        long Offset,   // ULONGLONG
        Pointer Buffer,   // void*
        int RequestBytes,   // DWORD
        int Flags,   // DWORD
        IntByReference DoneBytes   // DWORD* optional, out
    );
}
@[Link("dbghelp")]
lib Libdbghelp
  fun RangeMapWrite = RangeMapWrite(
    RmapHandle : Void*,   # void*
    Offset : UInt64,   # ULONGLONG
    Buffer : Void*,   # void*
    RequestBytes : UInt32,   # DWORD
    Flags : UInt32,   # DWORD
    DoneBytes : 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 RangeMapWriteNative = Int32 Function(Pointer<Void>, Uint64, Pointer<Void>, Uint32, Uint32, Pointer<Uint32>);
typedef RangeMapWriteDart = int Function(Pointer<Void>, int, Pointer<Void>, int, int, Pointer<Uint32>);
final RangeMapWrite = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<RangeMapWriteNative, RangeMapWriteDart>('RangeMapWrite');
// RmapHandle : void* -> Pointer<Void>
// Offset : ULONGLONG -> Uint64
// Buffer : void* -> Pointer<Void>
// RequestBytes : DWORD -> Uint32
// Flags : DWORD -> Uint32
// DoneBytes : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RangeMapWrite(
  RmapHandle: Pointer;   // void*
  Offset: UInt64;   // ULONGLONG
  Buffer: Pointer;   // void*
  RequestBytes: DWORD;   // DWORD
  Flags: DWORD;   // DWORD
  DoneBytes: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'dbghelp.dll' name 'RangeMapWrite';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RangeMapWrite"
  c_RangeMapWrite :: Ptr () -> Word64 -> Ptr () -> Word32 -> Word32 -> Ptr Word32 -> IO CInt
-- RmapHandle : void* -> Ptr ()
-- Offset : ULONGLONG -> Word64
-- Buffer : void* -> Ptr ()
-- RequestBytes : DWORD -> Word32
-- Flags : DWORD -> Word32
-- DoneBytes : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rangemapwrite =
  foreign "RangeMapWrite"
    ((ptr void) @-> uint64_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* RmapHandle : void* -> (ptr void) *)
(* Offset : ULONGLONG -> uint64_t *)
(* Buffer : void* -> (ptr void) *)
(* RequestBytes : DWORD -> uint32_t *)
(* Flags : DWORD -> uint32_t *)
(* DoneBytes : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("RangeMapWrite" range-map-write :convention :stdcall) :int32
  (rmap-handle :pointer)   ; void*
  (offset :uint64)   ; ULONGLONG
  (buffer :pointer)   ; void*
  (request-bytes :uint32)   ; DWORD
  (flags :uint32)   ; DWORD
  (done-bytes :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RangeMapWrite = Win32::API::More->new('dbghelp',
    'BOOL RangeMapWrite(LPVOID RmapHandle, UINT64 Offset, LPVOID Buffer, DWORD RequestBytes, DWORD Flags, LPVOID DoneBytes)');
# my $ret = $RangeMapWrite->Call($RmapHandle, $Offset, $Buffer, $RequestBytes, $Flags, $DoneBytes);
# RmapHandle : void* -> LPVOID
# Offset : ULONGLONG -> UINT64
# Buffer : void* -> LPVOID
# RequestBytes : DWORD -> DWORD
# Flags : DWORD -> DWORD
# DoneBytes : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。