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();
}
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";
	}

}
Beispiel #3
0
//----------------------------------------------------------------------------
//
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

  }