From a395cd5d1420ad9a74125de79a230ba0f8a5826c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 29 Aug 2014 23:21:56 +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/trunk@77507 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 521366b9f0..5bc5e19dfe 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