]> git.saurik.com Git - wxWidgets.git/commitdiff
added GlobalPtr: GlobalAlloc/Free() wrapper
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 12:18:17 +0000 (12:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 12:18:17 +0000 (12:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34983 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/private.h

index 73c03ad10ca23121690c609d5303bf4c4ade2a58..f165bf13e80c71ae0a375d480039b967488b28a0 100644 (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