MEMORY_MAPPED_FILE Class Reference

#include <LibSymbolInfo.h>

Public Member Functions

 MEMORY_MAPPED_FILE (PSTR pszFileName)
 
 ~MEMORY_MAPPED_FILE (void)
 
PVOID GetBase (void)
 
DWORD GetFileSize (void)
 
BOOL IsValid (void)
 
errMMF GetErrorType ()
 

Private Attributes

HANDLE m_hFile
 
HANDLE m_hFileMapping
 
PVOID m_pMemoryMappedFileBase
 
DWORD m_cbFile
 
errMMF m_errCode
 

Detailed Description

Definition at line 40 of file LibSymbolInfo.h.

Constructor & Destructor Documentation

MEMORY_MAPPED_FILE::MEMORY_MAPPED_FILE ( PSTR  pszFileName)

Definition at line 197 of file LibSymbolInfo.cpp.

197  {
198 
199  //
200  // Given a filename, the constructor opens a file handle, creates a file
201  // mapping, and maps the entire file into memory.
202  //
203  m_hFile = INVALID_HANDLE_VALUE;
204  m_hFileMapping = 0;
206  m_cbFile = 0;
207  m_errCode = errMMF_FileOpen; // Initial error code: not found
208  // First get a file handle
209  m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
210  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0);
211 
212  if ( m_hFile == INVALID_HANDLE_VALUE )
213  {
215  return;
216  }
218  // Now, create a file mapping
219  m_hFileMapping = CreateFileMapping(m_hFile,NULL, PAGE_READONLY, 0, 0,NULL);
220  if ( m_hFileMapping == 0 )
221  {
222  // Oops. Something went wrong. Clean up.
223  CloseHandle(m_hFile);
224  m_hFile = INVALID_HANDLE_VALUE;
226  return;
227  }
228  m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping,
229  FILE_MAP_READ, 0, 0, 0);
230  if ( m_pMemoryMappedFileBase == 0 )
231  {
232  // Oops. Something went wrong. Clean up.
233  CloseHandle(m_hFileMapping);
234  m_hFileMapping = 0;
235  CloseHandle(m_hFile);
236  m_hFile = INVALID_HANDLE_VALUE;
238  return;
239  }
241 }
DWORD GetFileSize(void)
Definition: LibSymbolInfo.h:47
PVOID m_pMemoryMappedFileBase
Definition: LibSymbolInfo.h:55
MEMORY_MAPPED_FILE::~MEMORY_MAPPED_FILE ( void  )

Definition at line 243 of file LibSymbolInfo.cpp.

244 {
245  // Clean up everything that was created by the constructor
247  UnmapViewOfFile( m_pMemoryMappedFileBase );
248 
249  if ( m_hFileMapping )
250  CloseHandle( m_hFileMapping );
251 
252  if ( m_hFile != INVALID_HANDLE_VALUE )
253  CloseHandle( m_hFile );
254 
256 }
PVOID m_pMemoryMappedFileBase
Definition: LibSymbolInfo.h:55

Member Function Documentation

PVOID MEMORY_MAPPED_FILE::GetBase ( void  )
inline

Definition at line 46 of file LibSymbolInfo.h.

46 { return m_pMemoryMappedFileBase; }
PVOID m_pMemoryMappedFileBase
Definition: LibSymbolInfo.h:55
errMMF MEMORY_MAPPED_FILE::GetErrorType ( )
inline

Definition at line 49 of file LibSymbolInfo.h.

49 { return m_errCode; }
DWORD MEMORY_MAPPED_FILE::GetFileSize ( void  )
inline

Definition at line 47 of file LibSymbolInfo.h.

47 { return m_cbFile; }
BOOL MEMORY_MAPPED_FILE::IsValid ( void  )
inline

Definition at line 48 of file LibSymbolInfo.h.

Member Data Documentation

DWORD MEMORY_MAPPED_FILE::m_cbFile
private

Definition at line 56 of file LibSymbolInfo.h.

errMMF MEMORY_MAPPED_FILE::m_errCode
private

Definition at line 57 of file LibSymbolInfo.h.

HANDLE MEMORY_MAPPED_FILE::m_hFile
private

Definition at line 53 of file LibSymbolInfo.h.

HANDLE MEMORY_MAPPED_FILE::m_hFileMapping
private

Definition at line 54 of file LibSymbolInfo.h.

PVOID MEMORY_MAPPED_FILE::m_pMemoryMappedFileBase
private

Definition at line 55 of file LibSymbolInfo.h.


The documentation for this class was generated from the following files: