aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/MemoryGlobal.h
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/Windows/MemoryGlobal.h')
-rw-r--r--CPP/Windows/MemoryGlobal.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/CPP/Windows/MemoryGlobal.h b/CPP/Windows/MemoryGlobal.h
new file mode 100644
index 0000000..c217510
--- /dev/null
+++ b/CPP/Windows/MemoryGlobal.h
@@ -0,0 +1,55 @@
1// Windows/MemoryGlobal.h
2
3#ifndef __WINDOWS_MEMORY_GLOBAL_H
4#define __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 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 != NULL)
49 GlobalUnlock(_global);
50 }
51};
52
53}}
54
55#endif