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

VirtualUnlock

関数
VirtualLockでロックした範囲のメモリのロックを解除する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL VirtualUnlock(
    void* lpAddress,
    UINT_PTR dwSize
);

パラメーター

名前方向
lpAddressvoid*in
dwSizeUINT_PTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL VirtualUnlock(
    void* lpAddress,
    UINT_PTR dwSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool VirtualUnlock(
    IntPtr lpAddress,   // void*
    UIntPtr dwSize   // UINT_PTR
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualUnlock(
    lpAddress As IntPtr,   ' void*
    dwSize As UIntPtr   ' UINT_PTR
) As Boolean
End Function
' lpAddress : void*
' dwSize : UINT_PTR
Declare PtrSafe Function VirtualUnlock 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

VirtualUnlock = ctypes.windll.kernel32.VirtualUnlock
VirtualUnlock.restype = wintypes.BOOL
VirtualUnlock.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')
VirtualUnlock = Fiddle::Function.new(
  lib['VirtualUnlock'],
  [
    Fiddle::TYPE_VOIDP,  # lpAddress : void*
    Fiddle::TYPE_UINTPTR_T,  # dwSize : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn VirtualUnlock(
        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 VirtualUnlock(IntPtr lpAddress, UIntPtr dwSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_VirtualUnlock' -Namespace Win32 -PassThru
# $api::VirtualUnlock(lpAddress, dwSize)
#uselib "KERNEL32.dll"
#func global VirtualUnlock "VirtualUnlock" sptr, sptr
; VirtualUnlock lpAddress, dwSize   ; 戻り値は stat
; lpAddress : void* -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global VirtualUnlock "VirtualUnlock" sptr, sptr
; res = VirtualUnlock(lpAddress, dwSize)
; lpAddress : void* -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; BOOL VirtualUnlock(void* lpAddress, UINT_PTR dwSize)
#uselib "KERNEL32.dll"
#cfunc global VirtualUnlock "VirtualUnlock" intptr, intptr
; res = VirtualUnlock(lpAddress, dwSize)
; lpAddress : void* -> "intptr"
; dwSize : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procVirtualUnlock = kernel32.NewProc("VirtualUnlock")
)

// lpAddress (void*), dwSize (UINT_PTR)
r1, _, err := procVirtualUnlock.Call(
	uintptr(lpAddress),
	uintptr(dwSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function VirtualUnlock(
  lpAddress: Pointer;   // void*
  dwSize: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'VirtualUnlock';
result := DllCall("KERNEL32\VirtualUnlock"
    , "Ptr", lpAddress   ; void*
    , "UPtr", dwSize   ; UINT_PTR
    , "Int")   ; return: BOOL
●VirtualUnlock(lpAddress, dwSize) = DLL("KERNEL32.dll", "bool VirtualUnlock(void*, int)")
# 呼び出し: VirtualUnlock(lpAddress, dwSize)
# lpAddress : void* -> "void*"
# dwSize : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。