MapViewOfFile (Compact 2013)

3/26/2014

This function maps a view of a file into the address space of the calling process.

Syntax

LPVOID MapViewOfFile(
  HANDLE hFileMappingObject,
  DWORD dwDesiredAccess,
  DWORD dwFileOffsetHigh,
  DWORD dwFileOffsetLow,
  DWORD dwNumberOfBytesToMap
);

Parameters

  • hFileMappingObject
    [in] Handle to an open handle of a file-mapping object returned by the CreateFileMapping function.
  • dwDesiredAccess
    [in] Type of access to the file view and, therefore, to the protection of the pages mapped by the file.

    The following table shows possible values.

    Value

    Description

    FILE_MAP_ALL_ACCESS

    Specifies read-write access. The hFileMappingObject parameter must have been created with PAGE_READWRITE protection. A read-write view of the file is mapped.

    FILE_MAP_READ

    Specifies read-only access. The hFileMappingObject parameter must have been created with PAGE_READWRITE or PAGE_READONLY protection. A read-only view of the file is mapped.

    FILE_MAP_WRITE

    Specifies read-write access. The hFileMappingObject parameter must have been created with PAGE_READWRITE protection. A read-write view of the file is mapped.

  • dwFileOffsetHigh
    [in] Specifies the high order 32 bits of the file offset where mapping is to begin.
  • dwFileOffsetLow
    [in] Specifies the low order 32 bits of the file offset where mapping is to begin. The combination of the high and low offsets must specify an offset within the file that matches the system's memory allocation granularity, or the function fails. That is, the offset must be a multiple of the allocation granularity. Use the GetSystemInfo function, which fills in the members of a SYSTEM_INFO structure, to obtain the system's memory allocation granularity.
  • dwNumberOfBytesToMap
    [in] Specifies the number of bytes of the file to map. If this parameter is set to zero, the entire file is mapped.

Return Value

The starting address of the mapped view indicates success; otherwise, returns NULL. To get extended error information, call GetLastError.

Remarks

This function can create views if the current process has enough virtual address space to contain them. Because of memory constraints, this function does not map files mapped directly to ROM or files that don't use the paging pool and that are larger than 4 GB.

If you intend to increase the file's size, specify the maximum file size so that the kernel can reserve the correct amount of memory.

The 64-KB alignment is not required for dwFileOffsetLow.

Mapping a file makes the specified portion of the file visible in the address space of the calling process.

Multiple views of a file, or a file-mapping object and its mapped file, contain identical data at a specified time if the file views are derived from the same file-mapping object. To create another view of a file-mapping object for a different process, use the CreateFileMapping function.

A mapped view of a file is not guaranteed to be identical to other file views or to the file if a file is accessed with the ReadFile or the WriteFile function.

To help prevent an access violation, use structured exception handling (SEH) when you write code that writes to or reads from a memory-mapped view.

The pages in the mapped views can become writeable if they are written to. Any pages that do not overlap remain read-only. Any pages that overlap, but which are not written to, remain read-only. If all writeable views are unmapped, unwritten pages remain read-only.

Requirements

Header

winbase.h

Library

coredll.lib

See Also

Reference

File Mapping Functions
CreateFileMapping
UnmapViewOfFile

Other Resources

GetSystemInfo
SYSTEM_INFO