Exemplo n.º 1
0
STDMETHODIMP CScdSpVector::get_Vector(/*[in]*/ VARIANT_BOOL EnthalpyBasis, /*[out, retval]*/ SAFEARRAY **pVal)
  {
  dllSCD_COMENTRYGET(long, pVal)
    {
    SAFEARRAY *pSA=NULL;
    SAFEARRAYBOUND bound[1]={SDB.Count()+3,0};
    pSA=SafeArrayCreate(VT_R8, 1, bound);

    double d;
    long Cnt=bound[0].cElements;
    for (long i=0; i<SDB.Count(); i++)
      {
      d=m_pOwn->Model()->VMass[i];
      SafeArrayPutElement(pSA, &i, &d);
      }

    // NBNB EnthalpyBasis is ignored on "get"
    d=m_pOwn->Model()->totHz(som_ALL, m_pOwn->Model()->Temp(), m_pOwn->Model()->Press());
    SafeArrayPutElement(pSA, &i, &d);

    i++;
    d=m_pOwn->Model()->Temp();
    SafeArrayPutElement(pSA, &i, &d);

    i++;
    d=m_pOwn->Model()->Press();
    SafeArrayPutElement(pSA, &i, &d);

    *pVal=pSA;
    }
Exemplo n.º 2
0
HRESULT CKhParser::GetNextHomonym( SAFEARRAY** lpHomonym )
{
    if (currHom == -1)
        return S_OK;
    std::wstring str;
    if (currHom < homonyms.size())
        str = homonyms[currHom].khak;
    else
        str = homonyms[currHom % homonyms.size()].rus;

    long idx, len, start;
    len = (long)str.length();
    SafeArrayLock(*lpHomonym);

    SafeArrayGetUBound(*lpHomonym, 1, &len);
    SafeArrayGetLBound(*lpHomonym, 1, &start);
    short asterisk = L'*';
    for (idx = start; idx < len; idx ++) {
        if (idx == str.length()) {
//        if (str[idx] == 0x0) {
            SafeArrayPutElement(*lpHomonym, &idx, &asterisk);
            break;
        }
        SafeArrayPutElement(*lpHomonym, &idx, &str[ idx ]);
    }
    SafeArrayUnlock(*lpHomonym);

    currHom++;

    return S_OK;
}
Exemplo n.º 3
0
static void com_write_dimension(zval *object, zval *offset, zval *value)
{
	php_com_dotnet_object *obj;
	zval args[2];
	VARIANT v;
	HRESULT res;

	obj = CDNO_FETCH(object);

	if (V_VT(&obj->v) == VT_DISPATCH) {
		ZVAL_COPY_VALUE(&args[0], offset);
		ZVAL_COPY_VALUE(&args[1], value);

		VariantInit(&v);

		if (SUCCESS == php_com_do_invoke_by_id(obj, DISPID_VALUE,
				DISPATCH_METHOD|DISPATCH_PROPERTYPUT, &v, 2, args, 0, 0)) {
			VariantClear(&v);
		}
	} else if (V_ISARRAY(&obj->v)) {
		LONG indices = 0;
		VARTYPE vt;

		if (SafeArrayGetDim(V_ARRAY(&obj->v)) == 1) {
			if (FAILED(SafeArrayGetVartype(V_ARRAY(&obj->v), &vt)) || vt == VT_EMPTY) {
				vt = V_VT(&obj->v) & ~VT_ARRAY;
			}

			convert_to_long(offset);
			indices = (LONG)Z_LVAL_P(offset);

			VariantInit(&v);
			php_com_variant_from_zval(&v, value, obj->code_page);

			if (V_VT(&v) != vt) {
				VariantChangeType(&v, &v, 0, vt);
			}

			if (vt == VT_VARIANT) {
				res = SafeArrayPutElement(V_ARRAY(&obj->v), &indices, &v);
			} else {
				res = SafeArrayPutElement(V_ARRAY(&obj->v), &indices, &v.lVal);
			}

			VariantClear(&v);

			if (FAILED(res)) {
				php_com_throw_exception(res, NULL);
			}

		} else {
			php_com_throw_exception(DISP_E_BADINDEX, "this variant has multiple dimensions; you can't set a new value without specifying *all* dimensions");
		}

	} else {
		php_com_throw_exception(E_INVALIDARG, "this variant is not an array type");
	}
}
void
addCircleThroughCom()
{
    AutoCAD::IAcadApplication *pAcad;
    AutoCAD::IAcadDocument *pDoc;
    AutoCAD::IAcadModelSpace *pMSpace;

    HRESULT hr = NOERROR;
    LPUNKNOWN pUnk = NULL;
    LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE); 
	if(pAcadDisp==NULL)
		return;
	
	hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad);
	pAcadDisp->Release();
	if (FAILED(hr))
		return;

	hr = pAcad->get_ActiveDocument(&pDoc);
	pAcad->Release();
	if (FAILED(hr))
		return;

	hr = pDoc->get_ModelSpace(&pMSpace);
	pDoc->Release();
	if (FAILED(hr))
		return;


    SAFEARRAYBOUND rgsaBound;
    rgsaBound.lLbound = 0L;
    rgsaBound.cElements = 3;
    long i;
    SAFEARRAY* pStartPoint = NULL;
    pStartPoint = SafeArrayCreate(VT_R8, 1, &rgsaBound);

    i = 0;
    double value = 4.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 1;
    value = 2.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 2;
    value = 0.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    VARIANT pt1;
    pt1.vt = VT_ARRAY | VT_R8;
    pt1.parray = pStartPoint;

    AutoCAD::IAcadCircle *pCircle;
    pMSpace->AddCircle(pt1, 2.0, &pCircle);
	VariantClear(&pt1);
    pMSpace->Release();
}
Exemplo n.º 5
0
void SimpleBrowser::Print(LPCTSTR header,LPCTSTR footer)
{
	if (m_pBrowser != NULL) {
		// construct two element SAFEARRAY;
		// first element is header string, second element is footer string
		HRESULT hr;
		VARIANT		header_variant;
		VariantInit(&header_variant);
		V_VT(&header_variant)   = VT_BSTR;
		V_BSTR(&header_variant) = CString(header).AllocSysString();
		VARIANT		footer_variant;
		VariantInit(&footer_variant);
		V_VT(&footer_variant)   = VT_BSTR;
		V_BSTR(&footer_variant) = CString(footer).AllocSysString();
		long index;
		SAFEARRAYBOUND	parameter_array_bound[1];
		SAFEARRAY		*parameter_array = NULL;

		parameter_array_bound[0].cElements = 2;
		parameter_array_bound[0].lLbound   = 0;

		parameter_array = SafeArrayCreate(VT_VARIANT,1,parameter_array_bound);

		index = 0;
		hr    = SafeArrayPutElement(parameter_array,&index,&header_variant);

		index = 1;
		hr    = SafeArrayPutElement(parameter_array,&index,&footer_variant);

		VARIANT	parameter;
		VariantInit(&parameter);
		V_VT(&parameter)    = VT_ARRAY | VT_BYREF;
		V_ARRAY(&parameter) = parameter_array;

		// start printing browser contents

		hr = m_pBrowser->ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DODEFAULT,&parameter,NULL);

			// Note: There is no simple way to determine that printing has completed. 
			//       In fact, if the browser is destroyed while printing is in progress, 
			//       only part of the contents will be printed.

		// release SAFEARRAY

		if (!SUCCEEDED(hr)) {
			VariantClear(&header_variant);
			VariantClear(&footer_variant);
			if (parameter_array != NULL) {
				SafeArrayDestroy(parameter_array);
			}
		}

	}
}
Exemplo n.º 6
0
/// <summary>
/// Loads and invokes the managed portion of the proxy.
/// </summary>
/// <param name="pInitMethod">Managed initialize method to be invoked.</param>
/// <param name="hSession">Handle to the installer session,
/// used for logging errors and to be passed on to the managed initialize method.</param>
/// <param name="szClassName">Name of the UI class to be loaded.
/// This must be of the form: AssemblyName!Namespace.Class</param>
/// <param name="pdwInternalUILevel">MSI install UI level passed to and returned from
/// the managed initialize method.</param>
/// <param name="puiResult">Return value of the invoked initialize method.</param>
/// <returns>True if the managed proxy was invoked successfully, or an
/// error code if there was some error. Note the initialize method itself may
/// return an error via puiResult while this method still returns true
/// since the invocation was successful.</returns>
bool InvokeInitializeMethod(_MethodInfo* pInitMethod, MSIHANDLE hSession, const wchar_t* szClassName, LPDWORD pdwInternalUILevel, UINT* puiResult)
{
	VARIANT vResult;
	VariantInit(&vResult);

	VARIANT vNull;
	vNull.vt = VT_EMPTY;

	SAFEARRAY* saArgs = SafeArrayCreateVector(VT_VARIANT, 0, 3);
	VARIANT vSessionHandle;
	vSessionHandle.vt = VT_I4;
	vSessionHandle.lVal = (LONG) hSession;
	LONG index = 0;
	HRESULT hr = SafeArrayPutElement(saArgs, &index, &vSessionHandle);
	if (FAILED(hr)) goto LExit;
	VARIANT vEntryPoint;
	vEntryPoint.vt = VT_BSTR;
	vEntryPoint.bstrVal = SysAllocString(szClassName);
	if (vEntryPoint.bstrVal == NULL)
	{
		hr = E_OUTOFMEMORY;
		goto LExit;
	}
	index = 1;
	hr = SafeArrayPutElement(saArgs, &index, &vEntryPoint);
	if (FAILED(hr)) goto LExit;
	VARIANT vUILevel;
	vUILevel.vt = VT_I4;
	vUILevel.ulVal = *pdwInternalUILevel;
	index = 2;
	hr = SafeArrayPutElement(saArgs, &index, &vUILevel);
	if (FAILED(hr)) goto LExit;
	
	hr = pInitMethod->Invoke_3(vNull, saArgs, &vResult);
	
LExit:
	SafeArrayDestroy(saArgs);
	if (SUCCEEDED(hr))
	{
		*puiResult = (UINT) vResult.lVal;
		if ((*puiResult & 0xFFFF) == 0)
		{
			// Due to interop limitations, the successful resulting UILevel is returned
			// as the high-word of the return value instead of via a ref parameter.
			*pdwInternalUILevel = *puiResult >> 16;
			*puiResult = 0;
		}
		return true;
	}
Exemplo n.º 7
0
SEXP rCallStaticMethod(SEXP p) {
	
	// 1 - Get data from SEXP
	p = CDR(p); // Skip the first parameter: because function name
	char* strTypeName = readStringFromSexp(p); p = CDR(p);
	char* strMethodName = readStringFromSexp(p); p = CDR(p);
	SAFEARRAY* parameters = readParametersFromSexp(p);

	// 2 - Prepare arguments to call proxy
	SAFEARRAY* args = SafeArrayCreateVector(VT_VARIANT, 0, 3);
	long i = 0;
	
	// 2.1 - Type name
	variant_t typeName(strTypeName);
	SafeArrayPutElement(args, &i, &typeName); i++;
	
	// 2.2 - Method name
	variant_t methodName(strMethodName);
	SafeArrayPutElement(args, &i, &methodName); i++;

	// 2.3 parameters
	VARIANT* pvt = new variant_t();
	VariantInit(pvt);
	pvt->vt = VT_ARRAY | VT_I8;
	pvt->parray = parameters;
	SafeArrayPutElement(args, &i, pvt); i++;

	// 3 - Call the proxy
	CLR_OBJ result;
	char* errorMsg;
	HRESULT hr = callProxy(L"CallStaticMethod", args, &result, &errorMsg);
	
	if(FAILED(hr)) {
		Rprintf(errorMsg);
		error("Exception during netCallStatic !");
		free(errorMsg);
		return R_NilValue;
	}

	// 4 - Free memory
	SafeArrayDestroy(parameters);
	SafeArrayDestroy(args);
	//free_variant_array(pvt);
	//free(strTypeName);
	//free(strMethodName);

	return convertToSEXP(result);
}
Exemplo n.º 8
0
int wdGetArrayLengthScriptResult(WebDriver* driver, ScriptResult* result,
                                 int* length)
{
  // Prepare an array for the Javascript execution, containing only one
  // element - the original returned array from a JS execution.
  SAFEARRAYBOUND lengthQuery;
  lengthQuery.cElements = 1;
  lengthQuery.lLbound = 0;
  SAFEARRAY* lengthArgs = SafeArrayCreate(VT_VARIANT, 1, &lengthQuery);
  LONG index = 0;
  SafeArrayPutElement(lengthArgs, &index, &(result->result));
  CComVariant lengthVar;
  int lengthResult = driver->ie->executeScript(
      L"(function(){return function() {return arguments[0].length;}})();",
      lengthArgs, &lengthVar);
  SafeArrayDestroy(lengthArgs);
  if (lengthResult != SUCCESS) {
    return lengthResult;
  }

  // Expect the return type to be an integer. A non-integer means this was
  // not an array after all.
  if (lengthVar.vt != VT_I4) {
    return EUNEXPECTEDJSERROR;
  }

  *length = lengthVar.lVal;

  return SUCCESS;
}
Exemplo n.º 9
0
void __declspec(dllexport) __stdcall
vbCSLToVariant( char **papszList, VARIANT *out_list )

{
    USES_CONVERSION;
    SAFEARRAYBOUND sBounds;
    SAFEARRAY *result;
    long i, nLength = CSLCount( papszList );

/* -------------------------------------------------------------------- */
/*      Create safe array result.                                       */
/* -------------------------------------------------------------------- */
    sBounds.lLbound = 1;
    sBounds.cElements = nLength;

    result = SafeArrayCreate( VT_BSTR, 1, &sBounds );

    for( i = 1; i <= nLength; i++ )
    {
        SafeArrayPutElement( result, &i,
                             SysAllocString( A2BSTR(papszList[i-1]) ) );
//        MessageBox( NULL, papszList[i-1], "Metadata Item", MB_OK );
    }

/* -------------------------------------------------------------------- */
/*      Assign to variant.                                              */
/* -------------------------------------------------------------------- */
    VariantClear( out_list );

    out_list->vt = VT_BSTR | VT_ARRAY;
    out_list->parray = result;
}
template<typename T> T ExecuteMethod(mscorlib::_MethodInfoPtr method, std::vector<variant_t>& args)
{
	variant_t obj;
	T retObj;

	SAFEARRAY * psa;
	SAFEARRAYBOUND rgsabound[1];

	rgsabound[0].lLbound = 0;
	rgsabound[0].cElements = (ULONG)args.size();
	psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);

	for (LONG indicies = 0; indicies < (LONG)args.size(); ++indicies)
	{
		SafeArrayPutElement(psa, &indicies, &args[indicies]);
	}

	variant_t ret = method->Invoke_3(obj, psa);

	if ((ret.vt == VT_UNKNOWN) || (ret.vt == VT_DISPATCH))
	{
		retObj = ret.punkVal;
	}

	SafeArrayDestroy(psa);

	return retObj;
}
Exemplo n.º 11
0
INT CADOParameters::Add(const BYTE *pBytes, INT iLen)
{
	_ParameterPtr pParam;

	// Create Parameter
	HRESULT hr = pParam.CreateInstance(__uuidof(Parameter));
	if (FAILED(hr))
		_com_issue_error(hr);

	// Set param for the value;
	pParam->Direction = adParamInput;

	pParam->Type = adBinary;
	pParam->Size = iLen;
	_variant_t var;
	SAFEARRAY *psa = NULL;
	SAFEARRAYBOUND rgsabound[1];
	rgsabound[0].lLbound = 0L;
	rgsabound[0].cElements = iLen;
	psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
	if (NULL == psa)
		_com_issue_error(E_OUTOFMEMORY);
	for (LONG l=0; l<iLen; l++)
		SafeArrayPutElement(psa, &l, (LPVOID)&pBytes[l]);
	var.vt = VT_ARRAY|VT_UI1;
	var.parray = psa;

	pParam->AppendChunk(var);

	return Add((_Parameter*)pParam);
}
STDMETHODIMP CFusionCHPHeaderCOM::get_AlgorithmParameters(VARIANT* pVal)
{
	VariantInit(pVal);
	pVal->vt = VT_ARRAY | VT_DISPATCH;
	pVal->parray = NULL;
	affymetrix_fusion_io::FusionTagValuePairTypeList values;
	header->AlgorithmParameters(values);
	int nparams = (int)values.size();
	SAFEARRAYBOUND  rgsaBound[1];
	rgsaBound[0].lLbound = 0;
	rgsaBound[0].cElements = nparams;
	pVal->parray = SafeArrayCreate(VT_DISPATCH, 1, rgsaBound);
	long index=0;
	affymetrix_fusion_io::FusionTagValuePairTypeList::iterator it;
	for (it=values.begin(); it!=values.end(); ++it)
	{
		CComPtr<IFusionTagValuePairType> param;
		param.CoCreateInstance(CLSID_FusionTagValuePairType);
		CFusionTagValuePairTypeCOM *pParam = static_cast<CFusionTagValuePairTypeCOM *>(param.p);
		pParam->SetParam((*it));
		HRESULT hr = SafeArrayPutElement(pVal->parray, &index, param);
		++index;
	}
	return S_OK;
}
Exemplo n.º 13
0
STDMETHODIMP CFusionCHPQuantificationDataCOM::get_SummaryParameters(VARIANT* pVal)
{
	if (chp == NULL)
		return E_FAIL;

	VariantInit(pVal);
	pVal->vt = VT_ARRAY | VT_DISPATCH;
	pVal->parray = NULL;
	affymetrix_calvin_parameter::ParameterNameValueTypeList params = chp->GetSummaryParams();
	int nparams = (int)params.size();
	SAFEARRAYBOUND  rgsaBound[1];
	rgsaBound[0].lLbound = 0;
	rgsaBound[0].cElements = nparams;
	pVal->parray = SafeArrayCreate(VT_DISPATCH, 1, rgsaBound);
	long index=0;
	affymetrix_calvin_parameter::ParameterNameValueTypeList::iterator it;
	for (it=params.begin(); it!=params.end(); ++it)
	{
		CComPtr<IFusionTagValuePairType> param;
		affymetrix_fusion_io::FusionTagValuePairType fparam;
		param.CoCreateInstance(CLSID_FusionTagValuePairType);
		CFusionTagValuePairTypeCOM *pParam = static_cast<CFusionTagValuePairTypeCOM *>(param.p);
		fparam.Tag = it->GetName();
		fparam.Value = it->ToString();
		pParam->SetParam(fparam);
		HRESULT hr = SafeArrayPutElement(pVal->parray, &index, param);
		++index;
	}
	return S_OK;
}
STDMETHODIMP CFusionCHPHeaderCOM::GetBackgroundZones(VARIANT *zones)
{
	VariantInit(zones);
	zones->vt = VT_ARRAY | VT_DISPATCH;
	zones->parray = NULL;
	affxchp::BackgroundZoneTypeList czones;
	header->GetBackgroundZones(czones);
	int nzones = (int)czones.size();
	SAFEARRAYBOUND  rgsaBound[1];
	rgsaBound[0].lLbound = 0;
	rgsaBound[0].cElements = nzones;
	zones->parray = SafeArrayCreate(VT_DISPATCH, 1, rgsaBound);
	long index=0;
	affxchp::BackgroundZoneTypeList::iterator it;
	for (it=czones.begin(); it!=czones.end(); ++it)
	{
		CComPtr<IBackgroundZoneType> z;
		z.CoCreateInstance(CLSID_BackgroundZoneType);
		CBackgroundZoneTypeCOM *pz = static_cast<CBackgroundZoneTypeCOM *>(z.p);
		pz->SetBg(*it);
		HRESULT hr = SafeArrayPutElement(zones->parray, &index, z);
		++index;
	}
	return S_OK;
}
Exemplo n.º 15
0
HRESULT STDMETHODCALLTYPE SumatraUIAutomationDocumentProvider::GetVisibleRanges(SAFEARRAY** pRetVal) {
    if (pRetVal == nullptr)
        return E_POINTER;
    if (released)
        return E_FAIL;

    // return all pages' ranges that are even partially visible
    Vec<SumatraUIAutomationTextRange*> rangeArray;
    SumatraUIAutomationPageProvider* it = child_first;
    while (it && rangeArray.size() > ULONG_MAX) {
        if (it->dm->GetPageInfo(it->pageNum) && it->dm->GetPageInfo(it->pageNum)->shown &&
            it->dm->GetPageInfo(it->pageNum)->visibleRatio > 0.0f) {
            rangeArray.Append(new SumatraUIAutomationTextRange(this, it->pageNum));
        }
        it = it->sibling_next;
    }
    CrashIf(ULONG_MAX == rangeArray.size());

    SAFEARRAY* psa = SafeArrayCreateVector(VT_UNKNOWN, 0, (ULONG)rangeArray.size());
    if (!psa) {
        for (size_t i = 0; i < rangeArray.size(); i++) {
            rangeArray[i]->Release();
        }
        return E_OUTOFMEMORY;
    }

    for (LONG i = 0; i < (LONG)rangeArray.size(); i++) {
        HRESULT hr = SafeArrayPutElement(psa, &i, rangeArray[i]);
        CrashIf(FAILED(hr));
        rangeArray[i]->Release();
    }

    *pRetVal = psa;
    return S_OK;
}
IFACEMETHODIMP AccessibleSelectionProvider::GetSelection(SAFEARRAY **pRetVal) {
    LOG("In AccessibleSelectionProvider::GetSelection\n");
    LOG("  this: %p\n", this);
    if (pRetVal == NULL)
        return E_INVALIDARG;
    JNIEnv* env = GetEnv();
    jlongArray selectedElements = static_cast<jlongArray>(env->CallObjectMethod(m_self, midGetSelection));
    if( selectedElements == NULL )
        return S_OK;
    jint size = env->GetArrayLength(selectedElements);
    if (size != 0) {
        //LOG("  size: %d\n", size);
        jlong* selectedElementsPatterns = env->GetLongArrayElements(selectedElements, JNI_FALSE);
        SAFEARRAY *psaElements = SafeArrayCreateVector(VT_I4, 0, size);
        if (psaElements == NULL) {
            return E_OUTOFMEMORY;
        }
        for (LONG idx = 0; idx < size; idx++) {
            LOG("  idx: %d\n", idx);
            LOG("  selectedElements: %p\n", reinterpret_cast<void*>(jlong_to_ptr(selectedElementsPatterns[idx])) );
            SafeArrayPutElement(psaElements, &idx, (void*)(jlong_to_ptr(selectedElementsPatterns[idx])));
        }
        env->ReleaseLongArrayElements(selectedElements, selectedElementsPatterns, JNI_FALSE);
        *pRetVal = psaElements;
    } else 
        LOG("AccessibleSelectionProvider size=%d\n" , size);
    return S_OK;
}
Exemplo n.º 17
0
void ImportDotXSI()
{

	CComPtr<XSIApplication>						l_pApplication;
	CLSID	lclsid;
	CLSIDFromProgID(L"XSI.Application", &lclsid );
	CoCreateInstance(lclsid, NULL, CLSCTX_INPROC, IID_XSIApplication, (void **)&l_pApplication);

	_variant_t args;  
	_variant_t v;  
	long l = 0 ;

	SAFEARRAY* psa = NULL;  
 
	const int cntArgs = 1 ;

	psa = ::SafeArrayCreateVector( VT_VARIANT, 0, cntArgs );  
 
	args.vt = VT_VARIANT | VT_ARRAY;  
	args.parray = psa;
 
	v = _bstr_t ( "c:\\__tmp.xsi" );
 
	SafeArrayPutElement(psa, &l, &v);  
	l++;  
 
	// more args?
	//

	VARIANT	l_vOutValue;
	l_pApplication->ExecuteScriptCommand( _bstr_t( L"SIImportDotXSIFile" ), args, &l_vOutValue ) ;


}
Exemplo n.º 18
0
//local helpers:
static FC_ARSTAT NodeListToSafeArray(FC_CGArray<FC_CArNode*>* pNList, SAFEARRAY** ppsa)
{
    HRESULT       hr;
    SAFEARRAY*    psa;
    long          i;
    long          nNodes;
    FC_CArNode*   pNode;
    const TCHAR*  pId;
    BSTR          bstr;

    if(!ppsa)
        return FC_AR_OK;

    *ppsa = NULL;

    nNodes = pNList->getUsed();
    psa = SafeArrayCreateVector(VT_BSTR, 0, nNodes);
    if(!psa)
        return FC_AR_OUTOFMEM;

    for(i=0; i<nNodes; i++)
    {
        pNode = pNList->get(i);
        pId   = pNode->getName();
#ifdef UNICODE
        bstr = SysAllocString(pId);
        hr = SafeArrayPutElement(psa, &i, bstr);
        SysFreeString(bstr);
#else
        wchar_t wBuffer[3*MAX_PATH];
        int iOk = FC_StringToWideChar(pId, wBuffer, FC_ARRAY_LEN(wBuffer));
        assert(iOk>0);
        bstr = SysAllocString(wBuffer);
        hr = SafeArrayPutElement(psa, &i, bstr);
        SysFreeString(bstr);
#endif
        if(FAILED(hr))
        {
            SafeArrayDestroy(psa);
            return FC_AR_OUTOFMEM;
        }
    }

    *ppsa = psa;
    return FC_AR_OK;
}
Exemplo n.º 19
0
void CAddIn::PutNParam(SAFEARRAY *pArray,long lIndex,VARIANT vt)
{
	ASSERT(pArray);
	ASSERT(pArray->fFeatures | FADF_VARIANT);

	HRESULT hRes = SafeArrayPutElement(pArray,&lIndex,&vt);
	ASSERT(hRes == S_OK);
}
Exemplo n.º 20
0
HRESULT CPyCOMTest::TestOptionals2(double dval, BSTR strval, short sval, SAFEARRAY **pRet)
{
	HRESULT hr = S_OK;
	SAFEARRAY *psa;
	SAFEARRAYBOUND rgsabound[1] = { 3, 0 };
	psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
	long ix[1];
	CComVariant v(dval);
	ix[0] = 0;
	SafeArrayPutElement(psa, ix, &v);
	v = strval;
	ix[0] = 1;
	SafeArrayPutElement(psa, ix, &v);
	v = sval;
	ix[0] = 2;
	SafeArrayPutElement(psa, ix, &v);
	*pRet = psa;
	return hr;
}
Exemplo n.º 21
0
	bool com_array_reader::convert_jsarray(IDispatch * pdisp)
	{
		if (!pdisp) return false;

		DISPPARAMS params = {0};
		_variant_t ret;

		DISPID id_length;
		LPOLESTR slength = L"length";

		if (FAILED(pdisp->GetIDsOfNames(IID_NULL, &slength, 1, LOCALE_USER_DEFAULT, &id_length)))
			return false;

		if (FAILED(pdisp->Invoke(id_length, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
			&params, &ret, NULL, NULL)))
			return false;

		if (FAILED(VariantChangeType(&ret, &ret, 0, VT_I4)))
			return false;

		m_lbound = 0;
		m_ubound = ret.lVal - 1;

		SAFEARRAY * psa = SafeArrayCreateVector(VT_VARIANT, 0, get_count());

		if (!psa) goto cleanup_and_return;

		for (long i = m_lbound; i <= m_ubound; ++i)
		{
			DISPID dispid = 0;
			DISPPARAMS params = {0};
			wchar_t buf[33];
			LPOLESTR name = buf;
			_variant_t element;
			HRESULT hr = S_OK;

			_itow_s(i, buf, 10);

			if (SUCCEEDED(hr)) hr = pdisp->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
			if (SUCCEEDED(hr)) hr = pdisp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, 
				&params, &element, NULL, NULL);

			if (FAILED(hr)) goto cleanup_and_return;
			if (FAILED(SafeArrayPutElement(psa, &i, &element))) goto cleanup_and_return;
		}

		m_psa = psa;
		return true;

