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;
}
// *****************************************************************
//			GetMinValue()
// *****************************************************************
void FieldClassification::GetMinValue(vector<VARIANT*>& srcValues, CComVariant& result, bool seekMin)
{
	CComVariant min, val;
	for (unsigned long i = 0; i < srcValues.size(); i++)
	{
		val.Copy(srcValues[i]);
		if (i == 0)	min = val;
		else {
			if (seekMin) {
				if (val < min)	min = val;
			}
			else {
				if (val > min)	min = val;
			}
		}
		val.Clear();
	}
	result.Copy(&min);
}
Beispiel #3
0
STDMETHODIMP CUUEngine::get_DFileDetail(short row, short itemno, short subscr, VARIANT *pVal)
{
	MString cs;
	CComVariant lv;
	int *ip;
	struct _uufile *ufp;
	long lct;

	uulist *l = ue.GetUulp(row);

	if (l == NULL)
		return(CTL_E_INVALIDPROPERTYARRAYINDEX);

	switch (itemno) {
		case UUVBLD_STATE:
			lv = l->state;
			break;

		case UUVBLD_MODE:
			lv = l->mode;
			break;

		case UUVBLD_BEGIN:
			lv = (short) l->begin;
			break;

		case UUVBLD_END:
			lv = (short) l->end;
			break;

		case UUVBLD_UUDET:
			lv = l->uudet;
			break;

		case UUVBLD_FLAGS:
			lv = (short) l->flags;
			break;

		case UUVBLD_SIZE:
			lv = l->size;
			break;

		case UUVBLD_FILEN:
			cs = l->filename;
			break;

		case UUVBLD_SUBF:
			cs = l->subfname;
			break;

		case UUVBLD_MIMEID:
			cs = l->mimeid;
			break;

		case UUVBLD_MIMETYPE:
			cs = l->mimetype;
			break;

		case UUVBLD_BINFILE:
			cs = l->binfile;
			break;

		case UUVBLD_HAVEPART:
		case UUVBLD_MISSPART:
			if (subscr < 0 || subscr > 255)
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			ip = ((itemno == UUVBLD_HAVEPART) ? l->haveparts : l->misparts)
				+ subscr;

			if (IsBadReadPtr(ip, sizeof(int)))
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			lv = (short) *ip;
			break;

		case UUVBLD_UFPART:
			if (subscr < 0 || subscr > 255)
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			for (ufp=l->thisfile; ufp != NULL && subscr > 0; subscr--)
				ufp = ufp->NEXT;

			if (ufp == NULL)
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			lv = ufp->partno;
			break;


		case UUVBLD_UFRSUBJ:
		case UUVBLD_UFRORG:
		case UUVBLD_UFRSFN:
		case UUVBLD_UFRSTART:		// uulist.thisfile[subscr].data.start
		case UUVBLD_UFRLEN:			// uulist.thisfile[subscr].data.length
			if (subscr < 0 || subscr > 255)
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			for (ufp=l->thisfile; ufp != NULL && subscr > 0; subscr--)
				ufp = ufp->NEXT;

			if (ufp == NULL || ufp->data == NULL)
				return(CTL_E_INVALIDPROPERTYARRAYINDEX);

			switch (itemno) 
			{
				case UUVBLD_UFRSUBJ:
					cs = ufp->data->subject;
					break;

				case UUVBLD_UFRORG:
					cs = ufp->data->origin;
					break;

				case UUVBLD_UFRSFN:
					cs = ufp->data->sfname;
					break;

				case UUVBLD_UFRSTART:		// uulist.thisfile[subscr].data.start
					lv = ufp->data->startpos;
					break;

				case UUVBLD_UFRLEN:			// uulist.thisfile[subscr].data.length
					lv = ufp->data->length;
					break;
			}
			break;

		case UUVBLD_UFRCOUNT:			// Figure out the number of parts this subsection has
			lct = 0;

			ufp = l->thisfile; 

			while (ufp != NULL)
			{
				ufp = ufp->NEXT;
				lct++;
			}

			lv = lct;
			break;

		}

	if (!cs.IsEmpty()) 			// This is a string return
	{
		lv.vt = VT_BSTR;
		cs.ToBSTR(&lv.bstrVal);
	}

	lv.Copy(pVal);

	return S_OK;
}