]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/ole/automtn.cpp
Output the extracted number from wxString::ToXXX() even if it returns false.
[wxWidgets.git] / src / msw / ole / automtn.cpp
index 3ca89f3231cc7576017cc6212396e637c6f64b4e..31348b791a723686905918a67a14491bf59641cf 100644 (file)
@@ -159,7 +159,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action,
     {
         namedArgCount = 1;
         dispIds[1] = DISPID_PROPERTYPUT;
-        vReturnPtr = (VARIANTARG*) NULL;
+        vReturnPtr = NULL;
     }
 
     // Convert the wxVariants to VARIANTARGs
@@ -220,7 +220,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action,
             // Mustn't release the dispatch pointer
             if (vReturn.vt == VT_DISPATCH)
             {
-                vReturn.pdispVal = (IDispatch*) NULL;
+                vReturn.pdispVal = NULL;
             }
             ReleaseVariant(& vReturn);
         }
@@ -440,7 +440,7 @@ WXIDISPATCH* wxAutomationObject::GetDispatchProperty(const wxString& property, i
         }
     }
 
-    return (WXIDISPATCH*) NULL;
+    return NULL;
 }
 
 // Uses DISPATCH_PROPERTYGET
@@ -458,7 +458,7 @@ WXIDISPATCH* wxAutomationObject::GetDispatchProperty(const wxString& property, i
         }
     }
 
-    return (WXIDISPATCH*) NULL;
+    return NULL;
 }
 
 
@@ -538,8 +538,13 @@ bool wxAutomationObject::CreateInstance(const wxString& classId) const
         return false;
     }
 
-    // start a new copy of Excel, grab the IDispatch interface
-    if (FAILED(CoCreateInstance(clsId, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**)&m_dispatchPtr)))
+    // 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
+    if (FAILED(CoCreateInstance(clsId, NULL, CLSCTX_SERVER, IID_IDispatch,
+                                (void**)&m_dispatchPtr)))
     {
         wxLogWarning(wxT("Cannot start an instance of this class."));
         return false;
@@ -677,7 +682,6 @@ wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
     bool ok = true;
     if ( oleVariant.vt & VT_ARRAY )
     {
-        variant.ClearList();
 
         // Compute the total number of elements in all array dimensions
         int cElements = 1;
@@ -685,23 +689,53 @@ wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
             cElements *= oleVariant.parray->rgsabound[cDims].cElements;
 
         // Get a pointer to the data
-        VARIANTARG* pvdata;
-        HRESULT hr = SafeArrayAccessData(oleVariant.parray, (void **)&pvdata);
+        void* pvdata;
+        HRESULT hr = SafeArrayAccessData(oleVariant.parray, &pvdata);
         if ( FAILED(hr) )
             return false;
 
-        for ( int i = 0; i < cElements; i++ )
+        switch (oleVariant.vt & VT_TYPEMASK)
         {
-            VARIANTARG& oleElement = pvdata[i];
-            wxVariant vElement;
-            if ( !wxConvertOleToVariant(oleElement, vElement) )
-            {
-                ok = false;
-                variant.ClearList();
+            case VT_VARIANT:
+                {
+                    variant.ClearList();
+                    VARIANTARG *variant_data=(VARIANTARG*)pvdata;
+                    for ( int i = 0; i < cElements; i++ )
+                    {
+                        VARIANTARG& oleElement = variant_data[i];
+                        wxVariant vElement;
+                        if ( !wxConvertOleToVariant(oleElement, vElement) )
+                        {
+                            ok = false;
+                            variant.ClearList();
+                            break;
+                        }
+
+                        variant.Append(vElement);
+                    }
+                }
+                break;
+
+            case VT_BSTR:
+                {
+                    wxArrayString strings;
+                    BSTR *string_val=(BSTR*)pvdata;
+                    for ( int i = 0; i < cElements; ++i )
+                    {
+                        wxString str=wxConvertStringFromOle(*string_val);
+                        strings.Add(str);
+                        ++string_val;
+                    }
+                    variant=strings;
+                }
                 break;
-            }
 
-            variant.Append(vElement);
+            default:
+                wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"),
+                           oleVariant.vt & VT_TYPEMASK);
+                variant = wxVariant();
+                ok = false;
+                break;
         }
 
         SafeArrayUnaccessData(oleVariant.parray);
@@ -719,23 +753,25 @@ wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
                 }
 
             default:
-                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),oleVariant.vt);
+                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),
+                            oleVariant.vt);
                 return false;
         }
     }
     else // simply type (not array or reference)
     {
-        switch (oleVariant.vt & VT_TYPEMASK)
+        switch ( oleVariant.vt & VT_TYPEMASK )
         {
             case VT_BSTR:
                 {
                     wxString str(wxConvertStringFromOle(oleVariant.bstrVal));
                     variant = str;
-                    break;
                 }
+                break;
+
             case VT_DATE:
-                {
 #if wxUSE_DATETIME
+                {
                     unsigned short dosDate = 0;
                     unsigned short dosTime = 0;
                     VariantTimeToDosDateTime(oleVariant.date, & dosDate, & dosTime);
@@ -744,61 +780,41 @@ wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
                     wxDateTime date;
                     date.SetFromDOS(dosDateTime);
                     variant = date;
-#endif
-                    break;
                 }
+#endif // wxUSE_DATETIME
+                break;
+
             case VT_I4:
-                {
-                    variant = (long) oleVariant.lVal;
-                    break;
-                }
+                variant = (long) oleVariant.lVal;
+                break;
+
             case VT_I2:
-                {
-                    variant = (long) oleVariant.iVal;
-                    break;
-                }
+                variant = (long) oleVariant.iVal;
+                break;
 
             case VT_BOOL:
-                {
-#if (defined(_MSC_VER) && (_MSC_VER <= 1000) && !defined(__MWERKS__) ) //GC
-#ifndef HAVE_BOOL // Can't use bool operator if no native bool type
-                    variant = (long) (oleVariant.bool != 0);
-#else
-                    variant = (bool) (oleVariant.bool != 0);
-#endif
-#else
-#ifndef HAVE_BOOL // Can't use bool operator if no native bool type
-                    variant = (long) (oleVariant.boolVal != 0);
-#else
-                    variant = (bool) (oleVariant.boolVal != 0);
-#endif
-#endif
-                    break;
-                }
+                variant = oleVariant.boolVal != 0;
+                break;
+
             case VT_R8:
-                {
-                    variant = oleVariant.dblVal;
-                    break;
-                }
+                variant = oleVariant.dblVal;
+                break;
+
             case VT_DISPATCH:
-                {
-                    variant = (void*) oleVariant.pdispVal;
-                    break;
-                }
+                variant = (void*) oleVariant.pdispVal;
+                break;
+
             case VT_NULL:
-                {
-                    variant.MakeNull();
-                    break;
-                }
+                variant.MakeNull();
+                break;
+
             case VT_EMPTY:
-                {
-                    break;    // Ignore Empty Variant, used only during destruction of objects
-                }
+                break;    // Ignore Empty Variant, used only during destruction of objects
+
             default:
-                {
-                    wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
-                    return false;
-                }
+                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),
+                           oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
+                return false;
         }
     }
 
@@ -886,6 +902,7 @@ static void ReleaseVariant(VARIANTARG *pvarg)
             case VT_R8:
             case VT_ERROR:        // to avoid erroring on an error return from Excel
             case VT_EMPTY:
+            case VT_DATE:
                 // no work for these types
                 break;