- 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);
- }
-#if wxUSE_DATETIME
- else if (type == wxT("datetime"))
- {
- wxDateTime date( variant.GetDateTime() );
- oleVariant.vt = VT_DATE;
-
- long dosDateTime = date.GetAsDOS();
- short dosDate = short((dosDateTime & 0xFFFF0000) >> 16);
- short dosTime = short(dosDateTime & 0xFFFF);
-
- DosDateTimeToVariantTime(dosDate, dosTime, & oleVariant.date);
- }
-#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;