home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / VDLib / source / win32 / FileMapping.cpp < prev   
Encoding:
C/C++ Source or Header  |  2009-09-14  |  1.2 KB  |  63 lines

  1. #include "stdafx.h"
  2. #include "vd2/VDLib/win32/FileMapping.h"
  3. #include <windows.h>
  4.  
  5. VDFileMappingW32::VDFileMappingW32()
  6.     : mpHandle(NULL)
  7. {
  8. }
  9.  
  10. VDFileMappingW32::~VDFileMappingW32() {
  11.     Shutdown();
  12. }
  13.  
  14. bool VDFileMappingW32::Init(uint32 bytes) {
  15.     if (mpHandle)
  16.         Shutdown();
  17.  
  18.     mpHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, bytes, NULL);
  19.     if (!mpHandle)
  20.         return false;
  21.  
  22.     return true;
  23. }
  24.  
  25. void VDFileMappingW32::Shutdown() {
  26.     if (mpHandle) {
  27.         CloseHandle(mpHandle);
  28.         mpHandle = NULL;
  29.     }
  30. }
  31.  
  32. ///////////////////////////////////////////////////////////////////////////////
  33.  
  34. VDFileMappingViewW32::VDFileMappingViewW32()
  35.     : mpView(NULL)
  36. {
  37. }
  38.  
  39. VDFileMappingViewW32::~VDFileMappingViewW32() {
  40.     Shutdown();
  41. }
  42.  
  43. bool VDFileMappingViewW32::Init(const VDFileMappingW32& mapping, uint64 offset, uint32 size) {
  44.     Shutdown();
  45.  
  46.     HANDLE h = mapping.GetHandle();
  47.     if (!h)
  48.         return false;
  49.  
  50.     mpView = MapViewOfFile(h, FILE_MAP_WRITE, (uint32)(offset >> 32), (uint32)offset, size);
  51.     if (!mpView)
  52.         return false;
  53.  
  54.     return true;
  55. }
  56.  
  57. void VDFileMappingViewW32::Shutdown() {
  58.     if (mpView) {
  59.         UnmapViewOfFile(mpView);
  60.         mpView = NULL;
  61.     }
  62. }
  63.