Win32 API 日本語リファレンス
ホームSystem.Memory.NonVolatile › RtlWriteNonVolatileMemory

RtlWriteNonVolatileMemory

関数
ソースから不揮発性メモリへデータを書き込む。
DLLntdll.dll呼出規約winapi

シグネチャ

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

DWORD RtlWriteNonVolatileMemory(
    void* NvToken,
    void* NvDestination,
    const void* Source,
    UINT_PTR Size,
    DWORD Flags
);

パラメーター

名前方向
NvTokenvoid*in
NvDestinationvoid*out
Sourcevoid*in
SizeUINT_PTRin
FlagsDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RtlWriteNonVolatileMemory(
    void* NvToken,
    void* NvDestination,
    const void* Source,
    UINT_PTR Size,
    DWORD Flags
);
[DllImport("ntdll.dll", ExactSpelling = true)]
static extern uint RtlWriteNonVolatileMemory(
    IntPtr NvToken,   // void*
    IntPtr NvDestination,   // void* out
    IntPtr Source,   // void*
    UIntPtr Size,   // UINT_PTR
    uint Flags   // DWORD
);
<DllImport("ntdll.dll", ExactSpelling:=True)>
Public Shared Function RtlWriteNonVolatileMemory(
    NvToken As IntPtr,   ' void*
    NvDestination As IntPtr,   ' void* out
    Source As IntPtr,   ' void*
    Size As UIntPtr,   ' UINT_PTR
    Flags As UInteger   ' DWORD
) As UInteger
End Function
' NvToken : void*
' NvDestination : void* out
' Source : void*
' Size : UINT_PTR
' Flags : DWORD
Declare PtrSafe Function RtlWriteNonVolatileMemory Lib "ntdll" ( _
    ByVal NvToken As LongPtr, _
    ByVal NvDestination As LongPtr, _
    ByVal Source As LongPtr, _
    ByVal Size As LongPtr, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlWriteNonVolatileMemory = ctypes.windll.ntdll.RtlWriteNonVolatileMemory
RtlWriteNonVolatileMemory.restype = wintypes.DWORD
RtlWriteNonVolatileMemory.argtypes = [
    ctypes.POINTER(None),  # NvToken : void*
    ctypes.POINTER(None),  # NvDestination : void* out
    ctypes.POINTER(None),  # Source : void*
    ctypes.c_size_t,  # Size : UINT_PTR
    wintypes.DWORD,  # Flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ntdll.dll')
RtlWriteNonVolatileMemory = Fiddle::Function.new(
  lib['RtlWriteNonVolatileMemory'],
  [
    Fiddle::TYPE_VOIDP,  # NvToken : void*
    Fiddle::TYPE_VOIDP,  # NvDestination : void* out
    Fiddle::TYPE_VOIDP,  # Source : void*
    Fiddle::TYPE_UINTPTR_T,  # Size : UINT_PTR
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "ntdll")]
extern "system" {
    fn RtlWriteNonVolatileMemory(
        NvToken: *mut (),  // void*
        NvDestination: *mut (),  // void* out
        Source: *const (),  // void*
        Size: usize,  // UINT_PTR
        Flags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ntdll.dll")]
public static extern uint RtlWriteNonVolatileMemory(IntPtr NvToken, IntPtr NvDestination, IntPtr Source, UIntPtr Size, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ntdll_RtlWriteNonVolatileMemory' -Namespace Win32 -PassThru
# $api::RtlWriteNonVolatileMemory(NvToken, NvDestination, Source, Size, Flags)
#uselib "ntdll.dll"
#func global RtlWriteNonVolatileMemory "RtlWriteNonVolatileMemory" sptr, sptr, sptr, sptr, sptr
; RtlWriteNonVolatileMemory NvToken, NvDestination, Source, Size, Flags   ; 戻り値は stat
; NvToken : void* -> "sptr"
; NvDestination : void* out -> "sptr"
; Source : void* -> "sptr"
; Size : UINT_PTR -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ntdll.dll"
#cfunc global RtlWriteNonVolatileMemory "RtlWriteNonVolatileMemory" sptr, sptr, sptr, sptr, int
; res = RtlWriteNonVolatileMemory(NvToken, NvDestination, Source, Size, Flags)
; NvToken : void* -> "sptr"
; NvDestination : void* out -> "sptr"
; Source : void* -> "sptr"
; Size : UINT_PTR -> "sptr"
; Flags : DWORD -> "int"
; DWORD RtlWriteNonVolatileMemory(void* NvToken, void* NvDestination, void* Source, UINT_PTR Size, DWORD Flags)
#uselib "ntdll.dll"
#cfunc global RtlWriteNonVolatileMemory "RtlWriteNonVolatileMemory" intptr, intptr, intptr, intptr, int
; res = RtlWriteNonVolatileMemory(NvToken, NvDestination, Source, Size, Flags)
; NvToken : void* -> "intptr"
; NvDestination : void* out -> "intptr"
; Source : void* -> "intptr"
; Size : UINT_PTR -> "intptr"
; Flags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdll = windows.NewLazySystemDLL("ntdll.dll")
	procRtlWriteNonVolatileMemory = ntdll.NewProc("RtlWriteNonVolatileMemory")
)

// NvToken (void*), NvDestination (void* out), Source (void*), Size (UINT_PTR), Flags (DWORD)
r1, _, err := procRtlWriteNonVolatileMemory.Call(
	uintptr(NvToken),
	uintptr(NvDestination),
	uintptr(Source),
	uintptr(Size),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RtlWriteNonVolatileMemory(
  NvToken: Pointer;   // void*
  NvDestination: Pointer;   // void* out
  Source: Pointer;   // void*
  Size: NativeUInt;   // UINT_PTR
  Flags: DWORD   // DWORD
): DWORD; stdcall;
  external 'ntdll.dll' name 'RtlWriteNonVolatileMemory';
result := DllCall("ntdll\RtlWriteNonVolatileMemory"
    , "Ptr", NvToken   ; void*
    , "Ptr", NvDestination   ; void* out
    , "Ptr", Source   ; void*
    , "UPtr", Size   ; UINT_PTR
    , "UInt", Flags   ; DWORD
    , "UInt")   ; return: DWORD
●RtlWriteNonVolatileMemory(NvToken, NvDestination, Source, Size, Flags) = DLL("ntdll.dll", "dword RtlWriteNonVolatileMemory(void*, void*, void*, int, dword)")
# 呼び出し: RtlWriteNonVolatileMemory(NvToken, NvDestination, Source, Size, Flags)
# NvToken : void* -> "void*"
# NvDestination : void* out -> "void*"
# Source : void* -> "void*"
# Size : UINT_PTR -> "int"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。