WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) { VariantInit(&oleVariant); if (variant.IsNull()) { oleVariant.vt = VT_NULL; return true; } wxString type(variant.GetType()); if (type == wxT("errorcode")) { wxVariantDataErrorCode* const ec = wxStaticCastVariantData(variant.GetData(), wxVariantDataErrorCode); oleVariant.vt = VT_ERROR; oleVariant.scode = ec->GetValue(); } else if (type == wxT("currency")) { wxVariantDataCurrency* const c = wxStaticCastVariantData(variant.GetData(), wxVariantDataCurrency); oleVariant.vt = VT_CY; oleVariant.cyVal = c->GetValue(); } else if (type == wxT("safearray")) { wxVariantDataSafeArray* const vsa = wxStaticCastVariantData(variant.GetData(), wxVariantDataSafeArray); SAFEARRAY* psa = vsa->GetValue(); VARTYPE vt; wxCHECK(psa, false); HRESULT hr = SafeArrayGetVartype(psa, &vt); if ( FAILED(hr) ) { wxLogApiError(wxS("SafeArrayGetVartype()"), hr); SafeArrayDestroy(psa); return false; } oleVariant.vt = vt | VT_ARRAY; oleVariant.parray = psa; } else if (type == wxT("long")) { oleVariant.vt = VT_I4; oleVariant.lVal = variant.GetLong() ; } // Original VC6 came with SDK too old to contain VARIANT::llVal declaration // and there doesn't seem to be any way to test for it as Microsoft simply // added it to the later version of oaidl.h without changing anything else. // So assume it's not present for VC6, even though it might be if an // updated SDK is used. In this case the user would need to disable this // check himself. #if wxUSE_LONGLONG && !defined(__VISUALC6__) else if (type == wxT("longlong")) { oleVariant.vt = VT_I8; oleVariant.llVal = variant.GetLongLong().GetValue(); } #endif else if (type == wxT("char")) { oleVariant.vt=VT_I1; // Signed Char oleVariant.cVal=variant.GetChar(); } else if (type == wxT("double")) { oleVariant.vt = VT_R8; oleVariant.dblVal = variant.GetDouble(); } else if (type == wxT("bool")) { oleVariant.vt = VT_BOOL; oleVariant.boolVal = variant.GetBool() ? VARIANT_TRUE : VARIANT_FALSE; } 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; SYSTEMTIME st; date.GetAsMSWSysTime(&st); SystemTimeToVariantTime(&st, &oleVariant.date); } #endif else if (type == wxT("void*")) { oleVariant.vt = VT_DISPATCH; oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr(); } else if (type == wxT("list")) { wxSafeArray<VT_VARIANT> safeArray; if (!safeArray.CreateFromListVariant(variant)) return false; oleVariant.vt = VT_VARIANT | VT_ARRAY; oleVariant.parray = safeArray.Detach(); } else if (type == wxT("arrstring")) { wxSafeArray<VT_BSTR> safeArray; if (!safeArray.CreateFromArrayString(variant.GetArrayString())) return false; oleVariant.vt = VT_BSTR | VT_ARRAY; oleVariant.parray = safeArray.Detach(); } else { oleVariant.vt = VT_NULL; return false; } return true; }
WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) { VariantInit(&oleVariant); if (variant.IsNull()) { oleVariant.vt = VT_NULL; return true; } wxString type(variant.GetType()); if (type == wxT("errorcode")) { wxVariantDataErrorCode* const ec = wxStaticCastVariantData(variant.GetData(), wxVariantDataErrorCode); oleVariant.vt = VT_ERROR; oleVariant.scode = ec->GetValue(); } else if (type == wxT("currency")) { wxVariantDataCurrency* const c = wxStaticCastVariantData(variant.GetData(), wxVariantDataCurrency); oleVariant.vt = VT_CY; oleVariant.cyVal = c->GetValue(); } else if (type == wxT("safearray")) { wxVariantDataSafeArray* const vsa = wxStaticCastVariantData(variant.GetData(), wxVariantDataSafeArray); SAFEARRAY* psa = vsa->GetValue(); VARTYPE vt; wxCHECK(psa, false); HRESULT hr = SafeArrayGetVartype(psa, &vt); if ( FAILED(hr) ) { wxLogApiError(wxS("SafeArrayGetVartype()"), hr); SafeArrayDestroy(psa); return false; } oleVariant.vt = vt | VT_ARRAY; oleVariant.parray = psa; } else if (type == wxT("long")) { oleVariant.vt = VT_I4; oleVariant.lVal = variant.GetLong() ; } #if wxUSE_LONGLONG else if (type == wxT("longlong")) { oleVariant.vt = VT_I8; oleVariant.llVal = variant.GetLongLong().GetValue(); } #endif else if (type == wxT("char")) { oleVariant.vt=VT_I1; // Signed Char oleVariant.cVal=variant.GetChar(); } else if (type == wxT("double")) { oleVariant.vt = VT_R8; oleVariant.dblVal = variant.GetDouble(); } else if (type == wxT("bool")) { oleVariant.vt = VT_BOOL; oleVariant.boolVal = variant.GetBool() ? VARIANT_TRUE : VARIANT_FALSE; } 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; SYSTEMTIME st; date.GetAsMSWSysTime(&st); SystemTimeToVariantTime(&st, &oleVariant.date); } #endif else if (type == wxT("void*")) { oleVariant.vt = VT_DISPATCH; oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr(); } else if (type == wxT("list")) { wxSafeArray<VT_VARIANT> safeArray; if (!safeArray.CreateFromListVariant(variant)) return false; oleVariant.vt = VT_VARIANT | VT_ARRAY; oleVariant.parray = safeArray.Detach(); } else if (type == wxT("arrstring")) { wxSafeArray<VT_BSTR> safeArray; if (!safeArray.CreateFromArrayString(variant.GetArrayString())) return false; oleVariant.vt = VT_BSTR | VT_ARRAY; oleVariant.parray = safeArray.Detach(); } else { oleVariant.vt = VT_NULL; return false; } return true; }
WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) { VariantInit(&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() ; } else if (type == wxT("char")) { oleVariant.vt=VT_I1; // Signed Char oleVariant.cVal=variant.GetChar(); } else if (type == wxT("double")) { oleVariant.vt = VT_R8; oleVariant.dblVal = variant.GetDouble(); } else if (type == wxT("bool")) { oleVariant.vt = VT_BOOL; oleVariant.boolVal = variant.GetBool(); } 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; SYSTEMTIME st; date.GetAsMSWSysTime(&st); SystemTimeToVariantTime(&st, &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; return false; } return true; }
void GEUIDialog::GEShowBoat(double lat, double lon) { LogDebugMessage(wxString::Format(_T("Show boat at %f, %f requested"), lat, lon)); if ( m_bbusy ) { LogDebugMessage(_T("Not showing, busy")); return; } int interval = m_stopwatch_boat.Time(); if (interval < CAMERA_MOVE_INTERVAL * 5) // If it is less than CAMERA_MOVE_INTERVAL * 5 since last request, don't move the boat { LogDebugMessage(_T("Boat display request discarded, too soon after a previous action")); return; } m_stopwatch_boat.Start(); if (m_pPositions->GetCount() > BOAT_POSITIONS_STORED) m_pPositions->Erase(m_pPositions->GetFirst()); m_pPositions->Append(new PositionReport(lat, lon, wxDateTime::Now())); wxTextFile kml(m_sLiveKmlFilename); if(wxFile::Exists(m_sLiveKmlFilename)) { kml.Open(); kml.Clear(); } else { kml.Create(); } wxString coords; wxPositionsListNode *posn = m_pPositions->GetFirst(); do { coords += wxString::Format(_T("%f,%f,0.000000\n"), posn->GetData()->longitude, posn->GetData()->latitude); } while (posn = posn->GetNext()); if (pPlugIn->ShouldShowBoat()) kml.AddLine(wxString::Format(LiveKml, 1, lon, lat, 1, coords)); else kml.AddLine(wxString::Format(LiveKml, 0, lon, lat, 0, coords)); kml.Write(); kml.Close(); if(NULL != app && m_bgeisuseable) { if (!m_bisfollowingboat && pPlugIn->ShouldShowBoat()) { if(wxFile::Exists(m_sEnvelopeKmlFilename)) wxRemoveFile(m_sEnvelopeKmlFilename); wxTextFile kml(m_sEnvelopeKmlFilename); kml.Create(); kml.AddLine(wxString::Format(EnvelopeKml, m_sLiveKmlFilename)); kml.Write(); kml.Close(); BSTR pdata = wxConvertStringToOle(m_sEnvelopeKmlFilename); m_bbusy = true; app->OpenKmlFile(pdata, 1); m_bisfollowingboat = true; } else if (m_bisfollowingboat && !pPlugIn->ShouldShowBoat()) { if(wxFile::Exists(m_sEnvelopeKmlFilename)) wxRemoveFile(m_sEnvelopeKmlFilename); wxTextFile kml(m_sEnvelopeKmlFilename); kml.Create(); kml.AddLine(EmptyKml); kml.Write(); kml.Close(); BSTR pdata = wxConvertStringToOle(m_sEnvelopeKmlFilename); m_bbusy = true; app->OpenKmlFile(pdata, 1); m_bisfollowingboat = false; } /* IFeatureGE* tp; app->raw_GetTemporaryPlaces(&tp); if ( tp ) { IFeatureCollectionGE* tps; tp->raw_GetChildren(&tps); if ( tps && tps->GetCount() > 0 ) { //for (int i = 0; i < tps->Count; i++) //{ // tps->Item[i]->PutVisibility(0); //} try { //FIXME: This works, BUT GE consumes enormous amounts of memory - really there is no way to change the properties of existing waypoint? //Looks like ther isn't, so some trick like from http://groups.google.com/group/kml-support-com-api/browse_thread/thread/76c9f9f3ab5ff28f/4244ff5df01c5c25?lnk=gst&q=temporary+places# and http://bbs.keyhole.com/ubb/ubbthreads.php?ubb=showflat&Number=816832&site_id=1#import will be necessary //Tutorial: http://code.google.com/intl/cs/apis/kml/documentation/kml_21tutorial.html#updates tps->GetItem(tps->GetCount() - 1)->PutVisibility(false); } catch (...) {} } } wxString kml = wxString::Format(_T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://earth.google.com/kml/2.0\">\n<Placemark>\n <name>BOAT</name>\n <visibility>1</visibility>\n <Style>\n <IconStyle>\n <Icon>\n <href>root://icons/palette-4.png</href>\n <x>32</x>\n <y>0</y>\n <w>32</w>\n <h>32</h>\n </Icon>\n </IconStyle>\n </Style>\n <Point>\n <extrude>1</extrude>\n <altitudeMode>relativeToGround</altitudeMode>\n <coordinates>%f,%f,0</coordinates>\n </Point>\n</Placemark>\n</kml>"), lon, lat); BSTR pdata = wxConvertStringToOle(kml); try { app->LoadKmlData(&pdata); LogDebugMessage(_T("Shown")); } catch (...) { LogDebugMessage(_T("There was an error showing the boat")); } */ } m_bbusy = false; }
WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) { VariantInit(&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() ; } // Original VC6 came with SDK too old to contain VARIANT::llVal declaration // and there doesn't seem to be any way to test for it as Microsoft simply // added it to the later version of oaidl.h without changing anything else. // So assume it's not present for VC6, even though it might be if an // updated SDK is used. In this case the user would need to disable this // check himself. #if wxUSE_LONGLONG && !defined(__VISUALC6__) else if (type == wxT("longlong")) { oleVariant.vt = VT_I8; oleVariant.llVal = variant.GetLongLong().GetValue(); } #endif else if (type == wxT("char")) { oleVariant.vt=VT_I1; // Signed Char oleVariant.cVal=variant.GetChar(); } else if (type == wxT("double")) { oleVariant.vt = VT_R8; oleVariant.dblVal = variant.GetDouble(); } else if (type == wxT("bool")) { oleVariant.vt = VT_BOOL; oleVariant.boolVal = variant.GetBool() ? VARIANT_TRUE : VARIANT_FALSE; } 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; SYSTEMTIME st; date.GetAsMSWSysTime(&st); SystemTimeToVariantTime(&st, &oleVariant.date); } #endif else if (type == wxT("void*")) { oleVariant.vt = VT_DISPATCH; oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr(); } else if (type == wxT("list")) { wxSafeArrayHelper sah; if (!sah.Create(VT_VARIANT, variant.GetCount())) return false; for (size_t i = 0; i < variant.GetCount(); i++) { if (!sah.SetElement(i, variant[i])) return false; } oleVariant.vt = VT_VARIANT | VT_ARRAY; oleVariant.parray = sah.Detach(); } else if (type == wxT("arrstring")) { wxArrayString strings(variant.GetArrayString()); wxSafeArrayHelper sah; if (!sah.Create(VT_BSTR, strings.GetCount())) return false; for (size_t i = 0; i < strings.GetCount(); i++) { if (!sah.SetElement(i, strings[i])) return false; } oleVariant.vt = VT_BSTR | VT_ARRAY; oleVariant.parray = sah.Detach(); } else { oleVariant.vt = VT_NULL; return false; } return true; }
// For Put/Get, no named arguments are allowed. bool wxAutomationObject::Invoke(const wxString& member, int action, wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[]) const { if (!m_dispatchPtr) return false; int ch = member.Find('.'); if (ch != -1) { // Use dot notation to get the next object wxString member2(member.Left((size_t) ch)); wxString rest(member.Right(member.length() - ch - 1)); wxAutomationObject obj; if (!GetObject(obj, member2)) return false; return obj.Invoke(rest, action, retValue, noArgs, args, ptrArgs); } VARIANTARG vReturn; VariantInit(& vReturn); VARIANTARG* vReturnPtr = & vReturn; // Find number of names args int namedArgCount = 0; int i; for (i = 0; i < noArgs; i++) if ( !INVOKEARG(i).GetName().empty() ) { namedArgCount ++; } int namedArgStringCount = namedArgCount + 1; BSTR* argNames = new BSTR[namedArgStringCount]; argNames[0] = wxConvertStringToOle(member); // Note that arguments are specified in reverse order // (all totally logical; hey, we're dealing with OLE here.) int j = 0; for (i = 0; i < namedArgCount; i++) { if ( !INVOKEARG(i).GetName().empty() ) { argNames[(namedArgCount-j)] = wxConvertStringToOle(INVOKEARG(i).GetName()); j ++; } } // + 1 for the member name, + 1 again in case we're a 'put' DISPID* dispIds = new DISPID[namedArgCount + 2]; HRESULT hr; DISPPARAMS dispparams; unsigned int uiArgErr; // Get the IDs for the member and its arguments. GetIDsOfNames expects the // member name as the first name, followed by argument names (if any). hr = ((IDispatch*)m_dispatchPtr)->GetIDsOfNames(IID_NULL, argNames, 1 + namedArgCount, LOCALE_SYSTEM_DEFAULT, dispIds); if (FAILED(hr)) { ShowException(member, hr); delete[] argNames; delete[] dispIds; return false; } // if doing a property put(ref), we need to adjust the first argument to have a // named arg of DISPID_PROPERTYPUT. if (action & (DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF)) { namedArgCount = 1; dispIds[1] = DISPID_PROPERTYPUT; vReturnPtr = NULL; } // Convert the wxVariants to VARIANTARGs VARIANTARG* oleArgs = new VARIANTARG[noArgs]; for (i = 0; i < noArgs; i++) { // Again, reverse args if (!wxConvertVariantToOle(INVOKEARG((noArgs-1) - i), oleArgs[i])) { delete[] argNames; delete[] dispIds; delete[] oleArgs; return false; } } dispparams.rgdispidNamedArgs = dispIds + 1; dispparams.rgvarg = oleArgs; dispparams.cArgs = noArgs; dispparams.cNamedArgs = namedArgCount; EXCEPINFO excep; wxZeroMemory(excep); hr = ((IDispatch*)m_dispatchPtr)->Invoke(dispIds[0], IID_NULL, LOCALE_SYSTEM_DEFAULT, (WORD)action, &dispparams, vReturnPtr, &excep, &uiArgErr); for (i = 0; i < namedArgStringCount; i++) { SysFreeString(argNames[i]); } delete[] argNames; delete[] dispIds; for (i = 0; i < noArgs; i++) VariantClear(& oleArgs[i]) ; delete[] oleArgs; if (FAILED(hr)) { // display the exception information if appropriate: ShowException(member, hr, &excep, uiArgErr); // free exception structure information SysFreeString(excep.bstrSource); SysFreeString(excep.bstrDescription); SysFreeString(excep.bstrHelpFile); if (vReturnPtr) VariantClear(vReturnPtr); return false; } else { if (vReturnPtr) { // Convert result to wxVariant form wxConvertOleToVariant(vReturn, retValue); // Mustn't release the dispatch pointer if (vReturn.vt == VT_DISPATCH) { vReturn.pdispVal = NULL; } VariantClear(& vReturn); } } return true; }
void wxWebViewIE::LoadURL(const wxString& url) { m_ie.CallMethod("Navigate", wxConvertStringToOle(url)); }