]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/msw/ole/oleutils.h
Applied patch for ArtProvider.
[wxWidgets.git] / include / wx / msw / ole / oleutils.h
index 9dc4716278296bcdb0932728dc088a8c31ddf2b8..b43624bee2caa62cef0bf65c48bf720649f33cdf 100644 (file)
 
 #include "wx/defs.h"
 
+#if wxUSE_OLE
+
 // get IUnknown, REFIID &c
 #include <ole2.h>
+#include "wx/intl.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 +241,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