+namespace
+{
+
+HRESULT wxCLSIDFromProgID(const wxString& progId, CLSID& clsId)
+{
+ HRESULT hr = CLSIDFromProgID(wxBasicString(progId), &clsId);
+ if ( FAILED(hr) )
+ {
+ wxLogSysError(hr, _("Failed to find CLSID of \"%s\""), progId);
+ }
+ return hr;
+}
+
+void *DoCreateInstance(const wxString& progId, const CLSID& clsId)
+{
+ // get the server IDispatch interface
+ //
+ // NB: using CLSCTX_INPROC_HANDLER results in failure when getting
+ // Automation interface for Microsoft Office applications so don't use
+ // CLSCTX_ALL which includes it
+ void *pDispatch = NULL;
+ HRESULT hr = CoCreateInstance(clsId, NULL, CLSCTX_SERVER,
+ IID_IDispatch, &pDispatch);
+ if (FAILED(hr))
+ {
+ wxLogSysError(hr, _("Failed to create an instance of \"%s\""), progId);
+ return NULL;
+ }
+
+ return pDispatch;
+}
+
+} // anonymous namespace
+