added GlobalPtr: GlobalAlloc/Free() wrapper

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34983 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2005-07-29 12:18:17 +00:00
parent c9e4ece63a
commit 2be57a5131

View File

@ -535,6 +535,33 @@ private:
DECLARE_NO_COPY_CLASS(HDCClipper)
};
// smart buffeer using GlobalAlloc/GlobalFree()
class GlobalPtr
{
public:
// allocates a block of given size
GlobalPtr(size_t size, unsigned flags = GMEM_MOVEABLE)
{
m_hGlobal = ::GlobalAlloc(flags, size);
if ( !m_hGlobal )
wxLogLastError(_T("GlobalAlloc"));
}
~GlobalPtr()
{
if ( m_hGlobal && ::GlobalFree(m_hGlobal) )
wxLogLastError(_T("GlobalFree"));
}
// implicit conversion
operator HGLOBAL() const { return m_hGlobal; }
private:
HGLOBAL m_hGlobal;
DECLARE_NO_COPY_CLASS(GlobalPtr)
};
// when working with global pointers (which is unfortunately still necessary
// sometimes, e.g. for clipboard) it is important to unlock them exactly as
// many times as we lock them which just asks for using a "smart lock" class