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 8namespace NWindows { 9namespace NMemory { 10 11class CGlobal 12{ 13 HGLOBAL _global; 14public: 15 CGlobal(): _global(NULL) {} 16 ~CGlobal() { Free(); } 17 operator HGLOBAL() const { return _global; } 18 void Attach(HGLOBAL hGlobal) 19 { 20 Free(); 21 _global = hGlobal; 22 } 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(); 31 LPVOID Lock() const { return GlobalLock(_global); } 32 void Unlock() const { GlobalUnlock(_global); } 33 bool ReAlloc(SIZE_T size) throw(); 34}; 35 36class CGlobalLock 37{ 38 HGLOBAL _global; 39 LPVOID _ptr; 40public: 41 LPVOID GetPointer() const { return _ptr; } 42 CGlobalLock(HGLOBAL hGlobal): _global(hGlobal) 43 { 44 _ptr = GlobalLock(hGlobal); 45 } 46 ~CGlobalLock() 47 { 48 if (_ptr) 49 GlobalUnlock(_global); 50 } 51}; 52 53}} 54 55#endif 56