MapViewOfFile2 function (memoryapi.h)

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

Syntax

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

Parameters

[in] FileMappingHandle

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

[in] ProcessHandle

A HANDLE to a process into which the section will be mapped. The handle must have the PROCESS_VM_OPERATION access mask.

[in] Offset

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

[in, optional] 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.

[in] ViewSize

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

[in] 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. This flag specifies that the view should be mapped using large page support. The size of the view must be a multiple of the size of a large page reported by the GetLargePageMinimum function, and the file-mapping object must have been created using the SEC_LARGE_PAGES option. If you provide a non-null value for the BaseAddress parameter, then the value must be a multiple of GetLargePageMinimum.

[in] 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.

Remarks

This function is implemented as an inline function in the header and can't be found in any export library or DLL. It's the same as calling MapViewOfFileNuma2 with the last parameter set to NUMA_NO_PREFERRED_NODE.

Requirements

Requirement Value
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 onecore.lib
DLL Kernel32.dll

See also

MapViewOfFile

MapViewOfFileNuma2