다음을 통해 공유


MapViewOfFile (Windows CE 5.0)

Send Feedback

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

LPVOID MapViewOfFile( HANDLEhFileMappingObject,DWORDdwDesiredAccess,DWORDdwFileOffsetHigh,DWORDdwFileOffsetLow,DWORD dwNumberOfBytesToMap );

Parameters

  • hFileMappingObject
    [in] Handle to an open handle of a file-mapping object. The CreateFileMapping function returns this handle.
  • dwDesiredAccess
    [in] Specifies the type of access to the file view and, therefore, the protection of the pages mapped by the file. The following table shows possible values for this parameter.
    Value Description
    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.
    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_ALL_ACCESS Same as FILE_MAP_WRITE.
  • 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 dwNumberOfBytesToMap is zero, the entire file is mapped.

Return Values

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

Remarks

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

The 64 KB alignment is not required for the dwFileOffsetLow parameter.

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) are said to be coherent if they contain identical data at a specified time. This occurs if the file views are derived from the same file-mapping object. In order 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 coherent with a file being accessed by the ReadFile or WriteFile function.

To guard against an access violation, use structured exception handling to protect any code that writes to or reads from a memory mapped view.

Requirements

OS Versions: Windows CE 1.01 and later.
Header: Winbase.h.
Link Library: Coredll.lib.

See Also

CreateFileMapping | GetSystemInfo | UnmapViewOfFile | SYSTEM_INFO

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.