xref: /aosp_15_r20/external/lzma/CPP/Windows/MemoryGlobal.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Windows/MemoryGlobal.h
2 
3 #ifndef ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H
4 #define ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H
5 
6 #include "../Common/MyWindows.h"
7 
8 namespace NWindows {
9 namespace NMemory {
10 
11 class CGlobal
12 {
13   HGLOBAL _global;
14 public:
CGlobal()15   CGlobal(): _global(NULL) {}
~CGlobal()16   ~CGlobal() { Free(); }
HGLOBAL()17   operator HGLOBAL() const { return _global; }
Attach(HGLOBAL hGlobal)18   void Attach(HGLOBAL hGlobal)
19   {
20     Free();
21     _global = hGlobal;
22   }
Detach()23   HGLOBAL Detach()
24   {
25     const HGLOBAL h = _global;
26     _global = NULL;
27     return h;
28   }
29   bool Alloc(UINT flags, SIZE_T size) throw();
30   bool Free() throw();
Lock()31   LPVOID Lock() const { return GlobalLock(_global); }
Unlock()32   void Unlock() const { GlobalUnlock(_global); }
33   bool ReAlloc(SIZE_T size) throw();
34 };
35 
36 class CGlobalLock
37 {
38   HGLOBAL _global;
39   LPVOID _ptr;
40 public:
GetPointer()41   LPVOID GetPointer() const { return _ptr; }
CGlobalLock(HGLOBAL hGlobal)42   CGlobalLock(HGLOBAL hGlobal): _global(hGlobal)
43   {
44     _ptr = GlobalLock(hGlobal);
45   }
~CGlobalLock()46   ~CGlobalLock()
47   {
48     if (_ptr)
49       GlobalUnlock(_global);
50   }
51 };
52 
53 }}
54 
55 #endif
56