ホーム › System.Memory › VirtualLock
VirtualLock
関数指定範囲のメモリを物理メモリにロックしページングを防ぐ。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL VirtualLock(
void* lpAddress,
UINT_PTR dwSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpAddress | void* | in |
| dwSize | UINT_PTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL VirtualLock(
void* lpAddress,
UINT_PTR dwSize
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool VirtualLock(
IntPtr lpAddress, // void*
UIntPtr dwSize // UINT_PTR
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualLock(
lpAddress As IntPtr, ' void*
dwSize As UIntPtr ' UINT_PTR
) As Boolean
End Function' lpAddress : void*
' dwSize : UINT_PTR
Declare PtrSafe Function VirtualLock Lib "kernel32" ( _
ByVal lpAddress As LongPtr, _
ByVal dwSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VirtualLock = ctypes.windll.kernel32.VirtualLock
VirtualLock.restype = wintypes.BOOL
VirtualLock.argtypes = [
ctypes.POINTER(None), # lpAddress : void*
ctypes.c_size_t, # dwSize : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
VirtualLock = Fiddle::Function.new(
lib['VirtualLock'],
[
Fiddle::TYPE_VOIDP, # lpAddress : void*
Fiddle::TYPE_UINTPTR_T, # dwSize : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn VirtualLock(
lpAddress: *mut (), // void*
dwSize: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool VirtualLock(IntPtr lpAddress, UIntPtr dwSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_VirtualLock' -Namespace Win32 -PassThru
# $api::VirtualLock(lpAddress, dwSize)#uselib "KERNEL32.dll"
#func global VirtualLock "VirtualLock" sptr, sptr
; VirtualLock lpAddress, dwSize ; 戻り値は stat
; lpAddress : void* -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global VirtualLock "VirtualLock" sptr, sptr
; res = VirtualLock(lpAddress, dwSize)
; lpAddress : void* -> "sptr"
; dwSize : UINT_PTR -> "sptr"; BOOL VirtualLock(void* lpAddress, UINT_PTR dwSize)
#uselib "KERNEL32.dll"
#cfunc global VirtualLock "VirtualLock" intptr, intptr
; res = VirtualLock(lpAddress, dwSize)
; lpAddress : void* -> "intptr"
; dwSize : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procVirtualLock = kernel32.NewProc("VirtualLock")
)
// lpAddress (void*), dwSize (UINT_PTR)
r1, _, err := procVirtualLock.Call(
uintptr(lpAddress),
uintptr(dwSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction VirtualLock(
lpAddress: Pointer; // void*
dwSize: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'VirtualLock';result := DllCall("KERNEL32\VirtualLock"
, "Ptr", lpAddress ; void*
, "UPtr", dwSize ; UINT_PTR
, "Int") ; return: BOOL●VirtualLock(lpAddress, dwSize) = DLL("KERNEL32.dll", "bool VirtualLock(void*, int)")
# 呼び出し: VirtualLock(lpAddress, dwSize)
# lpAddress : void* -> "void*"
# dwSize : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。