void lvDCOMInterface::getLabviewValue(const char* param, T* value, size_t nElements, size_t& nIn) { if (value == NULL) { throw std::runtime_error("getLabviewValue failed (NULL)"); } if (param == NULL || *param == '\0') { throw std::runtime_error("getLabviewValue: param is NULL"); } CComVariant v; char vi_name_xpath[MAX_PATH_LEN], control_name_xpath[MAX_PATH_LEN]; _snprintf(vi_name_xpath, sizeof(vi_name_xpath), "/lvinput/section[@name='%s']/vi/@path", m_configSection.c_str()); _snprintf(control_name_xpath, sizeof(control_name_xpath), "/lvinput/section[@name='%s']/vi/param[@name='%s']/read/@target", m_configSection.c_str(), param); CComBSTR vi_name(doPath(vi_name_xpath).c_str()); CComBSTR control_name(doXPATH(control_name_xpath).c_str()); if (vi_name.Length() == 0 || control_name.Length() == 0) { throw std::runtime_error("getLabviewValue: vi or control is NULL"); } getLabviewValue(vi_name, control_name, &v); if ( v.vt != (VT_ARRAY | CVarTypeInfo<T>::VT) ) { throw std::runtime_error("getLabviewValue failed (type mismatch)"); } CComSafeArray<T> sa; sa.Attach(v.parray); nIn = ( sa.GetCount() > nElements ? nElements : sa.GetCount() ); for(LONG i=0; i<nIn; ++i) { value[i] = sa.GetAt(i); } sa.Detach(); }
HRESULT GetAssemblyFromAppDomain(_AppDomain* appDomain, const wchar_t* assemblyName, _Assembly **assembly) { SAFEARRAY* safearray; CComSafeArray<IUnknown*> assemblies; CHECKCOM(appDomain->GetAssemblies(&safearray)); assemblies.Attach(safearray); for (int i = 0, n = assemblies.GetCount(); i < n; i++) { CComPtr<_Assembly> a; a = assemblies[i]; if (a == nullptr) continue; CComBSTR assemblyFullName; CHECKCOM(a->get_FullName(&assemblyFullName)); if (assemblyFullName != nullptr && _wcsnicmp(assemblyFullName, assemblyName, wcslen(assemblyName)) == 0) { *assembly = a.Detach(); return S_OK; } } return E_FAIL; }
void CRegionDlg::OnBnClickedSelect() { UpdateData(); ShowWindow(SW_HIDE); CRect rcCapture; CComPtr<ITSelectionInfo> pSelInfo; CComSafeArray<VARIANT, VT_VARIANT> arSafePoints; int nCount = 0; LONG hWnd = NULL; VARIANT points; if (!theApp.Select(tsSelectionRectangle, pSelInfo)) { goto Exit; } // Capture region hWnd = pSelInfo->WindowHandle; pSelInfo->get_Points(&points); // Ttransform safe arry points arSafePoints.CopyFrom(points.parray); nCount = (int)arSafePoints.GetCount(); ATLASSERT(2 == nCount); if (2 != nCount) { goto Exit; } rcCapture.SetRect(GET_X_LPARAM(arSafePoints[0].lVal), GET_Y_LPARAM(arSafePoints[0].lVal), GET_X_LPARAM(arSafePoints[1].lVal), GET_Y_LPARAM(arSafePoints[1].lVal)); // Fill the values m_strWindowName = theApp.GetWindowText((HWND)(LONG_PTR)hWnd); m_strWindowHandle.Format(_T("%X"), hWnd); m_nX = rcCapture.left; m_nY = rcCapture.top; m_nWidth = rcCapture.Width(); m_nHeight = rcCapture.Height(); // Capture DoCapture(hWnd, rcCapture); UpdateData(FALSE); Exit: if (m_nFullHeight > 0) { //restore the window theApp.RestoreWindow(this, m_nFullHeight); m_nFullHeight = 0; } ShowWindow(SW_SHOW); }
HRESULT RegisterWithGDEventFramework() { CComPtr<IGoogleDesktopRegistrar> registrar; HRESULT hr = registrar.CoCreateInstance(L"GoogleDesktop.Registrar"); if (SUCCEEDED(hr)) { CComBSTR our_guid(CONSOLE_PLUGIN_GUID); WCHAR icon_path[_MAX_PATH + 1] = {0}; ATLVERIFY(::GetModuleFileNameW(NULL, icon_path, _MAX_PATH - 2) != 0); SafeStrCat(icon_path, L"@0", _MAX_PATH+1); CComSafeArray<VARIANT> description; ATLVERIFY(SUCCEEDED(description.Create(8))); VARIANT* props = reinterpret_cast<VARIANT*>(description.m_psa->pvData); for (DWORD i = 0; i < description.GetCount(); ++i) { props[i].vt = VT_BSTR; } props[0].bstrVal = ::SysAllocString(L"Title"); props[1].bstrVal = ::SysAllocString(L"Console Events"); props[2].bstrVal = ::SysAllocString(L"Description"); props[3].bstrVal = ::SysAllocString(L"Outputs events from Google Desktop to the console"); props[4].bstrVal = ::SysAllocString(L"Icon"); props[5].bstrVal = ::SysAllocString(icon_path); props[6].bstrVal = ::SysAllocString(L"Homepage"); props[7].bstrVal = ::SysAllocString(L"http://desktop.google.com"); VARIANT desc; desc.vt = VT_ARRAY | VT_VARIANT; desc.parray = description; hr = registrar->StartComponentRegistration(our_guid, desc); if (SUCCEEDED(hr)) { CComPtr<IUnknown> unknown; hr = registrar->GetRegistrationInterface(CComBSTR(L"GoogleDesktop.EventRegistration"), &unknown); ATLASSERT(SUCCEEDED(hr)); CComQIPtr<IGoogleDesktopRegisterEventPlugin> event_registration(unknown); if (event_registration != NULL) { long cookie = 0; hr = event_registration->RegisterPlugin(our_guid, &cookie); if (SUCCEEDED(hr)) { hr = registrar->FinishComponentRegistration(); if (SUCCEEDED(hr)) { hr = StoreRegistrationCookie(cookie); } } } } } return hr; }
void displayCCOMBSTRFiles(CComSafeArray<BSTR> fileSet) { std::wcout << "Displaying Files Generated from the C++ Interface from COM OBJECT" << std::endl; for (ULONG i = 0; i < fileSet.GetCount(); i++) { std::cout << "Qualified File # " <<i<<" : "<< convertBSTR2stdSTR(fileSet.GetAt(i)) << "\n"; } }
/** * Output = Map of topic id and field data - Map to be deleted by caller */ std::map<long,CComVariant>* RTDClient::readNewData(){ SAFEARRAY *data_sa; long topic_count = 0; HRESULT hr = comObjectScripRTD->RefreshData( &topic_count, &data_sa ); // Pass Address of SAFEARRAY pointer so that we get pointer to 2D safearray if( FAILED(hr) ){ // Output Data has to be deleted by client std::cout << "RefreshData COM failure." << " - hr - " << hr << std::endl; return 0; } CComSafeArray<VARIANT> data; // Passing data_sa as Constructor input will copy it, but we need to destroy it after use data.Attach( data_sa ); // So attach instead and let CComSafeArray handle it ULONG row_count = data.GetCount(1); // No of Rows = 2nd Dimension Count if( row_count == 0) return 0 ; std::map<long,CComVariant> *output = new std::map<long,CComVariant>; // Map: Topicid, Field Data long index[2]; for( ULONG i=0 ; i<row_count; i++ ){ index[0] = 0; // 0,x - Topic ids. 1,x - Data index[1] = i; CComVariant topic_id_var; data.MultiDimGetAt( index, topic_id_var); long topic_id = (long)MiscUtil::getLong( topic_id_var ); index[0] = 1; index[1] = i; CComVariant topic_data_var; data.MultiDimGetAt( index, topic_data_var); if( output->count(topic_id) != 0 && (*output)[topic_id] != topic_data_var ){ std::cout << "Duplicate:"; MiscUtil::printVariant((*output)[topic_id]); std::cout << "-"; MiscUtil::printVariant(topic_data_var); std::cout << std::endl; //abort(); // If exists - we can have multiple topic values in same call => use vector } (*output)[topic_id] = topic_data_var; } return output; }
void printHistory(CComVariant history) { if (history.vt == (VT_ARRAY | VT_I2)) { printf("Ping code history for server: "); CComSafeArray<SHORT> codes = history.parray; int codeCount = codes.GetCount(); for (int i = 0; i < codeCount; i++) { printf("%hd ", codes[i]); } printf("\n"); codes.Destroy(); } else { printf("Incorrect variant type\n"); } }
//---------------------------------------------------------------------------- // HRESULT CAnchoRuntime::fireOnBeforeRequest(const std::wstring &aUrl, const std::wstring &aMethod, const CAnchoRuntime::FrameRecord *aFrameRecord, /*out*/ BeforeRequestInfo &aOutInfo) { CComPtr<ComSimpleJSObject> info; IF_FAILED_RET(SimpleJSObject::createInstance(info)); fillRequestInfo(*info, aUrl, aMethod, aFrameRecord); CComPtr<ComSimpleJSArray> argArray; IF_FAILED_RET(SimpleJSArray::createInstance(argArray)); argArray->push_back(CComVariant(info.p)); CComVariant result; m_pAnchoService->invokeEventObjectInAllExtensions(CComBSTR(L"webRequest.onBeforeRequest"), argArray.p, &result); if (result.vt & VT_ARRAY) { CComSafeArray<VARIANT> arr; arr.Attach(result.parray); //contained data already managed by CComSafeArray VARIANT tmp = {0}; HRESULT hr = result.Detach(&tmp); BEGIN_TRY_BLOCK aOutInfo.cancel = false; for (ULONG i = 0; i < arr.GetCount(); ++i) { Ancho::Utils::JSObjectWrapperConst item = Ancho::Utils::JSValueWrapperConst(arr.GetAt(i)).toObject(); Ancho::Utils::JSValueWrapperConst cancel = item[L"cancel"]; if (!cancel.isNull()) { aOutInfo.cancel = aOutInfo.cancel || cancel.toBool(); } Ancho::Utils::JSValueWrapperConst redirectUrl = item[L"redirectUrl"]; if (!redirectUrl.isNull()) { aOutInfo.redirect = true; aOutInfo.newUrl = redirectUrl.toString(); } } END_TRY_BLOCK_CATCH_TO_HRESULT }