]> git.saurik.com Git - wxWidgets.git/commitdiff
extracted code calling {Ole|Co}[Un]Initialize() to wxOle[Un]Initialize() functions...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 11 Mar 2005 11:47:13 +0000 (11:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 11 Mar 2005 11:47:13 +0000 (11:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/ole/oleutils.h
src/msw/app.cpp

index 9dc4716278296bcdb0932728dc088a8c31ddf2b8..399a39f269bd46e4a5fdbdc90750bcf8a4da4600 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "wx/defs.h"
 
+#if wxUSE_OLE
+
 // get IUnknown, REFIID &c
 #include <ole2.h>
 
 // General purpose functions and macros
 // ============================================================================
 
+// ----------------------------------------------------------------------------
+// initialize/cleanup OLE
+// ----------------------------------------------------------------------------
+
+// call OleInitialize() or CoInitialize[Ex]() depending on the platform
+//
+// return true if ok, false otherwise
+inline bool wxOleInitialize()
+{
+    // we need to initialize OLE library
+#ifdef __WXWINCE__
+    if ( FAILED(::CoInitializeEx(NULL, COINIT_MULTITHREADED)) )
+#else
+    if ( FAILED(::OleInitialize(NULL)) )
+#endif
+    {
+        wxLogError(_("Cannot initialize OLE"));
+
+        return false;
+    }
+
+    return true;
+}
+
+inline void wxOleUninitialize()
+{
+#ifdef __WXWINCE__
+    ::CoUninitialize();
+#else
+    ::OleUninitialize();
+#endif
+}
+
 // ----------------------------------------------------------------------------
 // misc helper functions/macros
 // ----------------------------------------------------------------------------
@@ -205,6 +240,16 @@ BSTR wxConvertStringToOle(const wxString& str);
 // Convert string from BSTR to wxString
 wxString wxConvertStringFromOle(BSTR bStr);
 
+#else // !wxUSE_OLE
+
+// ----------------------------------------------------------------------------
+// stub functions to avoid #if wxUSE_OLE in the main code
+// ----------------------------------------------------------------------------
+
+inline bool wxOleInitialize() { return false; }
+inline void wxOleUninitialize() { }
+
+#endif // wxUSE_OLE/!wxUSE_OLE
 
 #endif  //_WX_OLEUTILS_H
 
index 2cf9c66e86c8e539d36afb527091a831a5a124c1..b399d62aaa7bb573d2b76fce8f1d6f2075506261 100644 (file)
@@ -54,6 +54,7 @@
 #include "wx/dynlib.h"
 
 #include "wx/msw/private.h"
+#include "wx/msw/ole/oleutils.h"
 
 #if wxUSE_TOOLTIPS
     #include "wx/tooltip.h"
@@ -299,20 +300,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
     InitCommonControls();
 #endif // __WIN95__
 
-#if wxUSE_OLE || wxUSE_DRAG_AND_DROP
-
-#if wxUSE_OLE
-    // we need to initialize OLE library
-#ifdef __WXWINCE__
-    if ( FAILED(::CoInitializeEx(NULL, COINIT_MULTITHREADED)) )
-        wxLogError(_("Cannot initialize OLE"));
-#else
-    if ( FAILED(::OleInitialize(NULL)) )
-        wxLogError(_("Cannot initialize OLE"));
-#endif
-#endif
-
-#endif // wxUSE_OLE
+    wxOleInitialize();
 
     RegisterWindowClasses();
 
@@ -489,13 +477,7 @@ void wxApp::CleanUp()
     wxCleanUpPenWin();
 #endif
 
-#if wxUSE_OLE
-#ifdef __WXWINCE__
-    ::CoUninitialize();
-#else
-    ::OleUninitialize();
-#endif
-#endif
+    wxOleUninitialize();
 
     // for an EXE the classes are unregistered when it terminates but DLL may
     // be loaded several times (load/unload/load) into the same process in