网站首页  词典首页

请输入您要查询的函数:

 

术语 mapviewoffile
释义 MapViewOfFile
语法:
C++
LPVOID WINAPI MapViewOfFile(
__in HANDLE hFileMappingObject,
__in DWORD dwDesiredAccess,
__in DWORD dwFileOffsetHigh,
__in DWORD dwFileOffsetLow,
__in SIZE_T dwNumberOfBytesToMap
);
MapViewOfFile函数
到呼叫进程的地址空间映射一个文件映射视图。
要指定一个观点建议的基地址,使用MapViewOfFileEx功能。然而,这种做法是不推荐。
参数
hFileMappingObject [in]
句柄到一个文件映射对象。在CreateFileMapping和OpenFileMapping函数返回此句柄。
dwDesiredAccess [in]
在访问一个文件映射对象,它决定了保护类型的网页。此参数可以是下列值之一。
ValueMeaning
FILE_MAP_ALL_ACCESSA读/写文件的看法是映射。该文件映射对象必须已创建PAGE_READWRITE或PAGE_EXECUTE_READWRITE保护。
当与MapViewOfFile函数使用,FILE_MAP_ALL_ACCESS相当于FILE_MAP_WRITE。
FILE_MAP_COPYA复制上写的文件视图被映射。该文件映射对象必须已创建PAGE_READONLY,PAGE_READ_EXECUTE,PAGE_WRITECOPY,PAGE_EXECUTE_WRITECOPY,PAGE_READWRITE,或PAGE_EXECUTE_READWRITE保护。
当一个进程写入时复制写网页时,系统拷贝原始网页到新的页面是私有的过程。新网页背后是分页文件。这是自复制保护新的一页的变化上写读/写。
当复制上写访问指定的系统和流程所承诺负责,因为调用进程有可能写入每个页面视图中,使所有网页私营整个景观。新网页的内容是不写回原来的文件丢失和视图时映射。
FILE_MAP_READA读取该文件只能查看被映射。试图写入访问冲突文件查看的结果。
该文件映射对象必须已创建PAGE_READONLY,PAGE_READWRITE,PAGE_EXECUTE_READ,或PAGE_EXECUTE_READWRITE保护。
FILE_MAP_WRITEA读/写文件的看法是映射。该文件映射对象必须已创建PAGE_READWRITE或PAGE_EXECUTE_READWRITE保护。
当用于MapViewOfFile(FILE_MAP_WRITE | FILE_MAP_READ)和FILE_MAP_ALL_ACCESS相当于FILE_MAP_WRITE。
前面的每个值可以与下面的值。
ValueMeaning
FILE_MAP_EXECUTEAn文件的可执行文件的观点是映射(映射内存可以作为代码运行)。该文件映射对象必须已创建PAGE_EXECUTE_READ,PAGE_EXECUTE_WRITECOPY,或PAGE_EXECUTE_READWRITE保护。
Windows Server 2003和Windows XP中:此值可与Windows SP2和Windows Server 2003的XP的SP1的开始。
Windows 2000中:此值不支持。
有关更多信息,请参阅文件映射安全和访问权限。
dwFileOffsetHigh [in]
高阶文件双字节值的偏移,在看法上开始。
dwFileOffsetLow [in]
阿低位双字节值的偏移量文件,其中的观点是开始。在高和低失调组合必须指定一个偏移量文件映射。他们还必须匹配的系统内存分配粒度。也就是说,偏移量必须的分配粒度的倍数。要获取系统内存分配粒度,使用的GetSystemInfo功能,它在一个SYSTEM_INFO结构的成员填充。
dwNumberOfBytesToMap [in]
对一个文件映射的字节数映射到视图。所有字节必须由CreateFileMapping内指定的最大大小。如果此参数为0(零),映射扩展从指定偏移文件的映射结束。
返回值
如果函数成功,返回值是映射的视图起始地址。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
映射文件使一个文件中调用进程的地址空间可见的特定部分。
对于文件,这些文件的地址空间比大,您只能一次映射文件的一个小部分数据。当第一个观点是完整的,您可以取消映射,并映射到新的观点。
要获取视图的大小,使用VirtualQuery函数。
一个文件(或文件映射对象和它的映射文件的多个视图)是一致的,如果它们包含在指定的时间相同的数据。如果发生这种情况的文件的看法是从同一个文件映射对象产生。一个进程可以重复使用DuplicateHandle函数或其他进程的名称可以打开使用OpenFileMapping函数对象文件映射文件映射对象句柄到另一个进程。
一个文件映射的看法是不保证的是由了ReadFile和WriteFile函数访问的文件一致。
不要储存在内存映射文件的指针,从文件映射基础,使存储偏移映射可以在任何地址使用。
为了防止EXCEPTION_IN_PAGE_ERROR例外,使用结构化异常处理,以保护任何代码或写入一个文件映射比其他视图页面文件内存读取。有关详细信息,请阅读并从文件视图写作。
如果一个文件映射对象的背后是分页文件(CreateFileMapping是设置为INVALID_HANDLE_VALUE的hFile参数调用),分页文件必须足以容纳整个映射。如果不是,MapViewOfFile失败。在一个文件映射的网页对象的初始内容的分页文件备份为0(零)。
当一个文件映射对象,由分页文件的支持创建,调用者可以指定是否MapViewOfFile应该保留,并承诺在同一时间页(SEC_COMMIT)或只是储备页(SEC_RESERVE)。映射文件使整个映射虚拟地址范围无法获得其他分配的过程。从后保留的范围页面承诺,它不会释放或调用VirtualFree decommitted。保留并承诺释放页面视图时映射的文件映射对象关闭。有关详细信息,请参见UnmapViewOfFile和CloseHandle功能。
有一个具有执行权限的文件,应用程序必须调用要么PAGE_EXECUTE_READWRITE或PAGE_EXECUTE_READ CreateFileMapping,然后调用FILE_MAP_EXECUTE MapViewOfFile | FILE_MAP_WRITE或FILE_MAP_EXECUTE | FILE_MAP_READ。
实例
有关示例,请参阅创建命名共享内存。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateFileMapping
创建一个文件视图
DuplicateHandle
文件映射函数
的GetSystemInfo
MapViewOfFileEx
OpenFileMapping
SYSTEM_INFO
UnmapViewOfFile
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==MapViewOfFile Function
Maps a view of a file mapping into the address space of a calling process.
To specify a suggested base address for the view, use the MapViewOfFileEx function. However, this practice is not recommended.
Syntax
C++
LPVOID WINAPI MapViewOfFile(
__in HANDLE hFileMappingObject,
__in DWORD dwDesiredAccess,
__in DWORD dwFileOffsetHigh,
__in DWORD dwFileOffsetLow,
__in SIZE_T dwNumberOfBytesToMap
);
Parameters
hFileMappingObject [in]
A handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle.
dwDesiredAccess [in]
The type of access to a file mapping object, which determines the protection of the pages. This parameter can be one of the following values.
ValueMeaning
FILE_MAP_ALL_ACCESSA read/write view of the file is mapped. The file mapping object must have been created with PAGE_READWRITE or PAGE_EXECUTE_READWRITE protection.
When used with the MapViewOfFile function, FILE_MAP_ALL_ACCESS is equivalent to FILE_MAP_WRITE.
FILE_MAP_COPYA copy-on-write view of the file is mapped. The file mapping object must have been created with PAGE_READONLY, PAGE_READ_EXECUTE, PAGE_WRITECOPY, PAGE_EXECUTE_WRITECOPY, PAGE_READWRITE, or PAGE_EXECUTE_READWRITE protection.
When a process writes to a copy-on-write page, the system copies the original page to a new page that is private to the process. The new page is backed by the paging file. The protection of the new page changes from copy-on-write to read/write.
When copy-on-write access is specified, the system and process commit charge taken is for the entire view because the calling process can potentially write to every page in the view, making all pages private. The contents of the new page are never written back to the original file and are lost when the view is unmapped.
FILE_MAP_READA read-only view of the file is mapped. An attempt to write to the file view results in an access violation.
The file mapping object must have been created with PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE_READ, or PAGE_EXECUTE_READWRITE protection.
FILE_MAP_WRITEA read/write view of the file is mapped. The file mapping object must have been created with PAGE_READWRITE or PAGE_EXECUTE_READWRITE protection.
When used with MapViewOfFile, (FILE_MAP_WRITE | FILE_MAP_READ) and FILE_MAP_ALL_ACCESS are equivalent to FILE_MAP_WRITE.

