From 1368d4c0c5bdc0ba527fda7c5444313f8f061ad0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 29 Aug 2014 23:22:39 +0000 Subject: [PATCH] Add small wxOleInitializer RAII helper. Wrap wxOleInitialize()/wxOleUninitialize() in a helper class ensuring that we never forget to call the latter. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@77513 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/ole/oleutils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/wx/msw/ole/oleutils.h b/include/wx/msw/ole/oleutils.h index c9f7eb88c8..4450d77d6f 100644 --- a/include/wx/msw/ole/oleutils.h +++ b/include/wx/msw/ole/oleutils.h @@ -354,4 +354,30 @@ inline void wxOleUninitialize() { } #endif // wxUSE_OLE/!wxUSE_OLE +// RAII class initializing OLE in its ctor and undoing it in its dtor. +class wxOleInitializer +{ +public: + wxOleInitializer() + : m_ok(wxOleInitialize()) + { + } + + bool IsOk() const + { + return m_ok; + } + + ~wxOleInitializer() + { + if ( m_ok ) + wxOleUninitialize(); + } + +private: + const bool m_ok; + + wxDECLARE_NO_COPY_CLASS(wxOleInitializer); +}; + #endif //_WX_OLEUTILS_H