MapViewOfFile2 function

Maps a view of a file or a pagefile-backed section into the address space of the specified process.

Syntax

PVOID MapViewOfFile2(
  HANDLE  FileMappingHandle,
  HANDLE  ProcessHandle,
  ULONG64 Offset,
  PVOID   BaseAddress,
  SIZE_T  ViewSize,
  ULONG   AllocationType,
  ULONG   PageProtection
);

Parameters

FileMappingHandle

A HANDLE to a section that is to be mapped into the address space of the specified process.

ProcessHandle

A HANDLE to a process into which the section will be mapped.

Offset

The offset from the beginning of the section. This must be 64k aligned.

BaseAddress

The desired base address of the view. The address is rounded down to the nearest 64k boundary. If this parameter is NULL, the system picks the base address.

ViewSize

The number of bytes to map. A value of zero (0) specifies that the entire section is to be mapped.

AllocationType

The type of allocation. This parameter can be zero (0) or one of the following constant values:

  • MEM_RESERVE - Maps a reserved view
  • MEM_LARGE_PAGES - Maps a large page view

PageProtection

The desired page protection.

For file-mapping objects created with the SEC_IMAGE attribute, the PageProtection parameter has no effect, and should be set to any valid value such as PAGE_READONLY.

Return Value

Returns the base address of the mapped view, if successful. Otherwise, returns NULL and extended error status is available using GetLastError.

Requirements

   
Minimum supported client Windows 10, version 1703 [desktop apps only]
Minimum supported server Windows Server 2016 [desktop apps only]
Target Platform Windows
Header memoryapi.h (include Windows.h, Memoryapi.h)
Library Kernel32.lib
DLL Kernel32.dll

See Also

MapViewOfFile

MapViewOfFileNuma2