HRESULT vmsDomHelper::ExecJScript(IHTMLDocument *pDoc, BSTR bstrFuncName, const vector <CComVariant>& vArgs, CComVariant &vaResult)
{
	ATLASSERT (pDoc != NULL);
	if (!pDoc)
		return E_INVALIDARG;

	IDispatchPtr spScript;
	HRESULT hr = pDoc->get_Script (&spScript);
	if (spScript == NULL)
		return hr;

	DISPID did = NULL;
	hr = spScript->GetIDsOfNames (IID_NULL, &bstrFuncName, 1, LOCALE_SYSTEM_DEFAULT, &did);
	if (FAILED (hr))
		return hr;

	DISPPARAMS dparams;
	ZeroMemory (&dparams, sizeof (dparams));
	dparams.cArgs = vArgs.size ();
	if (dparams.cArgs)
		dparams.rgvarg = new VARIANT [dparams.cArgs];

	for (int i = 0; i < vArgs.size (); i++)
	{
		CComVariant vaTmp; vaTmp.Copy (&vArgs [vArgs.size () - i - 1]);
		VariantInit (&dparams.rgvarg [i]);
		vaTmp.Detach (&dparams.rgvarg [i]);
	}

	EXCEPINFO ei;
	ZeroMemory (&ei, sizeof (ei));
	UINT nArgErr = (UINT)-1;

	hr = spScript->Invoke (did, IID_NULL, 0, DISPATCH_METHOD, &dparams, &vaResult, &ei, &nArgErr);

	if (dparams.rgvarg)
	{
		for (int i = 0; i < dparams.cArgs; i++)
			VariantClear (&dparams.rgvarg [i]);
		delete [] dparams.rgvarg;
	}

	return hr;
}
Beispiel #2
0
HRESULT CMainDlg::PCSoftRunDefault(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{	
	CComVariant retVal;
	//if(pDispParams->rgvarg[0].bstrVal == NULL || pDispParams->rgvarg[0].bstrVal[0] == L'\0')
	//{
	//	retVal = false;
	//}
	//else
	{
		ShowWindow(FALSE);

		//CString strCmd;
		//strCmd = pDispParams->rgvarg[0].bstrVal;

		OnBkBtnDefault();

		OnBkBtnClose();
		//::PostMessage(this->m_hWnd, WM_CLOSE, 0, 0);

		retVal = true;
	}

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}

	return S_OK;
}
Beispiel #3
0
HRESULT CMainDlg::PCSoftOpenDownedSoft(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{	
	CString strCmdLine;
	BKSafeConfig::GetStoreDir(strCmdLine);
	::SHCreateDirectory(NULL, strCmdLine);

	CComVariant retVal;
	if(pDispParams->rgvarg[0].bstrVal == NULL || pDispParams->rgvarg[0].bstrVal[0] == L'\0')
	{
		retVal = true;
		::ShellExecute(NULL, L"open", strCmdLine, NULL, NULL, SW_SHOWNORMAL);
	}
	else
	{
		strCmdLine = _PathAddBackslash(strCmdLine) + pDispParams->rgvarg[0].bstrVal;

		BOOL bExist = ::PathFileExists(strCmdLine);
		if(bExist)
		{
			strCmdLine = L"/select," + strCmdLine;
			::ShellExecute(NULL, NULL, L"explorer.exe", strCmdLine, NULL, SW_NORMAL);
		}

		retVal = (bExist ? true : false);
	}

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}
	return S_OK;
}
Beispiel #4
0
HRESULT CMainDlg::PCSoftResumeDown(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	CComVariant retVal = false;

	do
	{
		LONG id = safe_atol(pDispParams->rgvarg[0].bstrVal);
		if(id == 0)
		{
			break;
		}

		CriticalSectionScoped locker(m_csPhoneNess);

		IDTManager *pDTMgr = GetDTMgrForPhone();
		if(pDTMgr != NULL)
		{
			Id2PhoneSoftIter itSoft = m_id2PhoneSoft.Lookup(id);
			if(itSoft != NULL)
			{
				pDTMgr->ResumeTask(itSoft->m_value.idDown);
				retVal = true;
			}
		}
	}
	while(FALSE);

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}

	return S_OK;
}
Beispiel #5
0
STDMETHODIMP CTRiASMICursorProperty::GetValue (BSTR Name, VARIANT *pVal)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
	
	_ASSERTE(NULL != Name || NULL != pVal);
	_ASSERTE(!wcscmp (Name, m_bstrName));		// muß voreingestellter Name sein
	if (NULL == pVal) return E_POINTER;

