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

MapViewOfFileFromApp

関数
UWPアプリ向けにファイルマッピングのビューをマップする。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFileFromApp(
    HANDLE hFileMappingObject,
    FILE_MAP DesiredAccess,
    ULONGLONG FileOffset,
    UINT_PTR NumberOfBytesToMap
);

パラメーター

名前方向
hFileMappingObjectHANDLEin
DesiredAccessFILE_MAPin
FileOffsetULONGLONGin
NumberOfBytesToMapUINT_PTRin

戻り値の型: MEMORY_MAPPED_VIEW_ADDRESS

各言語での呼び出し定義

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

MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFileFromApp(
    HANDLE hFileMappingObject,
    FILE_MAP DesiredAccess,
    ULONGLONG FileOffset,
    UINT_PTR NumberOfBytesToMap
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFileFromApp(
    IntPtr hFileMappingObject,   // HANDLE
    uint DesiredAccess,   // FILE_MAP
    ulong FileOffset,   // ULONGLONG
    UIntPtr NumberOfBytesToMap   // UINT_PTR
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MapViewOfFileFromApp(
    hFileMappingObject As IntPtr,   ' HANDLE
    DesiredAccess As UInteger,   ' FILE_MAP
    FileOffset As ULong,   ' ULONGLONG
    NumberOfBytesToMap As UIntPtr   ' UINT_PTR
) As MEMORY_MAPPED_VIEW_ADDRESS
End Function
' hFileMappingObject : HANDLE
' DesiredAccess : FILE_MAP
' FileOffset : ULONGLONG
' NumberOfBytesToMap : UINT_PTR
Declare PtrSafe Function MapViewOfFileFromApp Lib "kernel32" ( _
    ByVal hFileMappingObject As LongPtr, _
    ByVal DesiredAccess As Long, _
    ByVal FileOffset As LongLong, _
    ByVal NumberOfBytesToMap As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MapViewOfFileFromApp = ctypes.windll.kernel32.MapViewOfFileFromApp
MapViewOfFileFromApp.restype = ctypes.c_void_p
MapViewOfFileFromApp.argtypes = [
    wintypes.HANDLE,  # hFileMappingObject : HANDLE
    wintypes.DWORD,  # DesiredAccess : FILE_MAP
    ctypes.c_ulonglong,  # FileOffset : ULONGLONG
    ctypes.c_size_t,  # NumberOfBytesToMap : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
MapViewOfFileFromApp = Fiddle::Function.new(
  lib['MapViewOfFileFromApp'],
  [
    Fiddle::TYPE_VOIDP,  # hFileMappingObject : HANDLE
    -Fiddle::TYPE_INT,  # DesiredAccess : FILE_MAP
    -Fiddle::TYPE_LONG_LONG,  # FileOffset : ULONGLONG
    Fiddle::TYPE_UINTPTR_T,  # NumberOfBytesToMap : UINT_PTR
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn MapViewOfFileFromApp(
        hFileMappingObject: *mut core::ffi::c_void,  // HANDLE
        DesiredAccess: u32,  // FILE_MAP
        FileOffset: u64,  // ULONGLONG
        NumberOfBytesToMap: usize  // UINT_PTR
    ) -> MEMORY_MAPPED_VIEW_ADDRESS;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFileFromApp(IntPtr hFileMappingObject, uint DesiredAccess, ulong FileOffset, UIntPtr NumberOfBytesToMap);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_MapViewOfFileFromApp' -Namespace Win32 -PassThru
# $api::MapViewOfFileFromApp(hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap)
#uselib "KERNEL32.dll"
#func global MapViewOfFileFromApp "MapViewOfFileFromApp" sptr, sptr, sptr, sptr
; MapViewOfFileFromApp hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap   ; 戻り値は stat
; hFileMappingObject : HANDLE -> "sptr"
; DesiredAccess : FILE_MAP -> "sptr"
; FileOffset : ULONGLONG -> "sptr"
; NumberOfBytesToMap : UINT_PTR -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global MapViewOfFileFromApp "MapViewOfFileFromApp" sptr, int, int64, sptr
; res = MapViewOfFileFromApp(hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap)
; hFileMappingObject : HANDLE -> "sptr"
; DesiredAccess : FILE_MAP -> "int"
; FileOffset : ULONGLONG -> "int64"
; NumberOfBytesToMap : UINT_PTR -> "sptr"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; MEMORY_MAPPED_VIEW_ADDRESS MapViewOfFileFromApp(HANDLE hFileMappingObject, FILE_MAP DesiredAccess, ULONGLONG FileOffset, UINT_PTR NumberOfBytesToMap)
#uselib "KERNEL32.dll"
#cfunc global MapViewOfFileFromApp "MapViewOfFileFromApp" intptr, int, int64, intptr
; res = MapViewOfFileFromApp(hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap)
; hFileMappingObject : HANDLE -> "intptr"
; DesiredAccess : FILE_MAP -> "int"
; FileOffset : ULONGLONG -> "int64"
; NumberOfBytesToMap : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procMapViewOfFileFromApp = kernel32.NewProc("MapViewOfFileFromApp")
)

// hFileMappingObject (HANDLE), DesiredAccess (FILE_MAP), FileOffset (ULONGLONG), NumberOfBytesToMap (UINT_PTR)
r1, _, err := procMapViewOfFileFromApp.Call(
	uintptr(hFileMappingObject),
	uintptr(DesiredAccess),
	uintptr(FileOffset),
	uintptr(NumberOfBytesToMap),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // MEMORY_MAPPED_VIEW_ADDRESS
function MapViewOfFileFromApp(
  hFileMappingObject: THandle;   // HANDLE
  DesiredAccess: DWORD;   // FILE_MAP
  FileOffset: UInt64;   // ULONGLONG
  NumberOfBytesToMap: NativeUInt   // UINT_PTR
): MEMORY_MAPPED_VIEW_ADDRESS; stdcall;
  external 'KERNEL32.dll' name 'MapViewOfFileFromApp';
result := DllCall("KERNEL32\MapViewOfFileFromApp"
    , "Ptr", hFileMappingObject   ; HANDLE
    , "UInt", DesiredAccess   ; FILE_MAP
    , "Int64", FileOffset   ; ULONGLONG
    , "UPtr", NumberOfBytesToMap   ; UINT_PTR
    , "Ptr")   ; return: MEMORY_MAPPED_VIEW_ADDRESS
●MapViewOfFileFromApp(hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap) = DLL("KERNEL32.dll", "void* MapViewOfFileFromApp(void*, dword, qword, int)")
# 呼び出し: MapViewOfFileFromApp(hFileMappingObject, DesiredAccess, FileOffset, NumberOfBytesToMap)
# hFileMappingObject : HANDLE -> "void*"
# DesiredAccess : FILE_MAP -> "dword"
# FileOffset : ULONGLONG -> "qword"
# NumberOfBytesToMap : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。