Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Memory.h « Windows « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd8773b8e768e9fb66a2f2db8e86a86d3e059994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Windows/Memory.h

#ifndef __WINDOWS_MEMORY_H
#define __WINDOWS_MEMORY_H

namespace NWindows {
namespace NMemory {

class CGlobal
{
  HGLOBAL m_MemoryHandle;
public:
  CGlobal(): m_MemoryHandle(NULL){};
  ~CGlobal();
  operator HGLOBAL() const { return m_MemoryHandle; };
  void Attach(HGLOBAL hGlobal);
  HGLOBAL Detach();
  bool Alloc(UINT flags, SIZE_T size);
  bool Free();
  LPVOID Lock() const;
  void Unlock() const;
  bool ReAlloc(SIZE_T size);
};


class CGlobalLock
{
  HGLOBAL m_Global;
  LPVOID m_Pointer;
public:
  LPVOID GetPointer() const { return m_Pointer; }
  CGlobalLock(HGLOBAL hGlobal): m_Global(hGlobal)
  {
    m_Pointer = ::GlobalLock(hGlobal); 
  };
  ~CGlobalLock()
  {
    if(m_Pointer != NULL)
      ::GlobalUnlock(m_Global);
  }
};

}}

#endif