CComVariant val (m_Value);

	RETURN_FAILED_HRESULT(val.Detach (pVal));
	return S_OK;
}
Beispiel #6
0
HRESULT CMainDlg::PCSoftExists(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	CString strStore;
	BKSafeConfig::GetStoreDir(strStore);
	strStore = _PathAddBackslash(strStore) + pDispParams->rgvarg[0].bstrVal;

	CComVariant retVal = (::PathFileExists(strStore) ? true : false);
	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}
	return S_OK;
}
void ActiveXBrowserHost::getComVariant(VARIANT *dest, const FB::variant &var)
{
    CComVariant outVar;
    ::VariantInit(dest);

    const ComVariantBuilderMap& builderMap = getComVariantBuilderMap();
    const std::type_info& type = var.get_type();
    ComVariantBuilderMap::const_iterator it = builderMap.find(&type);
    
    if (it == builderMap.end()) {
        // unhandled type :(
        return;
    }
    
    outVar = (it->second)(FB::ptr_cast<ActiveXBrowserHost>(shared_ptr()), var);

    outVar.Detach(dest);
}
Beispiel #8
0
STDMETHODIMP C$$safe_root$$CursorProperty::GetValueAndType(BSTR Name, VARIANT * pVal, PROPERTY_TYPE * pType)
{
#if defined(_MFC_VER)
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif // defined(_MFC_VER)

	_ASSERTE(NULL != Name || NULL != pVal || NULL != pType);
	_ASSERTE(!wcscmp (Name, m_bstrName));		// muß voreingestellter Name sein

	if (NULL != pVal) return E_POINTER;
	if (NULL != pType) return E_POINTER;

CComVariant val (m_Value);

	RETURN_FAILED_HRESULT(val.Detach (pVal));
	*pType = PROPERTY_TYPE(PROPERTY_TYPE_Dynamic);
	return S_OK;
}
Beispiel #9
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

  }