cleanup_and_return:
		reset();
		SafeArrayDestroy(psa); 
		return false;
	}
Exemplo n.º 22
0
INT __stdcall EmbeddedUIHandler(UINT uiMessageType, MSIHANDLE hRecord)
{
	if (g_pProcessMessageMethod == NULL)
	{
		// Initialization was canceled. 
		return IDCANCEL;
	}

	VARIANT vResult;
	VariantInit(&vResult);

	VARIANT vNull;
	vNull.vt = VT_EMPTY;

	SAFEARRAY* saArgs = SafeArrayCreateVector(VT_VARIANT, 0, 2);
	VARIANT vMessageType;
	vMessageType.vt = VT_I4;
	vMessageType.lVal = (LONG) uiMessageType;
	LONG index = 0;
	HRESULT hr = SafeArrayPutElement(saArgs, &index, &vMessageType);
	if (FAILED(hr)) goto LExit;
	VARIANT vRecord;
	vRecord.vt = VT_I4;
	vRecord.lVal = (LONG) hRecord;
	index = 1;
	hr = SafeArrayPutElement(saArgs, &index, &vRecord);
	if (FAILED(hr)) goto LExit;
	
	hr = g_pProcessMessageMethod->Invoke_3(vNull, saArgs, &vResult);

LExit:
	SafeArrayDestroy(saArgs);
	if (SUCCEEDED(hr))
	{
		return vResult.intVal;
	}
	else
	{
		return -1;
	}
}
HRESULT CContextPlugin::CreateArrayOfEvents( VARIANT *pvarEvents, WMS_EVENT_TYPE *pWMSEvents, long nNumEvents)
{
    HRESULT hr = S_OK;
    long iEvents = 0;
    SAFEARRAY *psa = NULL;
    SAFEARRAYBOUND rgsabound[1];
    
    if( NULL == pvarEvents )
    {
        return( E_POINTER );
    }

    if( NULL == pWMSEvents || 0 >= nNumEvents )
    {
        return( E_INVALIDARG );   
    }
        
    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = nNumEvents;

    psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound );

    if( NULL == psa )
    {
        return ( E_OUTOFMEMORY );
    }

    for( iEvents = 0; iEvents < nNumEvents && SUCCEEDED( hr ); iEvents++ )
    {
        VARIANT varElement;

        VariantInit( &varElement );

        V_VT( &varElement ) = VT_I4;
        V_I4( &varElement ) = pWMSEvents[ iEvents ];

        hr = SafeArrayPutElement( psa, &iEvents, &varElement );
        VariantClear( &varElement );
    }

    if( FAILED( hr ) )
    {
        SafeArrayDestroy( psa );
        psa = NULL;
    }
    else
    {
        V_VT( pvarEvents ) = VT_ARRAY | VT_VARIANT;
        V_ARRAY( pvarEvents ) = psa;
    }

    return ( hr );
}
Exemplo n.º 24
0
static void
fillSafeArray (
    Tcl_Obj *pList,
    SAFEARRAY *psa,
    unsigned dim,
    long *pIndices,
    Tcl_Interp *interp,
    bool addRef)
{
    HRESULT hr;

    // Get index range.
    long lowerBound;
    hr = SafeArrayGetLBound(psa, dim, &lowerBound);
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }

    long upperBound;
    hr = SafeArrayGetUBound(psa, dim, &upperBound);
    if (FAILED(hr)) {
        _com_issue_error(hr);
    }

    int numElements;
    Tcl_Obj **pElements;
    if (Tcl_ListObjGetElements(interp, pList, &numElements, &pElements)
        != TCL_OK) {
        _com_issue_error(E_INVALIDARG);
    }

    unsigned dim1 = dim - 1;
    if (dim < SafeArrayGetDim(psa)) {
        // Create list of list for multi-dimensional array.
        for (int i = 0; i < numElements; ++i) {
            pIndices[dim1] = i;
            fillSafeArray(pElements[i], psa, dim + 1, pIndices, interp, addRef);
        }

    } else {
        for (int i = 0; i < numElements; ++i) {
            TclObject element(pElements[i]); 
            NativeValue elementVar;
            element.toNativeValue(&elementVar, Type::variant(), interp, addRef);

            pIndices[dim1] = i;
            hr = SafeArrayPutElement(psa, pIndices, &elementVar);
            if (FAILED(hr)) {
                _com_issue_error(hr);
            }
        }
    }
}
Exemplo n.º 25
0
int wdAddStringScriptArg(ScriptArgs* scriptArgs, const wchar_t* arg) 
{
	std::wstring value(arg);

	CComVariant dest(arg);
	LONG index = scriptArgs->currentIndex;
	SafeArrayPutElement(scriptArgs->args, &index, &dest);

	scriptArgs->currentIndex++;

	return SUCCESS;
}
Exemplo n.º 26
0
	void DensoRobot::Start()
	{
		/* Start the motor */
		CComVariant pVal; // probably empty
		hr = pRobot->Execute(CComBSTR(L"Motor"), CComVariant(L"1"), &pVal);
		if(FAILED(hr)) throw exception("Failed to start the robot motor!");

		/* Set the external robot speed TO DO*/ 
		CComVariant parameters; 
        parameters.vt = VT_ARRAY | VT_VARIANT; 

        SAFEARRAYBOUND bounds[1]; 
        bounds[0].lLbound = 0; 
        bounds[0].cElements = 3; 
        parameters.parray = SafeArrayCreate(VT_VARIANT, 1, bounds); 

        CComVariant varSpeed; 
        varSpeed.vt = VT_R4; 
        varSpeed.fltVal = (float)this->robotSpeed; 

        CComVariant varAcceleration; 
        varAcceleration.vt = VT_R4; 
        varAcceleration.fltVal = (float)(this->robotSpeed*this->robotSpeed/100); 

        CComVariant varDeceleration; 
		varDeceleration.vt = VT_R4; 
        varDeceleration.fltVal = (float)(this->robotSpeed*this->robotSpeed/100); 

		long index = 0; 
        SafeArrayPutElement(parameters.parray, &index, &varSpeed); 
        index = 1; 
		SafeArrayPutElement(parameters.parray, &index, &varAcceleration); 
        index = 2; 
        SafeArrayPutElement(parameters.parray, &index, &varDeceleration); 

        CComVariant vntDummy; 
        hr = pRobot->Execute(CComBSTR(L"ExtSpeed"), parameters, &vntDummy); 
		if(FAILED(hr)) throw exception("Failed to set the external robot speed!");
        parameters.Clear(); 
	}
