Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: MemoryFile.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of MemoryFile.cpp
  13. //----------------------------------------------------------------------------
  14. // MapFile.cpp: implementation of the CMemoryFile class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "MemoryFile.h"
  19. #include "..\..\LgLib\Version.h"
  20. //////////////////////////////////////////////////////////////////////
  21. // Construction/Destruction
  22. //////////////////////////////////////////////////////////////////////
  23. CMemoryFile::CMemoryFile()
  24. {
  25. m_hMap = NULL;
  26. m_pMemory = NULL;
  27. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CMemoryFile::CMemoryFile") );
  28. }
  29. CMemoryFile::~CMemoryFile()
  30. {
  31. Unmap();
  32. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CMemoryFile::~CMemoryFile") );
  33. }
  34. BOOL CMemoryFile::Map( DWORD dwSize, LPCTSTR pName )
  35. {
  36. Unmap();
  37. m_hMap = ::CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, dwSize, pName );
  38. if( m_hMap )
  39. {
  40. m_pMemory = ::MapViewOfFileEx( m_hMap, FILE_MAP_ALL_ACCESS, 0UL, 0UL, 0UL, NULL );
  41. if( m_pMemory )
  42. return TRUE;
  43. }
  44. return FALSE;
  45. }
  46. void CMemoryFile::Unmap()
  47. {
  48. if( m_pMemory )
  49. {
  50. ::UnmapViewOfFile( m_pMemory );
  51. m_pMemory = NULL;
  52. }
  53. if( m_hMap )
  54. {
  55. ::CloseHandle( m_hMap );
  56. m_hMap = NULL;
  57. }
  58. }