Each of the preceding values can be combined with the following value.
ValueMeaning
FILE_MAP_EXECUTEAn executable view of the file is mapped (mapped memory can be run as code). The file mapping object must have been created with PAGE_EXECUTE_READ, PAGE_EXECUTE_WRITECOPY, or PAGE_EXECUTE_READWRITE protection.
Windows Server 2003 and Windows XP: This value is available starting with Windows XP with SP2 and Windows Server 2003 with SP1.
Windows 2000: This value is not supported.

For more information, see File Mapping Security and Access Rights .
dwFileOffsetHigh [in]
A high-order DWORD of the file offset where the view begins.
dwFileOffsetLow [in]
A low-order DWORD of the file offset where the view is to begin. The combination of the high and low offsets must specify an offset within the file mapping. They must also match the memory allocation granularity of the system. That is, the offset must be a multiple of the allocation granularity. To obtain the memory allocation granularity of the system, use the GetSystemInfo function, which fills in the members of a SYSTEM_INFO structure.
dwNumberOfBytesToMap [in]
The number of bytes of a file mapping to map to the view. All bytes must be within the maximum size specified by CreateFileMapping. If this parameter is 0 (zero), the mapping extends from the specified offset to the end of the file mapping.
Return Value
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 a file visible in the address space of the calling process.
For files that are larger than the address space, you can only map a small portion of the file data at one time. When the first view is complete, you can unmap it and map a new view.
To obtain the size of a view, use the VirtualQuery function.
Multiple views of a file (or a file mapping object and its mapped file) are 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 that is being accessed by the ReadFile or WriteFile function.
Do not store pointers in the memory mapped file; store offsets from the base of the file mapping so that the mapping can be used at any address.
To guard against EXCEPTION_IN_PAGE_ERROR exceptions, use structured exception handling to protect any code that writes to or reads from a memory mapped view of a file other than the page file. For more information, see Reading and Writing From a File View .
If a file mapping object is backed by the paging file (CreateFileMapping is called with the hFile parameter set to INVALID_HANDLE_VALUE), the paging file must be large enough to hold the entire mapping. If it is not, MapViewOfFile fails. The initial contents of the pages in a file mapping object backed by the paging file are 0 (zero).
When a file mapping object that is backed by the paging file is created, the caller can specify whether MapViewOfFile should reserve and commit pages at the same time (SEC_COMMIT) or simply reserve pages (SEC_RESERVE). Mapping the file makes the entire mapped virtual address range unavailable to other allocations in the process. After a page from the reserved range is committed, it cannot be freed or decommitted by calling VirtualFree . Reserved and committed pages are released when the view is unmapped and the file mapping object is closed. For details, see the UnmapViewOfFile and CloseHandle functions.
To have a file with executable permissions, an application must call CreateFileMapping with either PAGE_EXECUTE_READWRITE or PAGE_EXECUTE_READ, and then call MapViewOfFile with FILE_MAP_EXECUTE | FILE_MAP_WRITE or FILE_MAP_EXECUTE | FILE_MAP_READ.
Examples
For an example, see Creating Named Shared Memory .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CreateFileMapping
Creating a File View
DuplicateHandle
File Mapping Functions
GetSystemInfo
MapViewOfFileEx
OpenFileMapping
SYSTEM_INFO
UnmapViewOfFile
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 9:26:23