Exemplo n.º 27
0
int wdAddElementScriptArg(ScriptArgs* scriptArgs, WebElement* element)
{
	VARIANT dest;
	dest.vt = VT_DISPATCH;
	dest.pdispVal = element->element->getWrappedElement();

	LONG index = scriptArgs->currentIndex;
	SafeArrayPutElement(scriptArgs->args, &index, &dest);

	scriptArgs->currentIndex++;

	return SUCCESS;
}
Exemplo n.º 28
0
int wdAddNumberScriptArg(ScriptArgs* scriptArgs, long number)
{
	VARIANT dest;
	dest.vt = VT_I4;
	dest.lVal = (LONG) number;	

	LONG index = scriptArgs->currentIndex;
	SafeArrayPutElement(scriptArgs->args, &index, &dest);

	scriptArgs->currentIndex++;

	return SUCCESS;
}
Exemplo n.º 29
0
int wdAddBooleanScriptArg(ScriptArgs* scriptArgs, int trueOrFalse) 
{
	VARIANT dest;
	dest.vt = VT_BOOL;
	dest.boolVal = trueOrFalse == 1;
	
	LONG index = scriptArgs->currentIndex;
	SafeArrayPutElement(scriptArgs->args, &index, &dest);

	scriptArgs->currentIndex++;

	return SUCCESS;
}
Exemplo n.º 30
0
SEXP rSetStatic(SEXP p) {
	
	// 1 - Get data from SEXP
	p = CDR(p); // Skip the first parameter: because function name
	char* strTypeName = readStringFromSexp(p); p = CDR(p);
	char* strPropertyName = readStringFromSexp(p); p = CDR(p);
	LONGLONG valueAddresse = (LONGLONG)CAR(p);

	// 2 - Prepare arguments to call proxy
	SAFEARRAY* args = SafeArrayCreateVector(VT_VARIANT, 0, 3);
	long i = 0;

	// 2.1 - Type name
	variant_t typeName(strTypeName);
	SafeArrayPutElement(args, &i, &typeName); i++;

	// 2.2 - Method name
	variant_t propertyName(strPropertyName);
	SafeArrayPutElement(args, &i, &propertyName); i++;

	// 2.3 property value
	variant_t value(valueAddresse);
	SafeArrayPutElement(args, &i, &value); i++;

	// 3 - Call the proxy
	CLR_OBJ result;
	char* errorMsg;
	HRESULT hr = callProxy(L"SetStaticProperty", args, &result, &errorMsg);

	if(FAILED(hr)) {
		Rprintf(errorMsg);
		error("Exception during netSetStatic !");
		free(errorMsg);
		return R_NilValue;
	}

	SafeArrayDestroy(args);
	return R_NilValue;
}