Beispiel #10
0
STDMETHODIMP CBDictionary::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
		VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
	if((dispIdMember & 0xff000000) != 0x65000000)
		return CBDispatch<IVariantDictionary>::g_typeinfo.Invoke((IVariantDictionary*)this, dispIdMember, wFlags,
			pDispParams, pVarResult, pExcepInfo, puArgErr);

	dispIdMember &= 0xffffff;

	CBLock l(&m_cs);

	if(dispIdMember < (int)m_posArray.GetCount())
	{
		if((wFlags & (DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF)) && pDispParams->cArgs == 1)
		{
			VARIANT* pvar = pDispParams->rgvarg;

			while(pvar->vt == (VT_VARIANT | VT_BYREF))
				pvar = pvar->pvarVal;

			if(!(wFlags & DISPATCH_PROPERTYPUTREF) &&
				(pvar->vt == VT_UNKNOWN || pvar->vt == VT_DISPATCH))
			{
				l.Unlock();

				if(pvar->punkVal == NULL)
					return DISP_E_UNKNOWNINTERFACE;

				CBDispatchPtr pDisp;
				CComVariant var;

				HRESULT hr = pvar->punkVal->QueryInterface(&pDisp);
				if(FAILED(hr))return hr;

				hr = pDisp.GetProperty(0, &var);
				if(FAILED(hr))return hr;

				l.Lock();
				if(dispIdMember < (int)m_posArray.GetCount())
				{
					var.Detach(&m_posArray[dispIdMember]->m_value);
					return S_OK;
				}else return DISP_E_MEMBERNOTFOUND;
			}else return VariantCopyInd(&m_posArray[dispIdMember]->m_value, pvar);
		}else if(pDispParams->cArgs == 0)
		{
			if(pVarResult != NULL)
				return VariantCopy(pVarResult, &m_posArray[dispIdMember]->m_value);

			return S_OK;
		}

		VARIANT *pvar = &m_posArray[dispIdMember]->m_value;

		if(pvar->vt == VT_UNKNOWN || pvar->vt == VT_DISPATCH)
		{
			CBDispatchPtr pDisp;

			HRESULT hr = pvar->punkVal->QueryInterface(&pDisp);
			if(FAILED(hr))
				return DISP_E_BADPARAMCOUNT;

			l.Unlock();
			return pDisp->Invoke(0, riid, lcid, wFlags, pDispParams,
					pVarResult, pExcepInfo, puArgErr);
		}

		return DISP_E_BADPARAMCOUNT;
	}else return DISP_E_MEMBERNOTFOUND;

	return S_OK;
}
Beispiel #11
0
HRESULT CMainDlg::PCSoftRun(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{	
	CComVariant retVal;
	if(pDispParams->rgvarg[0].bstrVal == NULL || pDispParams->rgvarg[0].bstrVal[0] == L'\0')
	{
		retVal = false;
	}
	else
	{
		ShowWindow(FALSE);

		CString strOld;
		CString strNew;
		GetRegExtInfo(strOld);

		CString strStore;
		BKSafeConfig::GetStoreDir(strStore);
		SHCreateDirectory(NULL, strStore);

		strStore = _PathAddBackslash(strStore) + pDispParams->rgvarg[0].bstrVal;
		CString strCmd;
		strCmd = strStore;
		
		CreateProcessSyn(strCmd);

		GetRegExtInfo(strNew);
		if (strOld != strNew)
		{
			CBkSafeMsgBox2	msgbox;
			msgbox.AddButton(L"是", IDOK);
			msgbox.AddButton(L"否", IDCANCEL);
			CString strMsg;
			strMsg.Format(L"软件安装完成,是否立即打开文件“%s”", m_strFileName);
			UINT nRet = msgbox.ShowMutlLineMsg(strMsg, 
				NULL, MB_BK_CUSTOM_BUTTON|MB_ICONQUESTION, NULL);
			if(nRet == IDOK)
			{
				::ShellExecute(NULL, L"open", g_strCmd, L"", NULL, SW_SHOWNORMAL);
			}
		}
		else
		{
			CBkSafeMsgBox2 msgbox;
			msgbox.AddButton( TEXT("确定"), IDOK);
			CString strMsg;
			strMsg.Format(L"由于您已取消,将无法打开文件“%s”", m_strFileName);
			msgbox.ShowMutlLineMsg( strMsg, NULL, MB_BK_CUSTOM_BUTTON | MB_ICONWARNING );
		}

		OnBkBtnClose();
		//::PostMessage(m_hWnd, WM_CLOSE, 0, 0);

		retVal = true;
	}

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}

	return S_OK;
}
Beispiel #12
0
HRESULT CMainDlg::PCSoftStartDown(DISPID dispIdMember, DISPPARAMS *pDispParams, VARIANT *pVarResult)
{
	CComVariant retVal = false;

	do
	{
		LONG id = safe_atol(pDispParams->rgvarg[4].bstrVal);
		if(id == 0)
		{
			break;
		}

		//
		// 若文件已存在,则直接返回
		//
		CString strStore;
		BKSafeConfig::GetStoreDir(strStore);
		SHCreateDirectory(NULL, strStore);

		strStore = _PathAddBackslash(strStore) + pDispParams->rgvarg[1].bstrVal;
		if(::PathFileExists(strStore))
		{
			retVal = true;
			break;
		}

		CriticalSectionScoped locker(m_csPhoneNess);

		// 若任务已经存在,则直接返回
		{
			Id2PhoneSoftIter itSoft = m_id2PhoneSoft.Lookup(id);
			if(itSoft != NULL)
			{
				retVal = false;
				break;
			}
		}

		IDTManager *pDTMgr = GetDTMgrForPhone();
		if(pDTMgr != NULL)
		{
			int curPos = 0;
			CString strUrl = pDispParams->rgvarg[3].bstrVal;

			CString token = strUrl.Tokenize(L" ", curPos);
			if(!token.IsEmpty())
			{
				CAtlArray<CString> *pUrlArray = new CAtlArray<CString>();

				do
				{
					pUrlArray->Add(token);
					token = strUrl.Tokenize(L" ", curPos);
				}
				while(!token.IsEmpty());

				PhoneSoft ps;
				ps.speed = 0;
				ps.recved = 0;
				ps.state = PDS_INIT;
				ps.idDown = pDTMgr->NewTask(pUrlArray, pDispParams->rgvarg[2].bstrVal, strStore);

				m_id2PhoneSoft[id] = ps;
				m_dt2Id[ps.idDown] = id;

				retVal = true;
			}
		}
	}
	while(FALSE);

	if(pVarResult != NULL)
	{
		retVal.Detach(pVarResult);
	}
	return S_OK;
}