MapViewOfFile3FromApp
関数シグネチャ
// api-ms-win-core-memory-l1-1-6.dll
#include <windows.h>
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
HANDLE FileMapping,
HANDLE Process, // optional
void* BaseAddress, // optional
ULONGLONG Offset,
UINT_PTR ViewSize,
VIRTUAL_ALLOCATION_TYPE AllocationType,
DWORD PageProtection,
MEM_EXTENDED_PARAMETER* ExtendedParameters, // optional
DWORD ParameterCount
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| FileMapping | HANDLE | in | 指定したプロセスのアドレス空間にマップされるセクションへの HANDLE。 | ||||||||
| Process | HANDLE | inoptional | セクションのマップ先となるプロセスへの HANDLE。 | ||||||||
| BaseAddress | void* | inoptional | ビューの希望するベースアドレス。 アドレスは直近の 64k 境界へ切り下げられます。
BaseAddress が NULL でない場合、 指定する MEM_ADDRESS_REQUIREMENTS 構造体はすべてゼロでなければなりません。 | ||||||||
| Offset | ULONGLONG | in | セクションの先頭からのオフセット。 64k 境界に整列している必要があります。 | ||||||||
| ViewSize | UINT_PTR | in | マップするバイト数。0 を指定すると セクション全体がマップされます。 サイズは常にページサイズの倍数である必要があります。 | ||||||||
| AllocationType | VIRTUAL_ALLOCATION_TYPE | in | メモリ割り当ての種類。このパラメーターには 0、または次のいずれかの値を指定できます。
| ||||||||
| PageProtection | DWORD | in | 希望するページ保護。 SEC_IMAGE 属性で作成されたファイルマッピングオブジェクトでは、 PageProtection パラメーターは効果を持たず、 PAGE_READONLY などの任意の有効な値を設定してください。 | ||||||||
| ExtendedParameters | MEM_EXTENDED_PARAMETER* | inoutoptional | MEM_EXTENDED_PARAMETER 型の 1 つ以上の拡張パラメーターへの省略可能なポインター。これらの各拡張パラメーター値は、それ自身が MemExtendedParameterAddressRequirements または MemExtendedParameterNumaNode のいずれかの Type フィールドを持つことができます。MemExtendedParameterNumaNode 拡張パラメーターが指定されない場合の動作は、VirtualAlloc/MapViewOfFile 関数の場合と同じです(つまり、物理ページの優先 NUMA ノードは、そのメモリに最初にアクセスするスレッドの理想プロセッサーに基づいて決定されます)。 | ||||||||
| ParameterCount | DWORD | in | ExtendedParameters が指す拡張パラメーターの数。 |
戻り値の型: MEMORY_MAPPED_VIEW_ADDRESS
公式ドキュメント
ファイルマッピングのビューを、呼び出し元の Windows ストアアプリのアドレス空間にマップします。(MapViewOfFile3FromApp)
戻り値
成功した場合、マップされたビューのベースアドレスを返します。それ以外の場合は NULL を返し、拡張エラー情報は GetLastError を使用して取得できます。
解説(Remarks)
この API は、仮想アドレス空間の管理に特有の要件を持つ高パフォーマンスのゲームやサーバーアプリケーションのサポートに役立ちます。たとえば、以前に予約した領域の上にメモリをマップすることができます。これは自動的にラップするリングバッファーの実装に有用です。また、特定の整列でメモリを割り当てることもできます。たとえば、アプリケーションがラージページ/ヒュージページにマップされた領域をオンデマンドでコミットできるようにするためです。
1 つの重要な例外を除き、同じファイルにバックされた任意のファイルマッピングオブジェクトから派生したファイルビューは、特定の時点においてコヒーレント(一貫)または同一です。コヒーレンシーは、プロセス内のビューおよび 異なるプロセスによってマップされたビューについて保証されます。
その例外はリモートファイルに関連します。 MapViewOfFile3FromApp はリモートファイルでも動作しますが、 それらのコヒーレンシーは維持しません。たとえば、2 台のコンピューターがどちらもファイルを書き込み可能としてマップし、両方が同じ ページを変更した場合、各コンピューターはそのページに対する自身の書き込みのみを参照します。データがディスク上で更新されるとき、それは マージされません。
実行可能保護を正常に要求できるのは、アプリが codeGeneration 機能を持っている場合のみです。
例
コード例については、Virtual2Alloc のシナリオ 1 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-core-memory-l1-1-6.dll
#include <windows.h>
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
HANDLE FileMapping,
HANDLE Process, // optional
void* BaseAddress, // optional
ULONGLONG Offset,
UINT_PTR ViewSize,
VIRTUAL_ALLOCATION_TYPE AllocationType,
DWORD PageProtection,
MEM_EXTENDED_PARAMETER* ExtendedParameters, // optional
DWORD ParameterCount
);[DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError = true, ExactSpelling = true)]
static extern MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
IntPtr FileMapping, // HANDLE
IntPtr Process, // HANDLE optional
IntPtr BaseAddress, // void* optional
ulong Offset, // ULONGLONG
UIntPtr ViewSize, // UINT_PTR
uint AllocationType, // VIRTUAL_ALLOCATION_TYPE
uint PageProtection, // DWORD
IntPtr ExtendedParameters, // MEM_EXTENDED_PARAMETER* optional, in/out
uint ParameterCount // DWORD
);<DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MapViewOfFile3FromApp(
FileMapping As IntPtr, ' HANDLE
Process As IntPtr, ' HANDLE optional
BaseAddress As IntPtr, ' void* optional
Offset As ULong, ' ULONGLONG
ViewSize As UIntPtr, ' UINT_PTR
AllocationType As UInteger, ' VIRTUAL_ALLOCATION_TYPE
PageProtection As UInteger, ' DWORD
ExtendedParameters As IntPtr, ' MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount As UInteger ' DWORD
) As MEMORY_MAPPED_VIEW_ADDRESS
End Function' FileMapping : HANDLE
' Process : HANDLE optional
' BaseAddress : void* optional
' Offset : ULONGLONG
' ViewSize : UINT_PTR
' AllocationType : VIRTUAL_ALLOCATION_TYPE
' PageProtection : DWORD
' ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
' ParameterCount : DWORD
Declare PtrSafe Function MapViewOfFile3FromApp Lib "api-ms-win-core-memory-l1-1-6" ( _
ByVal FileMapping As LongPtr, _
ByVal Process As LongPtr, _
ByVal BaseAddress As LongPtr, _
ByVal Offset As LongLong, _
ByVal ViewSize As LongPtr, _
ByVal AllocationType As Long, _
ByVal PageProtection As Long, _
ByVal ExtendedParameters As LongPtr, _
ByVal ParameterCount As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MapViewOfFile3FromApp = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-6.dll").MapViewOfFile3FromApp
MapViewOfFile3FromApp.restype = ctypes.c_void_p
MapViewOfFile3FromApp.argtypes = [
wintypes.HANDLE, # FileMapping : HANDLE
wintypes.HANDLE, # Process : HANDLE optional
ctypes.POINTER(None), # BaseAddress : void* optional
ctypes.c_ulonglong, # Offset : ULONGLONG
ctypes.c_size_t, # ViewSize : UINT_PTR
wintypes.DWORD, # AllocationType : VIRTUAL_ALLOCATION_TYPE
wintypes.DWORD, # PageProtection : DWORD
ctypes.c_void_p, # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
wintypes.DWORD, # ParameterCount : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-memory-l1-1-6.dll')
MapViewOfFile3FromApp = Fiddle::Function.new(
lib['MapViewOfFile3FromApp'],
[
Fiddle::TYPE_VOIDP, # FileMapping : HANDLE
Fiddle::TYPE_VOIDP, # Process : HANDLE optional
Fiddle::TYPE_VOIDP, # BaseAddress : void* optional
-Fiddle::TYPE_LONG_LONG, # Offset : ULONGLONG
Fiddle::TYPE_UINTPTR_T, # ViewSize : UINT_PTR
-Fiddle::TYPE_INT, # AllocationType : VIRTUAL_ALLOCATION_TYPE
-Fiddle::TYPE_INT, # PageProtection : DWORD
Fiddle::TYPE_VOIDP, # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
-Fiddle::TYPE_INT, # ParameterCount : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "api-ms-win-core-memory-l1-1-6")]
extern "system" {
fn MapViewOfFile3FromApp(
FileMapping: *mut core::ffi::c_void, // HANDLE
Process: *mut core::ffi::c_void, // HANDLE optional
BaseAddress: *mut (), // void* optional
Offset: u64, // ULONGLONG
ViewSize: usize, // UINT_PTR
AllocationType: u32, // VIRTUAL_ALLOCATION_TYPE
PageProtection: u32, // DWORD
ExtendedParameters: *mut MEM_EXTENDED_PARAMETER, // MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: u32 // DWORD
) -> MEMORY_MAPPED_VIEW_ADDRESS;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError = true)]
public static extern MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(IntPtr FileMapping, IntPtr Process, IntPtr BaseAddress, ulong Offset, UIntPtr ViewSize, uint AllocationType, uint PageProtection, IntPtr ExtendedParameters, uint ParameterCount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-6_MapViewOfFile3FromApp' -Namespace Win32 -PassThru
# $api::MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)#uselib "api-ms-win-core-memory-l1-1-6.dll"
#func global MapViewOfFile3FromApp "MapViewOfFile3FromApp" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MapViewOfFile3FromApp FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, varptr(ExtendedParameters), ParameterCount ; 戻り値は stat
; FileMapping : HANDLE -> "sptr"
; Process : HANDLE optional -> "sptr"
; BaseAddress : void* optional -> "sptr"
; Offset : ULONGLONG -> "sptr"
; ViewSize : UINT_PTR -> "sptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "sptr"
; PageProtection : DWORD -> "sptr"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "sptr"
; ParameterCount : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-memory-l1-1-6.dll" #cfunc global MapViewOfFile3FromApp "MapViewOfFile3FromApp" sptr, sptr, sptr, int64, sptr, int, int, var, int ; res = MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount) ; FileMapping : HANDLE -> "sptr" ; Process : HANDLE optional -> "sptr" ; BaseAddress : void* optional -> "sptr" ; Offset : ULONGLONG -> "int64" ; ViewSize : UINT_PTR -> "sptr" ; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int" ; PageProtection : DWORD -> "int" ; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "api-ms-win-core-memory-l1-1-6.dll" #cfunc global MapViewOfFile3FromApp "MapViewOfFile3FromApp" sptr, sptr, sptr, int64, sptr, int, int, sptr, int ; res = MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, varptr(ExtendedParameters), ParameterCount) ; FileMapping : HANDLE -> "sptr" ; Process : HANDLE optional -> "sptr" ; BaseAddress : void* optional -> "sptr" ; Offset : ULONGLONG -> "int64" ; ViewSize : UINT_PTR -> "sptr" ; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int" ; PageProtection : DWORD -> "int" ; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "sptr" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(HANDLE FileMapping, HANDLE Process, void* BaseAddress, ULONGLONG Offset, UINT_PTR ViewSize, VIRTUAL_ALLOCATION_TYPE AllocationType, DWORD PageProtection, MEM_EXTENDED_PARAMETER* ExtendedParameters, DWORD ParameterCount) #uselib "api-ms-win-core-memory-l1-1-6.dll" #cfunc global MapViewOfFile3FromApp "MapViewOfFile3FromApp" intptr, intptr, intptr, int64, intptr, int, int, var, int ; res = MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount) ; FileMapping : HANDLE -> "intptr" ; Process : HANDLE optional -> "intptr" ; BaseAddress : void* optional -> "intptr" ; Offset : ULONGLONG -> "int64" ; ViewSize : UINT_PTR -> "intptr" ; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int" ; PageProtection : DWORD -> "int" ; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(HANDLE FileMapping, HANDLE Process, void* BaseAddress, ULONGLONG Offset, UINT_PTR ViewSize, VIRTUAL_ALLOCATION_TYPE AllocationType, DWORD PageProtection, MEM_EXTENDED_PARAMETER* ExtendedParameters, DWORD ParameterCount) #uselib "api-ms-win-core-memory-l1-1-6.dll" #cfunc global MapViewOfFile3FromApp "MapViewOfFile3FromApp" intptr, intptr, intptr, int64, intptr, int, int, intptr, int ; res = MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, varptr(ExtendedParameters), ParameterCount) ; FileMapping : HANDLE -> "intptr" ; Process : HANDLE optional -> "intptr" ; BaseAddress : void* optional -> "intptr" ; Offset : ULONGLONG -> "int64" ; ViewSize : UINT_PTR -> "intptr" ; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int" ; PageProtection : DWORD -> "int" ; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "intptr" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_memory_l1_1_6 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-6.dll")
procMapViewOfFile3FromApp = api_ms_win_core_memory_l1_1_6.NewProc("MapViewOfFile3FromApp")
)
// FileMapping (HANDLE), Process (HANDLE optional), BaseAddress (void* optional), Offset (ULONGLONG), ViewSize (UINT_PTR), AllocationType (VIRTUAL_ALLOCATION_TYPE), PageProtection (DWORD), ExtendedParameters (MEM_EXTENDED_PARAMETER* optional, in/out), ParameterCount (DWORD)
r1, _, err := procMapViewOfFile3FromApp.Call(
uintptr(FileMapping),
uintptr(Process),
uintptr(BaseAddress),
uintptr(Offset),
uintptr(ViewSize),
uintptr(AllocationType),
uintptr(PageProtection),
uintptr(ExtendedParameters),
uintptr(ParameterCount),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // MEMORY_MAPPED_VIEW_ADDRESSfunction MapViewOfFile3FromApp(
FileMapping: THandle; // HANDLE
Process: THandle; // HANDLE optional
BaseAddress: Pointer; // void* optional
Offset: UInt64; // ULONGLONG
ViewSize: NativeUInt; // UINT_PTR
AllocationType: DWORD; // VIRTUAL_ALLOCATION_TYPE
PageProtection: DWORD; // DWORD
ExtendedParameters: Pointer; // MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: DWORD // DWORD
): MEMORY_MAPPED_VIEW_ADDRESS; stdcall;
external 'api-ms-win-core-memory-l1-1-6.dll' name 'MapViewOfFile3FromApp';result := DllCall("api-ms-win-core-memory-l1-1-6\MapViewOfFile3FromApp"
, "Ptr", FileMapping ; HANDLE
, "Ptr", Process ; HANDLE optional
, "Ptr", BaseAddress ; void* optional
, "Int64", Offset ; ULONGLONG
, "UPtr", ViewSize ; UINT_PTR
, "UInt", AllocationType ; VIRTUAL_ALLOCATION_TYPE
, "UInt", PageProtection ; DWORD
, "Ptr", ExtendedParameters ; MEM_EXTENDED_PARAMETER* optional, in/out
, "UInt", ParameterCount ; DWORD
, "Ptr") ; return: MEMORY_MAPPED_VIEW_ADDRESS●MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount) = DLL("api-ms-win-core-memory-l1-1-6.dll", "void* MapViewOfFile3FromApp(void*, void*, void*, qword, int, dword, dword, void*, dword)")
# 呼び出し: MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
# FileMapping : HANDLE -> "void*"
# Process : HANDLE optional -> "void*"
# BaseAddress : void* optional -> "void*"
# Offset : ULONGLONG -> "qword"
# ViewSize : UINT_PTR -> "int"
# AllocationType : VIRTUAL_ALLOCATION_TYPE -> "dword"
# PageProtection : DWORD -> "dword"
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "void*"
# ParameterCount : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-memory-l1-1-6" fn MapViewOfFile3FromApp(
FileMapping: ?*anyopaque, // HANDLE
Process: ?*anyopaque, // HANDLE optional
BaseAddress: ?*anyopaque, // void* optional
Offset: u64, // ULONGLONG
ViewSize: usize, // UINT_PTR
AllocationType: u32, // VIRTUAL_ALLOCATION_TYPE
PageProtection: u32, // DWORD
ExtendedParameters: [*c]MEM_EXTENDED_PARAMETER, // MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: u32 // DWORD
) callconv(std.os.windows.WINAPI) MEMORY_MAPPED_VIEW_ADDRESS;proc MapViewOfFile3FromApp(
FileMapping: pointer, # HANDLE
Process: pointer, # HANDLE optional
BaseAddress: pointer, # void* optional
Offset: uint64, # ULONGLONG
ViewSize: uint, # UINT_PTR
AllocationType: uint32, # VIRTUAL_ALLOCATION_TYPE
PageProtection: uint32, # DWORD
ExtendedParameters: ptr MEM_EXTENDED_PARAMETER, # MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: uint32 # DWORD
): MEMORY_MAPPED_VIEW_ADDRESS {.importc: "MapViewOfFile3FromApp", stdcall, dynlib: "api-ms-win-core-memory-l1-1-6.dll".}pragma(lib, "api-ms-win-core-memory-l1-1-6");
extern(Windows)
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
void* FileMapping, // HANDLE
void* Process, // HANDLE optional
void* BaseAddress, // void* optional
ulong Offset, // ULONGLONG
size_t ViewSize, // UINT_PTR
uint AllocationType, // VIRTUAL_ALLOCATION_TYPE
uint PageProtection, // DWORD
MEM_EXTENDED_PARAMETER* ExtendedParameters, // MEM_EXTENDED_PARAMETER* optional, in/out
uint ParameterCount // DWORD
);ccall((:MapViewOfFile3FromApp, "api-ms-win-core-memory-l1-1-6.dll"), stdcall, MEMORY_MAPPED_VIEW_ADDRESS,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, UInt64, Csize_t, UInt32, UInt32, Ptr{MEM_EXTENDED_PARAMETER}, UInt32),
FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
# FileMapping : HANDLE -> Ptr{Cvoid}
# Process : HANDLE optional -> Ptr{Cvoid}
# BaseAddress : void* optional -> Ptr{Cvoid}
# Offset : ULONGLONG -> UInt64
# ViewSize : UINT_PTR -> Csize_t
# AllocationType : VIRTUAL_ALLOCATION_TYPE -> UInt32
# PageProtection : DWORD -> UInt32
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Ptr{MEM_EXTENDED_PARAMETER}
# ParameterCount : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
void* FileMapping,
void* Process,
void* BaseAddress,
uint64_t Offset,
uintptr_t ViewSize,
uint32_t AllocationType,
uint32_t PageProtection,
void* ExtendedParameters,
uint32_t ParameterCount);
]]
local api-ms-win-core-memory-l1-1-6 = ffi.load("api-ms-win-core-memory-l1-1-6")
-- api-ms-win-core-memory-l1-1-6.MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
-- FileMapping : HANDLE
-- Process : HANDLE optional
-- BaseAddress : void* optional
-- Offset : ULONGLONG
-- ViewSize : UINT_PTR
-- AllocationType : VIRTUAL_ALLOCATION_TYPE
-- PageProtection : DWORD
-- ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
-- ParameterCount : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-memory-l1-1-6.dll');
const MapViewOfFile3FromApp = lib.func('__stdcall', 'MapViewOfFile3FromApp', 'MEMORY_MAPPED_VIEW_ADDRESS', ['void *', 'void *', 'void *', 'uint64_t', 'uintptr_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t']);
// MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
// FileMapping : HANDLE -> 'void *'
// Process : HANDLE optional -> 'void *'
// BaseAddress : void* optional -> 'void *'
// Offset : ULONGLONG -> 'uint64_t'
// ViewSize : UINT_PTR -> 'uintptr_t'
// AllocationType : VIRTUAL_ALLOCATION_TYPE -> 'uint32_t'
// PageProtection : DWORD -> 'uint32_t'
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> 'void *'
// ParameterCount : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-memory-l1-1-6.dll", {
MapViewOfFile3FromApp: { parameters: ["pointer", "pointer", "pointer", "u64", "usize", "u32", "u32", "pointer", "u32"], result: "pointer" },
});
// lib.symbols.MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
// FileMapping : HANDLE -> "pointer"
// Process : HANDLE optional -> "pointer"
// BaseAddress : void* optional -> "pointer"
// Offset : ULONGLONG -> "u64"
// ViewSize : UINT_PTR -> "usize"
// AllocationType : VIRTUAL_ALLOCATION_TYPE -> "u32"
// PageProtection : DWORD -> "u32"
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "pointer"
// ParameterCount : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
void* FileMapping,
void* Process,
void* BaseAddress,
uint64_t Offset,
size_t ViewSize,
uint32_t AllocationType,
uint32_t PageProtection,
void* ExtendedParameters,
uint32_t ParameterCount);
C, "api-ms-win-core-memory-l1-1-6.dll");
// $ffi->MapViewOfFile3FromApp(FileMapping, Process, BaseAddress, Offset, ViewSize, AllocationType, PageProtection, ExtendedParameters, ParameterCount);
// FileMapping : HANDLE
// Process : HANDLE optional
// BaseAddress : void* optional
// Offset : ULONGLONG
// ViewSize : UINT_PTR
// AllocationType : VIRTUAL_ALLOCATION_TYPE
// PageProtection : DWORD
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
// ParameterCount : DWORD
// 構造体/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-6 extends StdCallLibrary {
Api-ms-win-core-memory-l1-1-6 INSTANCE = Native.load("api-ms-win-core-memory-l1-1-6", Api-ms-win-core-memory-l1-1-6.class);
MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFile3FromApp(
Pointer FileMapping, // HANDLE
Pointer Process, // HANDLE optional
Pointer BaseAddress, // void* optional
long Offset, // ULONGLONG
long ViewSize, // UINT_PTR
int AllocationType, // VIRTUAL_ALLOCATION_TYPE
int PageProtection, // DWORD
Pointer ExtendedParameters, // MEM_EXTENDED_PARAMETER* optional, in/out
int ParameterCount // DWORD
);
}@[Link("api-ms-win-core-memory-l1-1-6")]
lib Libapi-ms-win-core-memory-l1-1-6
fun MapViewOfFile3FromApp = MapViewOfFile3FromApp(
FileMapping : Void*, # HANDLE
Process : Void*, # HANDLE optional
BaseAddress : Void*, # void* optional
Offset : UInt64, # ULONGLONG
ViewSize : LibC::SizeT, # UINT_PTR
AllocationType : UInt32, # VIRTUAL_ALLOCATION_TYPE
PageProtection : UInt32, # DWORD
ExtendedParameters : MEM_EXTENDED_PARAMETER*, # MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount : UInt32 # DWORD
) : MEMORY_MAPPED_VIEW_ADDRESS
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MapViewOfFile3FromAppNative = MEMORY_MAPPED_VIEW_ADDRESS Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint64, UintPtr, Uint32, Uint32, Pointer<Void>, Uint32);
typedef MapViewOfFile3FromAppDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, int, int, Pointer<Void>, int);
final MapViewOfFile3FromApp = DynamicLibrary.open('api-ms-win-core-memory-l1-1-6.dll')
.lookupFunction<MapViewOfFile3FromAppNative, MapViewOfFile3FromAppDart>('MapViewOfFile3FromApp');
// FileMapping : HANDLE -> Pointer<Void>
// Process : HANDLE optional -> Pointer<Void>
// BaseAddress : void* optional -> Pointer<Void>
// Offset : ULONGLONG -> Uint64
// ViewSize : UINT_PTR -> UintPtr
// AllocationType : VIRTUAL_ALLOCATION_TYPE -> Uint32
// PageProtection : DWORD -> Uint32
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Pointer<Void>
// ParameterCount : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MapViewOfFile3FromApp(
FileMapping: THandle; // HANDLE
Process: THandle; // HANDLE optional
BaseAddress: Pointer; // void* optional
Offset: UInt64; // ULONGLONG
ViewSize: NativeUInt; // UINT_PTR
AllocationType: DWORD; // VIRTUAL_ALLOCATION_TYPE
PageProtection: DWORD; // DWORD
ExtendedParameters: Pointer; // MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: DWORD // DWORD
): MEMORY_MAPPED_VIEW_ADDRESS; stdcall;
external 'api-ms-win-core-memory-l1-1-6.dll' name 'MapViewOfFile3FromApp';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MapViewOfFile3FromApp"
c_MapViewOfFile3FromApp :: Ptr () -> Ptr () -> Ptr () -> Word64 -> CUIntPtr -> Word32 -> Word32 -> Ptr () -> Word32 -> IO MEMORY_MAPPED_VIEW_ADDRESS
-- FileMapping : HANDLE -> Ptr ()
-- Process : HANDLE optional -> Ptr ()
-- BaseAddress : void* optional -> Ptr ()
-- Offset : ULONGLONG -> Word64
-- ViewSize : UINT_PTR -> CUIntPtr
-- AllocationType : VIRTUAL_ALLOCATION_TYPE -> Word32
-- PageProtection : DWORD -> Word32
-- ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Ptr ()
-- ParameterCount : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let mapviewoffile3fromapp =
foreign "MapViewOfFile3FromApp"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint64_t @-> size_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning MEMORY_MAPPED_VIEW_ADDRESS)
(* FileMapping : HANDLE -> (ptr void) *)
(* Process : HANDLE optional -> (ptr void) *)
(* BaseAddress : void* optional -> (ptr void) *)
(* Offset : ULONGLONG -> uint64_t *)
(* ViewSize : UINT_PTR -> size_t *)
(* AllocationType : VIRTUAL_ALLOCATION_TYPE -> uint32_t *)
(* PageProtection : DWORD -> uint32_t *)
(* ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> (ptr void) *)
(* ParameterCount : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-memory-l1-1-6 (t "api-ms-win-core-memory-l1-1-6.dll"))
(cffi:use-foreign-library api-ms-win-core-memory-l1-1-6)
(cffi:defcfun ("MapViewOfFile3FromApp" map-view-of-file3-from-app :convention :stdcall) (:struct memory-mapped-view-address)
(file-mapping :pointer) ; HANDLE
(process :pointer) ; HANDLE optional
(base-address :pointer) ; void* optional
(offset :uint64) ; ULONGLONG
(view-size :uint64) ; UINT_PTR
(allocation-type :uint32) ; VIRTUAL_ALLOCATION_TYPE
(page-protection :uint32) ; DWORD
(extended-parameters :pointer) ; MEM_EXTENDED_PARAMETER* optional, in/out
(parameter-count :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MapViewOfFile3FromApp = Win32::API::More->new('api-ms-win-core-memory-l1-1-6',
'LPVOID MapViewOfFile3FromApp(HANDLE FileMapping, HANDLE Process, LPVOID BaseAddress, UINT64 Offset, WPARAM ViewSize, DWORD AllocationType, DWORD PageProtection, LPVOID ExtendedParameters, DWORD ParameterCount)');
# my $ret = $MapViewOfFile3FromApp->Call($FileMapping, $Process, $BaseAddress, $Offset, $ViewSize, $AllocationType, $PageProtection, $ExtendedParameters, $ParameterCount);
# FileMapping : HANDLE -> HANDLE
# Process : HANDLE optional -> HANDLE
# BaseAddress : void* optional -> LPVOID
# Offset : ULONGLONG -> UINT64
# ViewSize : UINT_PTR -> WPARAM
# AllocationType : VIRTUAL_ALLOCATION_TYPE -> DWORD
# PageProtection : DWORD -> DWORD
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> LPVOID
# ParameterCount : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CreateFileMappingW — ファイルマッピングオブジェクトを作成または開く(Unicode版)。
- f DuplicateHandle — オブジェクトハンドルの複製を作成する。
- f GetSystemInfo — プロセッサや構成など現在のシステム情報を取得する。
- f MapViewOfFileEx — ベースアドレスを指定してファイルマッピングのビューをマップする。
- f OpenFileMappingW — 名前付きファイルマッピングオブジェクトを開く(Unicode版)。
- s SYSTEM_INFO
- f UnmapViewOfFile — マップされたファイルビューをプロセスのアドレス空間から解除する。