网站首页  词典首页

请输入您要查询的函数:

 

术语 mapviewoffileex
释义 MapViewOfFileEx
语法:
C++
LPVOID WINAPI MapViewOfFileEx(
__in HANDLE hFileMappingObject,
__in DWORD dwDesiredAccess,
__in DWORD dwFileOffsetHigh,
__in DWORD dwFileOffsetLow,
__in SIZE_T dwNumberOfBytesToMap,
__in_opt LPVOID lpBaseAddress
);
MapViewOfFileEx功能
到呼叫进程的地址空间映射一个文件映射视图。调用方可以选择指定一个观点建议基本内存地址。
要指定的物理内存NUMA节点,见MapViewOfFileExNuma。
参数
hFileMappingObject [in]
句柄到一个文件映射对象。在CreateFileMapping和OpenFileMapping函数返回此句柄。
dwDesiredAccess [in]
在访问一个文件映射对象,它决定了保护类型页。此参数可以是下列值之一。
ValueMeaning
FILE_MAP_ALL_ACCESSA读/写文件的看法是映射。该文件映射对象必须已创建PAGE_READWRITE或PAGE_EXECUTE_READWRITE保护。
当与MapViewOfFileEx函数使用,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保护。
当用于MapViewOfFileEx,(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(零),映射扩展从指定偏移文件的映射结束。
lpBaseAddress [中,可选]
向在调用进程地址空间的内存地址指针放在映射开始。这必须是一个系统的内存分配粒度,或函数的多重失败。要确定系统内存分配粒度,使用的GetSystemInfo函数。如果没有足够的地址在指定的地址空间,功能失败。
如果lpBaseAddress是NULL,操作系统选择的映射地址。在这种情况下,功能等同于MapViewOfFile函数。
虽然可以指定的地址,现在是安全的(不使用操作系统),但不能保证该地址将随着时间的推移仍然安全。因此,最好是让操作系统选择的地址。在这种情况下,您不会存储在内存映射文件的指针,您将存储从文件映射基础,让映射可以在任何地址中使用偏移。
返回值
如果函数成功,返回值是映射的视图起始地址。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
映射文件使文件在调用进程的地址空间可见的特定部分。
对于文件,这些文件的地址空间比大,您只能一次映射文件的一个小部分数据。当第一种观点是完整的,那么您取消映射,并映射到新的观点。
要获取视图的大小,使用VirtualQueryEx功能。
在一个文件映射的网页内容对象的初始页面文件的支持是0(零)。
如果建议的映射地址提供,该文件被映射到指定的地址(四舍五入至最接近的64K的边界),如果有足够的地址在指定的地址空间。如果没有足够的地址空间,功能失败。
通常情况下,建议的地址是用来指定一个文件,应在多个进程在同一地址的映射。这就需要区域的地址空间将在所有涉及的工艺可用。没有其他的内存分配可以在所使用的映射,包括VirtualAlloc或VirtualAllocEx函数使用保留内存区域发生。
如果lpBaseAddress参数指定一个基地偏移,函数成功如果指定的内存区域是不是已经在使用的调用进程。该系统并不能保证同样的内存区域是映射到其他32位程序文件的内存。
一个文件(或文件映射对象和它的映射文件的多个视图)是一致的,如果它们包含在指定的时间相同的数据。如果发生这种情况的文件的看法是从同一个文件映射对象产生。一个进程可以重复使用DuplicateHandle函数或其他进程的名称可以打开使用OpenFileMapping函数对象文件映射文件映射对象句柄到另一个进程。
一个文件映射的观点是不能保证是一致的文件被了ReadFile和WriteFile函数访问。
为了防止EXCEPTION_IN_PAGE_ERROR例外,使用结构化异常处理,以保护任何代码或写入一个文件映射比其他视图页面文件内存读取。有关详细信息,请阅读并从文件视图写作。
有一个具有执行权限的文件,应用程序必须调用要么PAGE_EXECUTE_READWRITE或PAGE_EXECUTE_READ CreateFileMapping,然后调用FILE_MAP_EXECUTE MapViewOfFileEx | 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
MapViewOfFileExNuma
OpenFileMapping
ReadFile
SYSTEM_INFO
UnmapViewOfFile
VirtualAlloc
WriteFile
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==MapViewOfFileEx Function
Maps a view of a file mapping into the address space of a calling process. A caller can optionally specify a suggested base memory address for the view.
To specify the NUMA node for the physical memory, see MapViewOfFileExNuma .
Syntax
C++
LPVOID WINAPI MapViewOfFileEx(
__in HANDLE hFileMappingObject,
__in DWORD dwDesiredAccess,
__in DWORD dwFileOffsetHigh,
__in DWORD dwFileOffsetLow,
__in SIZE_T dwNumberOfBytesToMap,
__in_opt LPVOID lpBaseAddress
);
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 page 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 MapViewOfFileEx 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 MapViewOfFileEx, (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]
The high-order DWORD of the file offset where the view is to begin.
dwFileOffsetLow [in]
The 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 a 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.
lpBaseAddress [in, optional]
A pointer to the memory address in the calling process address space where mapping begins. This must be a multiple of the system's memory allocation granularity, or the function fails. To determine the memory allocation granularity of the system, use the GetSystemInfo function. If there is not enough address space at the specified address, the function fails.
If lpBaseAddress is NULL, the operating system chooses the mapping address. In this scenario, the function is equivalent to the MapViewOfFile function.
While it is possible to specify an address that is safe now (not used by the operating system), there is no guarantee that the address will remain safe over time. Therefore, it is better to let the operating system choose the address. In this case, you would not store pointers in the memory mapped file, you would store offsets from the base of the file mapping so that the mapping can be used at any address.
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 the 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, then you unmap it and map a new view.
To obtain the size of a view, use the VirtualQueryEx function.
The initial contents of the pages in a file mapping object backed by the page file are 0 (zero).
If a suggested mapping address is supplied, the file is mapped at the specified address (rounded down to the nearest 64K-boundary) if there is enough address space at the specified address. If there is not enough address space, the function fails.
Typically, the suggested address is used to specify that a file should be mapped at the same address in multiple processes. This requires the region of address space to be available in all involved processes. No other memory allocation can take place in the region that is used for mapping, including the use of the VirtualAlloc or VirtualAllocEx function to reserve memory.
If the lpBaseAddress parameter specifies a base offset, the function succeeds if the specified memory region is not already in use by the calling process. The system does not ensure that the same memory region is available for the memory mapped file in other 32-bit processes.
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 being accessed by the ReadFile or WriteFile function.
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 .
To have a file with executable permissions, an application must call CreateFileMapping with either PAGE_EXECUTE_READWRITE or PAGE_EXECUTE_READ, and then call MapViewOfFileEx with FILE_MAP_EXECUTE | FILE_MAP_WRITE or FILE_MAP_EXECUTE | FILE_MAP_READ.
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
MapViewOfFileExNuma
OpenFileMapping
ReadFile
SYSTEM_INFO
UnmapViewOfFile
VirtualAlloc
WriteFile
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa366763(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:20:27