|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| Yes
| Win32s
| Yes
| Import Library
| kernel32.lib
| Header File
| winbase.h
| Unicode
| No
| Platform Notes
| Windows 95: Memory mapped files appear in the same address space in all
processes
|
|
|
MapViewOfFile
The MapViewOfFile function maps a view of a file into the address space of the calling process.
LPVOID MapViewOfFile(
HANDLE hFileMappingObject,
| // file-mapping object to map into address space
| DWORD dwDesiredAccess,
| // access mode
| DWORD dwFileOffsetHigh,
| // high-order 32 bits of file offset
| DWORD dwFileOffsetLow,
| // low-order 32 bits of file offset
| DWORD dwNumberOfBytesToMap
| // number of bytes to map
| );
|
|
Parameters
hFileMappingObject
Identifies an open handle of a file-mapping object. The CreateFileMapping and OpenFileMapping functions return this handle.
dwDesiredAccess
Specifies the type of access to the file view and, therefore, the protection
of the pages mapped by the file. This parameter can be one of the following
values:
Value
| Meaning
| FILE_MAP_WRITE
| 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
| 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.
| FILE_MAP_COPY
| Copy on write access. If you create the map with PAGE_WRITECOPY and the view
with FILE_MAP_COPY, you will receive a view to file. If you write to it, the
pages are automatically swappable and the modifications you make will not go to
the original data file.
Windows 95: You must pass PAGE_WRITECOPY to CreateFileMapping; otherwise, an error will be returned.
If you share the mapping between multiple processes using DuplicateHandle or OpenFileMapping and one process writes to a view, the modification is propagated to the other
process. The original file does not change.
Windows NT: There is no restriction as to how the hFileMappingObject parameter must be created. Copy on write is valid for any type of view.
If you share the mapping between multiple processes using DuplicateHandle or OpenFileMapping and one process writes to a view, the modification is not propagated to the
other process. The original file does not change.
|
dwFileOffsetHigh
Specifies the high-order 32 bits of the file offset where mapping is to begin.
dwFileOffsetLow
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
Specifies the number of bytes of the file to map. If dwNumberOfBytesToMap is zero, the entire file is mapped.
Return Values
If the function succeeds, the return value is the starting address of the
mapped view.
If the function fails, the return value is NULL. To get extended error
information, call GetLastError.
Remarks
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. A process
can duplicate a file-mapping object handle into another process by using the DuplicateHandle function, or another process can open a file-mapping object by name by using
the OpenFileMapping function.
A mapped view of a file is not guaranteed to be coherent with a file being
accessed by the ReadFile or WriteFile function.
Windows 95: MapViewOfFile may require the swapfile to grow. If the swapfile cannot grow, the function
fails.
Windows NT: If the file-mapping object is backed by the paging file (handle =
0xFFFFFFFF), the paging file must be large enough to hold the entire mapping. If it is
not, MapViewOfFile fails.
See Also
CreateFileMapping, DuplicateHandle, GetSystemInfo, MapViewOfFileEx, OpenFileMapping, UnmapViewOfFile, SYSTEM_INFO
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|