- ClearVariant(&oleVariant);
- if (variant.IsNull())
- {
- oleVariant.vt = VT_NULL;
- return true;
- }
-
- wxString type(variant.GetType());
-
-
- if (type == wxT("long"))
- {
- oleVariant.vt = VT_I4;
- oleVariant.lVal = variant.GetLong() ;
- }
- // cVal not always present
-#ifndef __GNUWIN32__
- else if (type == wxT("char"))
- {
- oleVariant.vt=VT_I1; // Signed Char
- oleVariant.cVal=variant.GetChar();
- }
-#endif
- else if (type == wxT("double"))
- {
- oleVariant.vt = VT_R8;
- oleVariant.dblVal = variant.GetDouble();
- }
- else if (type == wxT("bool"))
- {
- oleVariant.vt = VT_BOOL;
- // 'bool' required for VC++ 4 apparently
-#if (defined(__VISUALC__) && (__VISUALC__ <= 1000))
- oleVariant.bool = variant.GetBool();
-#else
- oleVariant.boolVal = variant.GetBool();
-#endif
- }
- else if (type == wxT("string"))
- {
- wxString str( variant.GetString() );
- oleVariant.vt = VT_BSTR;
- oleVariant.bstrVal = wxConvertStringToOle(str);
- }
-// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
-// Now obsolete
-#if 0 // wxUSE_TIMEDATE && !defined(__WATCOMC__)
- else if (type == wxT("date"))
- {
- wxDate date( variant.GetDate() );
- oleVariant.vt = VT_DATE;
-
- if (!OleDateFromTm(date.GetYear(), date.GetMonth(), date.GetDay(),
- 0, 0, 0, oleVariant.date))
- return false;
- }
- else if (type == wxT("time"))
- {
- wxTime time( variant.GetTime() );
- oleVariant.vt = VT_DATE;
-
- if (!OleDateFromTm(time.GetYear(), time.GetMonth(), time.GetDay(),
- time.GetHour(), time.GetMinute(), time.GetSecond(), oleVariant.date))
- return false;
- }
-#endif
-#if wxUSE_DATETIME
- else if (type == wxT("datetime"))
- {
- wxDateTime date( variant.GetDateTime() );
- oleVariant.vt = VT_DATE;
-
- if (!OleDateFromTm(date.GetYear(), date.GetMonth(), date.GetDay(),
- date.GetHour(), date.GetMinute(), date.GetSecond(), oleVariant.date))
- return false;
- }
-#endif
- else if (type == wxT("void*"))
- {
- oleVariant.vt = VT_DISPATCH;
- oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr();
- }
- else if (type == wxT("list") || type == wxT("stringlist"))
- {
- oleVariant.vt = VT_VARIANT | VT_ARRAY;
-
- SAFEARRAY *psa;
- SAFEARRAYBOUND saBound;
- VARIANTARG *pvargBase;
- VARIANTARG *pvarg;
- int i, j;
-
- int iCount = variant.GetCount();
-
- saBound.lLbound = 0;
- saBound.cElements = iCount;
-
- psa = SafeArrayCreate(VT_VARIANT, 1, &saBound);
- if (psa == NULL)
- return false;
-
- SafeArrayAccessData(psa, (void**)&pvargBase);
-
- pvarg = pvargBase;
- for (i = 0; i < iCount; i++)
- {
- // copy each string in the list of strings
- wxVariant eachVariant(variant[i]);
- if (!wxConvertVariantToOle(eachVariant, * pvarg))
- {
- // memory failure: back out and free strings alloc'ed up to
- // now, and then the array itself.
- pvarg = pvargBase;
- for (j = 0; j < i; j++)
- {
- SysFreeString(pvarg->bstrVal);
- pvarg++;
- }
- SafeArrayDestroy(psa);
- return false;
- }
- pvarg++;
- }
-
- SafeArrayUnaccessData(psa);
-
- oleVariant.parray = psa;
- }
- else
- {
- oleVariant.vt = VT_NULL;