blob: 1984baf6a660b3f102d8bcab49d84eb24c73cbee (
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
46
47
48
49
50
51
52
53
|
// 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() { Free(); }
operator HGLOBAL() const { return m_MemoryHandle; };
void Attach(HGLOBAL hGlobal)
{
Free();
m_MemoryHandle = hGlobal;
}
HGLOBAL Detach()
{
HGLOBAL h = m_MemoryHandle;
m_MemoryHandle = NULL;
return h;
}
bool Alloc(UINT flags, SIZE_T size);
bool Free();
LPVOID Lock() const { return GlobalLock(m_MemoryHandle); }
void Unlock() const { GlobalUnlock(m_MemoryHandle); }
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
|