ホーム › System.Memory › VirtualUnlockEx
VirtualUnlockEx
関数指定プロセスのロックされたメモリ範囲のロックを解除する。
シグネチャ
// api-ms-win-core-memory-l1-1-5.dll
#include <windows.h>
BOOL VirtualUnlockEx(
HANDLE Process, // optional
void* Address,
UINT_PTR Size
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Process | HANDLE | inoptional | ロックを解除する対象プロセスのハンドル。 |
| Address | void* | in | ロックを解除する領域の開始アドレス。 |
| Size | UINT_PTR | in | ロックを解除する領域のバイト数。 |
戻り値の型: BOOL
各言語での呼び出し定義
// api-ms-win-core-memory-l1-1-5.dll
#include <windows.h>
BOOL VirtualUnlockEx(
HANDLE Process, // optional
void* Address,
UINT_PTR Size
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-memory-l1-1-5.dll", ExactSpelling = true)]
static extern bool VirtualUnlockEx(
IntPtr Process, // HANDLE optional
IntPtr Address, // void*
UIntPtr Size // UINT_PTR
);<DllImport("api-ms-win-core-memory-l1-1-5.dll", ExactSpelling:=True)>
Public Shared Function VirtualUnlockEx(
Process As IntPtr, ' HANDLE optional
Address As IntPtr, ' void*
Size As UIntPtr ' UINT_PTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Process : HANDLE optional
' Address : void*
' Size : UINT_PTR
Declare PtrSafe Function VirtualUnlockEx Lib "api-ms-win-core-memory-l1-1-5" ( _
ByVal Process As LongPtr, _
ByVal Address As LongPtr, _
ByVal Size As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VirtualUnlockEx = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-5.dll").VirtualUnlockEx
VirtualUnlockEx.restype = wintypes.BOOL
VirtualUnlockEx.argtypes = [
wintypes.HANDLE, # Process : HANDLE optional
ctypes.POINTER(None), # Address : void*
ctypes.c_size_t, # Size : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-memory-l1-1-5.dll')
VirtualUnlockEx = Fiddle::Function.new(
lib['VirtualUnlockEx'],
[
Fiddle::TYPE_VOIDP, # Process : HANDLE optional
Fiddle::TYPE_VOIDP, # Address : void*
Fiddle::TYPE_UINTPTR_T, # Size : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-memory-l1-1-5")]
extern "system" {
fn VirtualUnlockEx(
Process: *mut core::ffi::c_void, // HANDLE optional
Address: *mut (), // void*
Size: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-memory-l1-1-5.dll")]
public static extern bool VirtualUnlockEx(IntPtr Process, IntPtr Address, UIntPtr Size);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-5_VirtualUnlockEx' -Namespace Win32 -PassThru
# $api::VirtualUnlockEx(Process, Address, Size)#uselib "api-ms-win-core-memory-l1-1-5.dll"
#func global VirtualUnlockEx "VirtualUnlockEx" sptr, sptr, sptr
; VirtualUnlockEx Process, Address, Size ; 戻り値は stat
; Process : HANDLE optional -> "sptr"
; Address : void* -> "sptr"
; Size : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-memory-l1-1-5.dll"
#cfunc global VirtualUnlockEx "VirtualUnlockEx" sptr, sptr, sptr
; res = VirtualUnlockEx(Process, Address, Size)
; Process : HANDLE optional -> "sptr"
; Address : void* -> "sptr"
; Size : UINT_PTR -> "sptr"; BOOL VirtualUnlockEx(HANDLE Process, void* Address, UINT_PTR Size)
#uselib "api-ms-win-core-memory-l1-1-5.dll"
#cfunc global VirtualUnlockEx "VirtualUnlockEx" intptr, intptr, intptr
; res = VirtualUnlockEx(Process, Address, Size)
; Process : HANDLE optional -> "intptr"
; Address : void* -> "intptr"
; Size : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_memory_l1_1_5 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-5.dll")
procVirtualUnlockEx = api_ms_win_core_memory_l1_1_5.NewProc("VirtualUnlockEx")
)
// Process (HANDLE optional), Address (void*), Size (UINT_PTR)
r1, _, err := procVirtualUnlockEx.Call(
uintptr(Process),
uintptr(Address),
uintptr(Size),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction VirtualUnlockEx(
Process: THandle; // HANDLE optional
Address: Pointer; // void*
Size: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'api-ms-win-core-memory-l1-1-5.dll' name 'VirtualUnlockEx';result := DllCall("api-ms-win-core-memory-l1-1-5\VirtualUnlockEx"
, "Ptr", Process ; HANDLE optional
, "Ptr", Address ; void*
, "UPtr", Size ; UINT_PTR
, "Int") ; return: BOOL●VirtualUnlockEx(Process, Address, Size) = DLL("api-ms-win-core-memory-l1-1-5.dll", "bool VirtualUnlockEx(void*, void*, int)")
# 呼び出し: VirtualUnlockEx(Process, Address, Size)
# Process : HANDLE optional -> "void*"
# Address : void* -> "void*"
# Size : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-memory-l1-1-5" fn VirtualUnlockEx(
Process: ?*anyopaque, // HANDLE optional
Address: ?*anyopaque, // void*
Size: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;proc VirtualUnlockEx(
Process: pointer, # HANDLE optional
Address: pointer, # void*
Size: uint # UINT_PTR
): int32 {.importc: "VirtualUnlockEx", stdcall, dynlib: "api-ms-win-core-memory-l1-1-5.dll".}pragma(lib, "api-ms-win-core-memory-l1-1-5");
extern(Windows)
int VirtualUnlockEx(
void* Process, // HANDLE optional
void* Address, // void*
size_t Size // UINT_PTR
);ccall((:VirtualUnlockEx, "api-ms-win-core-memory-l1-1-5.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t),
Process, Address, Size)
# Process : HANDLE optional -> Ptr{Cvoid}
# Address : void* -> Ptr{Cvoid}
# Size : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t VirtualUnlockEx(
void* Process,
void* Address,
uintptr_t Size);
]]
local api-ms-win-core-memory-l1-1-5 = ffi.load("api-ms-win-core-memory-l1-1-5")
-- api-ms-win-core-memory-l1-1-5.VirtualUnlockEx(Process, Address, Size)
-- Process : HANDLE optional
-- Address : void*
-- Size : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-memory-l1-1-5.dll');
const VirtualUnlockEx = lib.func('__stdcall', 'VirtualUnlockEx', 'int32_t', ['void *', 'void *', 'uintptr_t']);
// VirtualUnlockEx(Process, Address, Size)
// Process : HANDLE optional -> 'void *'
// Address : void* -> 'void *'
// Size : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-memory-l1-1-5.dll", {
VirtualUnlockEx: { parameters: ["pointer", "pointer", "usize"], result: "i32" },
});
// lib.symbols.VirtualUnlockEx(Process, Address, Size)
// Process : HANDLE optional -> "pointer"
// Address : void* -> "pointer"
// Size : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t VirtualUnlockEx(
void* Process,
void* Address,
size_t Size);
C, "api-ms-win-core-memory-l1-1-5.dll");
// $ffi->VirtualUnlockEx(Process, Address, Size);
// Process : HANDLE optional
// Address : void*
// Size : UINT_PTR
// 構造体/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 Api-ms-win-core-memory-l1-1-5 extends StdCallLibrary {
Api-ms-win-core-memory-l1-1-5 INSTANCE = Native.load("api-ms-win-core-memory-l1-1-5", Api-ms-win-core-memory-l1-1-5.class);
boolean VirtualUnlockEx(
Pointer Process, // HANDLE optional
Pointer Address, // void*
long Size // UINT_PTR
);
}@[Link("api-ms-win-core-memory-l1-1-5")]
lib Libapi-ms-win-core-memory-l1-1-5
fun VirtualUnlockEx = VirtualUnlockEx(
Process : Void*, # HANDLE optional
Address : Void*, # void*
Size : LibC::SizeT # UINT_PTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef VirtualUnlockExNative = Int32 Function(Pointer<Void>, Pointer<Void>, UintPtr);
typedef VirtualUnlockExDart = int Function(Pointer<Void>, Pointer<Void>, int);
final VirtualUnlockEx = DynamicLibrary.open('api-ms-win-core-memory-l1-1-5.dll')
.lookupFunction<VirtualUnlockExNative, VirtualUnlockExDart>('VirtualUnlockEx');
// Process : HANDLE optional -> Pointer<Void>
// Address : void* -> Pointer<Void>
// Size : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function VirtualUnlockEx(
Process: THandle; // HANDLE optional
Address: Pointer; // void*
Size: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'api-ms-win-core-memory-l1-1-5.dll' name 'VirtualUnlockEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "VirtualUnlockEx"
c_VirtualUnlockEx :: Ptr () -> Ptr () -> CUIntPtr -> IO CInt
-- Process : HANDLE optional -> Ptr ()
-- Address : void* -> Ptr ()
-- Size : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let virtualunlockex =
foreign "VirtualUnlockEx"
((ptr void) @-> (ptr void) @-> size_t @-> returning int32_t)
(* Process : HANDLE optional -> (ptr void) *)
(* Address : void* -> (ptr void) *)
(* Size : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-memory-l1-1-5 (t "api-ms-win-core-memory-l1-1-5.dll"))
(cffi:use-foreign-library api-ms-win-core-memory-l1-1-5)
(cffi:defcfun ("VirtualUnlockEx" virtual-unlock-ex :convention :stdcall) :int32
(process :pointer) ; HANDLE optional
(address :pointer) ; void*
(size :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $VirtualUnlockEx = Win32::API::More->new('api-ms-win-core-memory-l1-1-5',
'BOOL VirtualUnlockEx(HANDLE Process, LPVOID Address, WPARAM Size)');
# my $ret = $VirtualUnlockEx->Call($Process, $Address, $Size);
# Process : HANDLE optional -> HANDLE
# Address : void* -> LPVOID
# Size : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f VirtualUnlock — VirtualLockでロックした範囲のメモリのロックを解除する。