Share via


CAtlFileMappingBase::MapFile

Call this method to open or create a file-mapping object for the specified file.

HRESULT MapFile( 
   HANDLE hFile, 
   SIZE_T nMappingSize = 0, 
   ULONGLONG nOffset = 0, 
   DWORD dwMappingProtection = PAGE_READONLY, 
   DWORD dwViewDesiredAccess = FILE_MAP_READ  
) throw( );

Parameters

  • hFile
    Handle to the file from which to create a mapping object. hFile must be valid and cannot be set to INVALID_HANDLE_VALUE.

  • nMappingSize
    The mapping size. If 0, the maximum size of the file-mapping object is equal to the current size of the file identified by hFile.

  • nOffset
    The file offset where mapping is to begin. The offset value must be a multiple of the system's memory allocation granularity.

  • dwMappingProtection
    The protection desired for the file view when the file is mapped. See flProtect in CreateFileMapping in the Windows SDK.

  • dwViewDesiredAccess
    Specifies the type of access to the file view and, therefore, the protection of the pages mapped by the file. See dwDesiredAccess in MapViewOfFileEx in the Windows SDK.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Remarks

After a file-mapping object has been created, the size of the file must not exceed the size of the file-mapping object; if it does, not all of the file's contents will be available for sharing. For more details, see CreateFileMapping and MapViewOfFileEx in the Windows SDK.

Example

See the example for CAtlFileMappingBase::CAtlFileMappingBase.

Requirements

Header: atlfile.h

See Also

Reference

CAtlFileMappingBase Class