Esempio n. 1
0
static zval* saproxy_iter_get_data(zend_object_iterator *iter)
{
	php_com_saproxy_iter *I = (php_com_saproxy_iter*)Z_PTR(iter->data);
	VARIANT v;
	VARTYPE vt;
	SAFEARRAY *sa;

	I->indices[I->proxy->dimensions-1] = I->key;

	sa = V_ARRAY(&I->proxy->obj->v);

	if (FAILED(SafeArrayGetVartype(sa, &vt)) || vt == VT_EMPTY) {
		vt = V_VT(&I->proxy->obj->v) & ~VT_ARRAY;
	}

	VariantInit(&v);
	if (vt == VT_VARIANT) {
		SafeArrayGetElement(sa, I->indices, &v);
	} else {
		V_VT(&v) = vt;
		SafeArrayGetElement(sa, I->indices, &v.lVal);
	}

	ZVAL_NULL(&I->data);
	php_com_wrap_variant(&I->data, &v, I->proxy->obj->code_page);
	VariantClear(&v);

	return &I->data;
}
Esempio n. 2
0
void QtWMI::DisplayVariantValues(CString& strName, variant_t& var)
{	
	switch (var.vt)
	{
	case VT_BSTR:
		dprintf(L"%s=%s", strName, var.pbstrVal );		
		break;		

	case VT_UI1:
	case VT_UI2:
	case VT_UI4:
	case VT_UINT:		
		dprintf(L"%s=%lu", strName, var.uiVal);
		break;

	case VT_I1:
	case VT_I2:
	case VT_I4:
	case VT_INT:		
		dprintf(L"%s=%d",strName, var.iVal);
		break;

	case VT_BOOL:		
		dprintf(L"%s=%s",strName, (var.boolVal==VARIANT_TRUE)? L"True": L"False" );
		break;	

	case VT_ARRAY|VT_BSTR:
		{
			SAFEARRAY*	pAray=var.parray;
			LONG  nLower=0, nUpper=0;
			SafeArrayGetLBound(pAray, 1, &nLower);
			SafeArrayGetUBound(pAray, 1, &nUpper);
			_bstr_t		str;										
			for(long n=nLower; n<nUpper;n++)
			{
				SafeArrayGetElement(pAray, &n, &str);				
				dprintf(L"%s=%s",strName , str );
			}							
		}
		break;
	case VT_I4|VT_ARRAY:
		{
			SAFEARRAY*	pAray=var.parray;
			long nLower=0, nUpper=0;
			SafeArrayGetLBound(pAray, 1, &nLower);
			SafeArrayGetUBound(pAray, 1, &nUpper);
			int nVal=0;			
			for(long n=nLower; n<nUpper;n++)
			{
				SafeArrayGetElement(pAray, &n, &nVal);
				dprintf(L"%s=%d",strName, nVal );
			}							
		}
		break;	
	}
}
Esempio n. 3
0
BOOL CMediaVisDlg::EnumerateWrapped(LPCTSTR pszName, REFCLSID pCLSID, LPCTSTR pszCLSID)
{
	IWrappedPluginControl* pPlugin = NULL;

	HINSTANCE hRes = AfxGetResourceHandle();

	HRESULT hr = CoCreateInstance( pCLSID, NULL, CLSCTX_ALL,
		IID_IWrappedPluginControl, (void**)&pPlugin );

	AfxSetResourceHandle( hRes );

	if ( FAILED(hr) || pPlugin == NULL ) return FALSE;

	LPSAFEARRAY pArray = NULL;
	hr = pPlugin->Enumerate( &pArray );

	pPlugin->Release();

	if ( FAILED(hr) || pArray == NULL ) return FALSE;

	LONG pIndex[2] = { 0, 0 };
	SafeArrayGetUBound( pArray, 2, &pIndex[1] );

	if ( pIndex[1] < 0 )
	{
		SafeArrayDestroy( pArray );
		return TRUE;
	}

	for ( ; pIndex[1] >= 0; pIndex[1]-- )
	{
		CString strName, strPath;
		BSTR bsValue = NULL;

		strName = pszName;
		strName += L": ";

		pIndex[0] = 0;
		SafeArrayGetElement( pArray, pIndex, &bsValue );
		strName += bsValue;
		SysFreeString( bsValue );
		bsValue = NULL;

		pIndex[0] = 1;
		SafeArrayGetElement( pArray, pIndex, &bsValue );
		strPath = bsValue;
		SysFreeString( bsValue );
		bsValue = NULL;

		AddPlugin( strName, pszCLSID, strPath );
	}

	SafeArrayDestroy( pArray );

	return TRUE;
}
Esempio n. 4
0
/* this is a convenience function for fetching a particular
 * element from a (possibly multi-dimensional) safe array */
PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1)
{
    UINT dims;
    LONG lbound, ubound;
    LONG indices[1];
    VARTYPE vt;

    if (!V_ISARRAY(array)) {
        return 0;
    }

    dims = SafeArrayGetDim(V_ARRAY(array));

    if (dims != 1) {
        php_error_docref(NULL, E_WARNING,
                         "Can only handle single dimension variant arrays (this array has %d)", dims);
        return 0;
    }

    if (FAILED(SafeArrayGetVartype(V_ARRAY(array), &vt)) || vt == VT_EMPTY) {
        vt = V_VT(array) & ~VT_ARRAY;
    }

    /* determine the bounds */
    SafeArrayGetLBound(V_ARRAY(array), 1, &lbound);
    SafeArrayGetUBound(V_ARRAY(array), 1, &ubound);

    /* check bounds */
    if (dim1 < lbound || dim1 > ubound) {
        php_com_throw_exception(DISP_E_BADINDEX, "index out of bounds");
        return 0;
    }

    /* now fetch that element */
    VariantInit(dest);

    indices[0] = dim1;

    if (vt == VT_VARIANT) {
        SafeArrayGetElement(V_ARRAY(array), indices, dest);
    } else {
        V_VT(dest) = vt;
        /* store the value into "lVal" member of the variant.
         * This works because it is a union; since we know the variant
         * type, we end up with a working variant */
        SafeArrayGetElement(V_ARRAY(array), indices, &dest->lVal);
    }

    return 1;
}
//vrati pocet zkopirovanych stringu
int CWordManager::LoadSafeArrayToStringTable(SAFEARRAY *sarray, CStringTableImpl &str_table)
{
	LONG l_bound = 0;
	LONG u_bound = -1;

	SafeArrayGetLBound(sarray, 1, & l_bound);
	SafeArrayGetUBound(sarray, 1, & u_bound);

	str_table.Clear();


	for (LONG a = l_bound; a <= u_bound; a++)
	{
		BSTR arg;
		SafeArrayGetElement(sarray, &a, & arg);

		_bstr_t s;
		s.Assign(arg);

		str_table.Add(s);
	}
	
	SafeArrayDestroy(sarray);

	return u_bound - l_bound +1;
}
Esempio n. 6
0
	RobotPoint DensoRobot::GetCurrentPos()
	{
		CComVariant varValue;
		long i, longlBound, longUBound;

		float *positionArray = new float[6];

		hr = this->currentPosition->get_Value(&varValue);
		if(FAILED(hr)) throw exception ("Could not get the current position!");
		
		SAFEARRAY *psa = varValue.parray;
		SafeArrayGetLBound(psa, 1, &longlBound);
		SafeArrayGetUBound(psa, 1, &longUBound);
		
		int n = 0;
		for(i = longlBound; i <= longUBound; i++)
		{
			float fltResult;
			SafeArrayGetElement(psa, &i, &fltResult);		
			positionArray[n] = fltResult; 
			n++;
		}
		
		RobotPoint robotPoint((float)positionArray[0], 
							  (float)positionArray[1],
							  (float)positionArray[2],
							  (float)positionArray[3],
							  (float)positionArray[4],
							  (float)positionArray[5],
							  (float)positionArray[6]);

		return robotPoint;
	}
mscorlib::_MethodInfoPtr GetStaticMethod(mscorlib::_TypePtr type, LPCWSTR findName, int pcount)
{
	LPSAFEARRAY methods = type->GetMethods_2();
	mscorlib::_MethodInfoPtr ret;
	LONG methodCount = GetSafeArrayLen(methods);

	for (long i = 0; i < methodCount; ++i)
	{
		IUnknown* v = nullptr;

		if (SUCCEEDED(SafeArrayGetElement(methods, &i, &v)))
		{
			mscorlib::_MethodInfoPtr method = v;

			bstr_t name = method->Getname();
			LPSAFEARRAY params = method->GetParameters();
			long paramCount = GetSafeArrayLen(params);

			if (method->IsStatic && wcscmp(name.GetBSTR(), findName) == 0 && paramCount == pcount)
			{
				ret = method;
				break;
			}
		}
	}

	SafeArrayDestroy(methods);

	return ret;
}
Esempio n. 8
0
/* 
These two methods is convenient way to access function 
parameters from SAFEARRAY vector of variants
*/
VARIANT CAddIn::GetNParam(SAFEARRAY *pArray,long lIndex)
{
	ASSERT(pArray);
	ASSERT(pArray->fFeatures | FADF_VARIANT);

	VARIANT vt;
	HRESULT hRes = SafeArrayGetElement(pArray,&lIndex,&vt);
	ASSERT(hRes == S_OK);

	return vt;
}
STDMETHODIMP CXMiLFilesControl::CopyMoveFiles(/*[in]*/ BSTR pathName, /*[in]*/ SAFEARRAY* sa, /*[in]*/ VARIANT_BOOL bSilent, /*[out,retval]*/ long* nFilesCopied)
{
	if (nFilesCopied == NULL) return E_POINTER;

//	CProgressDlg dlg;
//	dlg.Create(NULL, NULL);

	int i;

	__int64 nSize = 0;
	for (i = 0; i < sa->rgsabound[0].cElements; i++)
	{
		long ix[1];
		ix[0] = i;

		BSTR bstr;
		SafeArrayGetElement(sa, ix, (void**)&bstr);

		nSize += GetTotalSizeOfFiles(_bstr_t(bstr));
	}

//	dlg.m_min = 0;
//	dlg.m_max = nSize/10;
//	dlg.m_pos = 0;

	for (i = 0; i < sa->rgsabound[0].cElements; i++)
	{
		long ix[1];
		ix[0] = i;

		BSTR bstr;
		SafeArrayGetElement(sa, ix, (void**)&bstr);

		(*nFilesCopied) += CopyMoveFile(_bstr_t(pathName), _bstr_t(bstr), bSilent, NULL/*&dlg*/);
	}

//	dlg.DestroyWindow();

	return S_OK;
}
Esempio n. 10
0
// Read Operation
int CFanmotorDlg::rreg(int reg_addr)
{
success=1;

	CString s;
	int dat=0;
	long r;
	int timeout_counter=0;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,reg_addr); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);
	int datalen=2;//in bytes

	if(this->virtual_board)
	{
		dat = ReadVirtualBoardReg(reg_addr, fOTP);
	}

	else
	{
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//r = Bridge->ReadIICdataReg(L"0000011", reg_addr, ReadAddress,datalen, &dataIn); 
		//Sleep(500);
		//r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn);//no data received.????
		//do{
		//	timeout_counter++;
		//	if (timeout_counter == TIMEOUT){
		//		DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
		//		success = 0;
		//	}
		//	r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,datalen, &dataIn); 
		//}while ((r !=34) && (timeout_counter != TIMEOUT));

			CString strByte;
			for (long i = 0; i < datalen; i++) {
				BYTE ReadByte;
				SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
				strByte.Format(L"%02x",ReadByte);
				s += strByte;
			}
			dat=use_debugdlg_main.string2int(s,2*datalen);
		//	success=1;
		//}
		//else {ErrorMsg(r);};
		VariantClear(&dataIn);
	}
	return dat;
	Sleep(20);
}
Esempio n. 11
0
void ExcelWorksheet::GetValues(ExcelData& excelData, const char* cell/* = "A1"*/)
{
	RangePtr usedRange = _worksheet->UsedRange;
	_variant_t values = usedRange->Value2;

	if (values.vt == (VT_ARRAY | VT_VARIANT) &&
		::SafeArrayGetDim(values.parray) == 2)
	{
		LONG rowLBound = 0, rowUBound = 0;
		LONG colLBound = 0, colUBound = 0;

		SafeArrayGetLBound(values.parray, 1, &rowLBound);
		SafeArrayGetUBound(values.parray, 1, &rowUBound);
		SafeArrayGetLBound(values.parray, 2, &colLBound);
		SafeArrayGetUBound(values.parray, 2, &colUBound);

		excelData.Create(rowUBound - rowLBound + 1, colUBound - colLBound + 1);

		for (int row = rowLBound; row <= rowUBound; ++row)
		{
			for (int col = colLBound; col <= colUBound; ++col)
			{
				LONG indices[] = { row, col };
				_variant_t value;
				SafeArrayGetElement(values.parray, indices, &value);

				excelData.SetValue(row - rowLBound + 1, col - colLBound + 1, value);
			}
		}

		//VARIANT* pData = NULL;
		//HRESULT hr = SafeArrayAccessData(values.parray, (void **)&pData);
		//if (SUCCEEDED(hr))
		//{
		//	int rowNum = rowUBound - rowLBound + 1;
		//	int colNum = colUBound - colLBound + 1;
		//	for (int row = rowLBound; row <= rowUBound; ++row)
		//	{
		//		for (int col = colLBound; col <= colUBound; ++col)
		//		{
		//			_variant_t v = pData[(col - colLBound)*rowNum + (row - rowLBound)];
		//			printf("%d\t", (int)(V_R8(&v)));
		//		}

		//		printf("\n");
		//	}

		//	SafeArrayUnaccessData(values.parray);
		//}
	}
}
Esempio n. 12
0
void PrintManager::CreateVectorFromSafeArray(SAFEARRAY* ReportSafeArray, std::vector<CStdString>& VecElements)
{
	long lElementCount = ReportSafeArray->rgsabound->cElements;
	for(long lCnt = 0; lCnt <lElementCount; lCnt++)
	{
		_variant_t varTitle;
		HRESULT hr=SafeArrayGetElement(ReportSafeArray,&lCnt,(void *)&varTitle);
		if(FAILED(hr))
		{
			throw std::exception ("CreateVectorFromSafeArray SafeArrayGetElement failed" );
		}
		CStdString sTitle = varTitle.bstrVal;
		VecElements.push_back(sTitle);
		VariantClear(&varTitle);
	}
}
Esempio n. 13
0
HRESULT HrGetVariantElement(SAFEARRAY *psa, int lPosition, VARIANT* pvar)
{
    HRESULT hr = S_OK;
    long    alPos[1];

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

    alPos[0] = lPosition;

    hr = SafeArrayGetElement(psa,
                             alPos,
                             pvar);
    return hr;
}
Esempio n. 14
0
DOUBLE WindDataParser::GetDoubeItemByIndex(const VARIANT& safeArray, int index)
{
	if(!IsArray(safeArray))
	{
		return 0.0;
	}

	if (VT_R8 != (safeArray.vt & VT_BSTR_BLOB) && VT_DATE != (safeArray.vt & VT_BSTR_BLOB))
	{
		return 0.0;
	}
	long lPos = (long)index;
	DOUBLE dbl = 0;

	SafeArrayGetElement(safeArray.parray, &lPos, &dbl);
	
	return dbl;
}
Esempio n. 15
0
static HRESULT VBArray_getItem(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    VBArrayInstance *vbarray;
    int i, *indexes;
    VARIANT out;
    HRESULT hres;

    TRACE("\n");

    vbarray = vbarray_this(vthis);
    if(!vbarray)
        return throw_type_error(ctx, JS_E_VBARRAY_EXPECTED, NULL);

    if(argc < SafeArrayGetDim(vbarray->safearray))
        return throw_range_error(ctx, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);

    indexes = heap_alloc(sizeof(int)*argc);
    if(!indexes)
        return E_OUTOFMEMORY;

    for(i=0; i<argc; i++) {
        hres = to_int32(ctx, argv[i], indexes+i);
        if(FAILED(hres)) {
            heap_free(indexes);
            return hres;
        }
    }

    hres = SafeArrayGetElement(vbarray->safearray, indexes, (void*)&out);
    heap_free(indexes);
    if(hres == DISP_E_BADINDEX)
        return throw_range_error(ctx, JS_E_SUBSCRIPT_OUT_OF_RANGE, NULL);
    else if(FAILED(hres))
        return hres;

    if(r) {
        hres = variant_to_jsval(&out, r);
        VariantClear(&out);
    }
    return hres;
}
Esempio n. 16
0
BOOL CADORecordset::GetChunk(FieldPtr pField, LPVOID lpData)
{
	long lngSize, lngOffSet = 0;
	_variant_t varChunk;    
	UCHAR chData;
	HRESULT hr;
	long lBytesCopied = 0;

	lngSize = pField->ActualSize;
	
	while(lngOffSet < lngSize)
	{ 
		try
		{
			varChunk = pField->GetChunk(ChunkSize);

			//Copy the data only upto the Actual Size of Field.  
            for(long lIndex = 0; lIndex <= (ChunkSize - 1); lIndex++)
            {
                hr= SafeArrayGetElement(varChunk.parray, &lIndex, &chData);
                if(SUCCEEDED(hr))
                {
                    //Take BYTE by BYTE and advance Memory Location
                    //hr = SafeArrayPutElement((SAFEARRAY FAR*)lpData, &lBytesCopied ,&chData); 
					((UCHAR*)lpData)[lBytesCopied] = chData;
                    lBytesCopied++;
                }
                else
                    break;
            }
			lngOffSet += ChunkSize;
		}
		catch(_com_error &e)
		{
			dump_com_error(e);
			return FALSE;
		}
	}

	lngOffSet = 0;
	return TRUE;
}
Esempio n. 17
0
int CFanmotorDlg::rFWData(int fType, int nByte)
{
	success=1;
	CString s;
	int dat=0;
	int timeout_counter=0;
	long r;
	CByteArray baAddr;
	baAddr.SetSize (1);   
	baAddr.SetAt(0,fType); 
	COleVariant ReadAddress(baAddr); // Create ReadAddress argument
	VARIANT dataIn;
	VariantInit(&dataIn);

	///*Sleep(50);*/
	//long r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress, 
 //                                  1, &dataIn);  
	do{
		timeout_counter++;
		if (timeout_counter == TIMEOUT){
			DisplayInforMessageBox((LPCWSTR)L"Error", (LPCWSTR)L"Device is not available.\nPlease check your hardware connection and power supply!");
			success = 0;
		}
		r = Bridge->ReadIICdataReg(L"0000011", 0x49, ReadAddress,nByte, &dataIn); 
	}while ((r !=34) && (timeout_counter != TIMEOUT));
	//{
		CString strByte;
		for (long i = 0; i < nByte; i++) {
			BYTE ReadByte;
			SafeArrayGetElement(dataIn.parray, &i, &ReadByte);
			strByte.Format(L"%02x",ReadByte);
			s += strByte;
		}
		dat=use_debugdlg_main.string2int(s,2*nByte);
		success=1;
	//}
	//else {ErrorMsg(r);};
	VariantClear(&dataIn);
	return dat;	
}
Esempio n. 18
0
STDMETHODIMP CElement::Call(BSTR name, SAFEARRAY * params, /*[out,retval]*/ VARIANT *rv)
{
  HRESULT hr; 
  long lbound = 0, ubound = -1;
  bool r = false;

	hr = SafeArrayGetLBound(params, 0, &lbound); 
  hr = SafeArrayGetUBound(params, 0, &ubound); 
  
  aux::w2a aname(name);
  XCALL_PARAMS prm(aname);

  if( lbound <= ubound )
  {
    json::value *argv = new json::value[ubound - lbound + 1];
    int argc = 0;
    for(long n = lbound; n <= ubound; ++n)
    {
      CComVariant var;
      hr = SafeArrayGetElement(params,&n, &var); 
      if(FAILED(hr))
        break;
      argv[argc++] = cvt_VARIANT_to_json_value(var);
    }
    prm.argv = argv;
    prm.argc = argc;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
    delete [] argv;
  }  
  else
  {
    prm.argv = 0;
    prm.argc = 0;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
  }
  return r? S_OK : S_FALSE;
}
Esempio n. 19
0
bool ComConvertUtils::ConvertBstrSafeArrayToStringVector(SAFEARRAY* pSafeArray , std::vector<CStdString>& vsOut)
{

	
	long lUpperBound;
	if( FAILED (SafeArrayGetUBound(pSafeArray, 1, &lUpperBound) ))
	{
		return false;
	}

	long lLowerBound;
	if( FAILED (SafeArrayGetLBound(pSafeArray, 1, &lLowerBound) ))
	{
		return false;
	}

	BSTR bstrVal;
	for(long lCount = lLowerBound; lCount <= lUpperBound; lCount ++)
	{
		if( FAILED (SafeArrayGetElement(pSafeArray, &lCount, &bstrVal) ) )
		{
			return false;
		}

		// VB seems to add a empty item at the end of the array
		if(SysStringLen(bstrVal) == 0)
		{
			return true;
		}
		
		
		CStdString sTemp(bstrVal);
		vsOut.push_back(sTemp);
		

	}

	return true;
}
/////////////////////////////////////////////////////////////////////
// OPCBrowser::MoveTo method
STDMETHODIMP COPCBrowserImpl::MoveTo( SAFEARRAY ** ppBranches )
{
   if(*ppBranches == NULL)
      return E_INVALIDARG;

   // Clear out the list
   ClearNames();

   HRESULT hr = S_OK;
   LONG lBound=0;
   LONG uBound=0;
   // ServerHandles
   hr = SafeArrayGetLBound(*ppBranches, 1, &lBound);
   if( FAILED(hr) )
      return hr;
   hr = SafeArrayGetUBound(*ppBranches, 1, &uBound);
   if( FAILED(hr) )
      return hr;

   hr = MoveToRoot();
   if( FAILED(hr) )
      return hr;

   for( LONG index=lBound; index<=uBound; index++ )
   {
      BSTR Branch;
      hr = SafeArrayGetElement(*ppBranches, &index, &Branch);
      if( FAILED(hr) )
         return hr;
      if(*Branch != 0 )
      {
         hr = m_pOPCBrowser->ChangeBrowsePosition( OPC_BROWSE_DOWN, Branch );
         SysFreeString( Branch );
         if( FAILED(hr) )
            return hr;
      }
   }
   return hr;
}
Esempio n. 21
0
STDMETHODIMP CPyCOMTest::ChangeDoubleSafeArray(SAFEARRAY** vals)
{
	UINT cDims = SafeArrayGetDim(*vals);
	if (cDims != 1) {
		return E_UNEXPECTED;
	}
	HRESULT hr;
	long ub=0, lb=0;
	SafeArrayGetUBound(*vals, 1, &ub);
	SafeArrayGetLBound(*vals, 1, &lb);
	for (long i=lb; i <= ub; i++) {
		double val;
		hr = SafeArrayGetElement(*vals, &i, &val);
		if (FAILED(hr))
			return hr;
		val *= 2;
		hr = SafeArrayPutElement(*vals, &i, &val);
		if (FAILED(hr))
			return hr;
	}
	return S_OK;
}
Esempio n. 22
0
bool ComConvertUtils::ConvertVariantBstrSafeArrayToStringVector(SAFEARRAY* pSafeArray , std::vector<CStdString>& vsOut)
{

	
	long lUpperBound;
	if( FAILED (SafeArrayGetUBound(pSafeArray, 1, &lUpperBound) ))
	{
		return false;
	}

	long lLowerBound;
	if( FAILED (SafeArrayGetLBound(pSafeArray, 1, &lLowerBound) ))
	{
		return false;
	}


	VARIANT varElement;
	for(long lCount = lLowerBound; lCount <= lUpperBound; lCount ++)
	{
		if( FAILED (SafeArrayGetElement(pSafeArray, &lCount, &varElement) ) )
		{
			return false;
		}
		
		if(varElement.vt != VT_BSTR)
		{
			return false;
		}
		
		CStdString sTemp(varElement.bstrVal);
		vsOut.push_back(sTemp);
		

	}

	return true;

}
Esempio n. 23
0
/*
for bindings, securebindings, httperrors, HTTPCustomHeaders, etc.
Take the variant array recieved from get and makes it into a semicolon delimited string
*/
int VARIANTARRAYtoCString (VARIANT var, CString& str, CCFXRequest* pRequest, char seperator )
{
	USES_CONVERSION;
	
	//
	HRESULT hr;
	
	CString e;
	
	//
	LONG lstart, lend;
	SAFEARRAY *sa = V_ARRAY( &var );
	
	//
	hr = SafeArrayGetLBound( sa, 1, &lstart );
	log_COMError(__LINE__,hr);
	hr = SafeArrayGetUBound( sa, 1, &lend );
	log_COMError(__LINE__,hr);
	
	//
	VARIANT varItem;
	VariantInit(&varItem);
	
	//
	for ( long idx=lstart; idx <= lend; idx++ )
	{
		hr = SafeArrayGetElement( sa, &idx, &varItem );
		e+=V_BSTR(&varItem);
		VariantClear(&varItem);
		if(idx!=lend) e+=seperator;
	}
	
	//
	str=e;
	
	// return count
	return (lend-lstart+1);
}
Esempio n. 24
0
void 
variantToDoublesArray( const VARIANT &var, long *pnDoubles, double **ppdblArray )
{
	if ( variantIsArrayOfDoubles( var ) ) {

		// Get the safearray from VARIANT
		SAFEARRAY* pSA = NULL;

		if (var.vt & VT_BYREF)
			//SafeArrayCopy(*(pVar.pparray), &pSA);
			pSA = *(var.pparray);
		else
			//SafeArrayCopy(pVar.parray, &pSA);
			pSA = var.parray;

		// Check dimension of the array
		if (pSA->cDims == 1) {

			// Number of elements in the array
			int cnt = pSA->rgsabound->cElements;
			if (cnt > 0) {

				*pnDoubles = cnt;

				// Resize the out array
				*ppdblArray = (double*)realloc(*ppdblArray, cnt * sizeof(double));
				if (*ppdblArray != NULL) {

					// Transfer the elements
					for (long i=0; i < cnt; i++) {
						SafeArrayGetElement( pSA, &i, (void **)((*ppdblArray)+i) );
					}
				}
			}
		}
	}
}
Esempio n. 25
0
CdIpmDoc::CdIpmDoc(LPCTSTR lpszKey, VARIANT* pArrayItem, BOOL bShowTree)
{
	USES_CONVERSION;
	Initialize();
	m_strSelectKey = lpszKey;
	m_bShowTree    = bShowTree;

	LONG dwSLBound = 0;
	LONG dwSUBound = 0;
	if (!pArrayItem)
		return;
	if (!pArrayItem->parray)
		return;
	long lDim = SafeArrayGetDim (pArrayItem->parray);
	ASSERT (lDim == 1);
	if (lDim != 1)
		return;

	HRESULT hr = SafeArrayGetLBound(pArrayItem->parray, 1, &dwSLBound);
	if(FAILED(hr))
		return;
	if(dwSLBound != 0)
		return;
	hr = SafeArrayGetUBound(pArrayItem->parray, 1, &dwSUBound);
	if(FAILED(hr))
		return;

	for (long i=dwSLBound; i<=dwSUBound; i++)
	{
		VARIANT obj;
		VariantInit(&obj);
		SafeArrayGetElement(pArrayItem->parray, &i, &obj);
		m_arrItemPath.Add(W2T(obj.bstrVal));
		VariantClear(&obj);
	}
}
Esempio n. 26
0
stdex::tString CSystemInfo::GetWmiInfo( LPCTSTR lpszQuery, LPCTSTR lpszField )
{	
	CComPtr<IWbemLocator>  pIWbemLocator;
	CComPtr<IWbemServices> pWbemServices;
	stdex::tString   strValue;

	HRESULT hr = CoInitialize(NULL);
	hr = CoInitializeSecurity( NULL, -1, NULL,	NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0);
	if (hr != S_OK && hr != RPC_E_TOO_LATE)
	{
		CoUninitialize();
		return strValue;
	}

	if(CoCreateInstance (CLSID_WbemAdministrativeLocator, NULL,	CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, \
		IID_IUnknown , reinterpret_cast<void**>(&pIWbemLocator.p)) == S_OK)
    {
        if (pIWbemLocator->ConnectServer(BSTR(L"root\\cimv2"),  \
		    NULL, NULL, NULL, 0, NULL, NULL, &pWbemServices.p) == S_OK)
	    {
		    CComPtr<IEnumWbemClassObject> pEnumObject;
            hr = pWbemServices->ExecQuery(_bstr_t("WQL"), _bstr_t(lpszQuery),WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject.p);
            if(FAILED(hr))
            {
                CoUninitialize();
                return strValue;
            }

		    hr = pEnumObject->Reset();
            if(FAILED(hr))
            {
                CoUninitialize();
                return strValue;
            }

            CComPtr<IWbemClassObject> pClassObject;

            ULONG uCount = 1, uReturned = 0;
		    hr = pEnumObject->Next(C_WAIT_WMI_TIME, uCount, &pClassObject.p, &uReturned);
		    if (SUCCEEDED(hr) && pClassObject != NULL)
		    {
			    do
			    {
                    assert(pClassObject != NULL);
				    CComVariant varValue ;
				    _bstr_t bstrName(lpszField);
				    if( pClassObject->Get( bstrName ,0 ,&varValue ,NULL ,0 ) == S_OK )
				    {
					    if(varValue.vt == VT_NULL || varValue.vt == VT_EMPTY || varValue.vt == VT_ERROR)   
						    break;
					    _bstr_t b;
					    if( varValue.vt & VT_BSTR )
					    {
						    b = &varValue;
						    strValue = stdex::tString(b);
					    }
					    else if( varValue.vt & VT_ARRAY )
					    {
						    long iLowBound = 0 , iUpBound = 0 ;
						    SafeArrayGetLBound( varValue.parray , 1 , &iLowBound ) ;
						    SafeArrayGetUBound( varValue.parray , 1 , &iUpBound ) ;
						    for( long j = iLowBound ; j <= iUpBound ; j ++ )
						    {
							    VARIANT *pvar = NULL ;
							    long temp = j ;
							    if( SafeArrayGetElement( varValue.parray , &temp , pvar ) == S_OK &&
								    pvar )
							    {
								    CComVariant varTemp ;
								    if( varTemp.ChangeType( VT_BSTR , pvar ) == S_OK )
								    {
									    if(!strValue.empty())
										    strValue += TEXT(",");
									    b = &varTemp;
									    strValue += stdex::tString(b) ;
								    }                                                                
							    }
						    }
					    }
					    else
					    {
						    if( varValue.ChangeType( VT_BSTR ) == S_OK )
						    {
							    b = &varValue;
							    strValue += stdex::tString(b) ;
						    }					
					    }
				    }
			    } while (FALSE);
		    }
	    }
    }

	CoUninitialize();   
	return strValue;
}
Esempio n. 27
0
HRESULT UiTreeWalk::AppendUiAttributes(long left, long top, IUIAutomationElement* pCurUia, long nPos, std::wstring& wstr)
{
    SAFEARRAY *rid;
    REQUIRE_SUCCESS_HR(pCurUia->GetRuntimeId(&rid));
    LONG lbound;
    REQUIRE_SUCCESS_HR(SafeArrayGetLBound(rid, 1, &lbound));
    LONG ubound;
    REQUIRE_SUCCESS_HR(SafeArrayGetUBound(rid, 1, &ubound));

    CComBSTR bstrRuntimeId;
    LONG runtimeId = 0;
    WCHAR temp[16];
    for (LONG i = lbound; i <= ubound; i++)
    {
        REQUIRE_SUCCESS_HR(SafeArrayGetElement(rid, &i, &runtimeId));
        _ltow_s(runtimeId, temp, 10);
        REQUIRE_SUCCESS_HR(bstrRuntimeId.Append(temp));
        
        if (i < ubound)
        {
            REQUIRE_SUCCESS_HR(bstrRuntimeId.Append(L"."));
        }
    }

    REQUIRE_SUCCESS_HR(SafeArrayDestroy(rid));

    if (bstrRuntimeId == NULL)
    {
        wsprintf(temp, L"%lu", reinterpret_cast<std::uintptr_t>(pCurUia));
        bstrRuntimeId = temp;
    }

    CComPtr<IUIAutomationElement> spUia(pCurUia);
    auto it = cachedAutoElements.find(bstrRuntimeId);
    if (it == cachedAutoElements.end())
    {
        cachedAutoElements.insert(std::make_pair(bstrRuntimeId, spUia));
    }
    else
    {
        it->second = spUia;
    }

    CComBSTR bstrClass;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentClassName(&bstrClass));
    bstrClass = bstrClass == NULL ? L"" : bstrClass;
    std::wstring shortClass(bstrClass, SysStringLen(bstrClass));
    bool bStartWith = XmlEncode(shortClass, MaxNameLength);
    if (bStartWith == true || shortClass.length() >= MaxNameLength)
    {
        shortClass.insert(0, L"starts-with:");
    }

    CComBSTR bstrName;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentName(&bstrName));
    bstrName = bstrName == NULL ? L"" : bstrName;

    std::wstring shortName(bstrName, SysStringLen(bstrName));
    bStartWith = XmlEncode(shortName, MaxNameLength);

    if (bStartWith == true || shortName.length() >= MaxNameLength)
    {
        shortName.insert(0, L"starts-with:");
    }

    CComBSTR bstrCtrlType;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentLocalizedControlType(&bstrCtrlType));
    bstrCtrlType = bstrCtrlType == NULL ? L"" : bstrCtrlType;

    CONTROLTYPEID cid;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentControlType(&cid));

    CComBSTR bstrProgrammaticName;
    if (cid >= UIA_ButtonControlTypeId && UIA_ButtonControlTypeId <= UIA_AppBarControlTypeId)
    {
        REQUIRE_SUCCESS_HR(bstrProgrammaticName.Append(gc_controlTypesTable[cid - UIA_ButtonControlTypeId].pszName));
    }

    // CurrentLocalizedControlType can be empty: Cortana set reminder Time button's parent
    if (bstrProgrammaticName.Length() == 0)
    {
        bstrProgrammaticName = L"Unknown";
    }

    CComBSTR bstrAutoId;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentAutomationId(&bstrAutoId));
    bstrAutoId = bstrAutoId == NULL ? L"" : bstrAutoId;

    std::wstring shortAutoId(bstrAutoId, SysStringLen(bstrAutoId));
    bStartWith = XmlEncode(shortAutoId, MaxNameLength);

    if (bStartWith == true || shortAutoId.length() >= MaxNameLength)
    {
        shortAutoId.insert(0, L"starts-with:");
    }

    RECT rect;
    REQUIRE_SUCCESS_HR(pCurUia->get_CurrentBoundingRectangle(&rect));

    WCHAR chPos[16];
    if (nPos <= 0)
    {
        wsprintf(chPos, L"");
    }
    else
    {
        wsprintf(chPos, L"%d", nPos + 1); // xpath index starts at 1
    } 

    wsprintf(UiTreeWalk::s_chBuffer,
        c_chNodeFormat,
        bstrProgrammaticName.m_str,
        bstrCtrlType.m_str,
        shortClass.c_str(),
        shortName.c_str(),
        shortAutoId.c_str(),
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top,
        left - rect.left,
        top - rect.top,
        chPos,
        bstrRuntimeId.m_str);

    if (wcslen(UiTreeWalk::s_chBuffer) > 0)
    {
        wstr.append(UiTreeWalk::s_chBuffer);
    }

    return S_OK;
}
Esempio n. 28
0
char __declspec(dllexport) ** __stdcall
vbVariantToCSL( VARIANT *vList )

{
    char **papszResult = NULL;
    SAFEARRAY *psSA;
    long nLBound, nUBound;
    VARTYPE eVartype;

/* -------------------------------------------------------------------- */
/*      Get and verify info about safe array.                           */
/* -------------------------------------------------------------------- */
    if( vList == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "VARIANT is NULL in VariantToCSL()." );
        return NULL;
    }

    if( vList->vt == (VT_BSTR | VT_ARRAY | VT_BYREF) )
        psSA = *(vList->pparray);
    else if( vList->vt == (VT_BSTR | VT_ARRAY) )
        psSA = vList->parray;
    else
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "VARIANT is wrong type (%x).",
                  vList->vt );
        return NULL;
    }

    if( SafeArrayGetDim(psSA) != 1 )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Wrong dimension in array (%d)",
                  SafeArrayGetDim(psSA) );
        return NULL;
    }

    if( FAILED(SafeArrayGetLBound( psSA, 1, &nLBound ))
        || FAILED(SafeArrayGetUBound( psSA, 1, &nUBound)) )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "SafeARrayGet{L,U}Bound() failed." );
        return NULL;
    }

    if( nUBound < nLBound )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Crazy L/U Bound (L=%d, U=%d)",
                  nLBound, nUBound );
        return NULL;
    }

    SafeArrayGetVartype(psSA, &eVartype );
    if( eVartype != VT_BSTR )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "SafeArray contains type %d instead of VT_BSTR.",
                  eVartype );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Create string list from safe array BSTRings.                    */
/* -------------------------------------------------------------------- */
    papszResult = (char **) CPLCalloc(sizeof(char *),(nUBound-nLBound+2));

    for( long iElement = nLBound; iElement <= nUBound; iElement++ )
    {
        BSTR bstrValue;
        char szValue[5000];

        if( FAILED(SafeArrayGetElement(psSA, &iElement, &bstrValue)) )
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                      "SafeArrayGetElement(%d) failed.",
                      iElement );
            CSLDestroy( papszResult );
            return NULL;
        }

        sprintf( szValue, "%S", bstrValue );
        papszResult[iElement - nLBound] = CPLStrdup( szValue );
    }

    return papszResult;
}
Esempio n. 29
0
void QtWMI::OnQueryWMI()
{		
	CString strQuery;
	strQuery.Format(L"select * from Win32_%s", ui.cboWMIClasses->currentText().toStdWString().c_str() );	
	IWbemLocator *pLoc = NULL;	
	IWbemServices *pSvc = NULL;
	IEnumWbemClassObject* pEnumerator = NULL;
	IWbemClassObject *pclsObj=NULL;
	HRESULT hr=E_FAIL;

	do 
	{
		hr=CoCreateInstance(CLSID_WbemLocator,0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
		if (FAILED(hr) )		break;

		hr=pLoc->ConnectServer(	_bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pSvc);
		if (FAILED(hr) )		break;

		hr=CoSetProxyBlanket( pSvc,  RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, 
			RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
		if (FAILED(hr) )		break;

		hr=pSvc->ExecQuery( _bstr_t(L"WQL"),  bstr_t(strQuery), 
			WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,  NULL, &pEnumerator);
		if (FAILED(hr) )		break;

		ULONG		uReturn=0;
		variant_t		vtProp;	
		vtProp.Clear();						
		SAFEARRAY* psaNames=NULL;
		LONG nLower=0, nUpper=0;		
		_bstr_t		PropName;
		CString s;

		while (pEnumerator)
		{
			pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
			if(!uReturn)     break;   

			hr=pclsObj->GetNames(NULL, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
			if (hr==WBEM_S_NO_ERROR )
			{
				nLower=nUpper=0;

				SafeArrayGetLBound(psaNames, 1, &nLower);
				SafeArrayGetUBound(psaNames, 1, &nUpper);
				ui.lbDebug->clear();

				for (long i = nLower; i <= nUpper; i++) 
				{					
					SafeArrayGetElement(psaNames, &i, &PropName);	
					s.Format(L"%s", PropName);							
					hr = pclsObj->Get(s, 0, &vtProp, 0, 0);					
					if (hr==WBEM_S_NO_ERROR)																
						DisplayVariantValues(s, vtProp);	
					vtProp.Clear();						
				}					
			}
			if (psaNames)
				::SafeArrayDestroy(psaNames);	
			SAFE_RELEASE(pclsObj);	
		}		

	} while (0);

	SAFE_RELEASE(pEnumerator);
	SAFE_RELEASE(pclsObj);	
	SAFE_RELEASE(pSvc);
	SAFE_RELEASE(pLoc);
}
// **************************************************************************
//
//	CAdvClientDlg::OnDiskdetails()
//
// Description:
//		Enumerates the properties of the C: drive using the 'GetNames()'
//		technique. The technique uses safearrays.
//
// Parameters:
//		None.
//
// Returns:
//		Nothing.
//
// Globals accessed:
//		None.
//
// Globals modified:
//		None.
//
//===========================================================================
void CAdvClientDlg::OnDiskdetails() 
{
	HRESULT  hRes;
	long lLower, lUpper, lCount; 
	SAFEARRAY *psaNames = NULL;
	BSTR PropName = NULL;
	VARIANT varString, pVal;
	WCHAR *pBuf;
	CString clMyBuff;

	IWbemClassObject *pDriveInst = NULL;
	IWbemQualifierSet *pQualSet = NULL;

	VariantInit(&varString);
	VariantInit(&pVal);

	m_outputList.ResetContent();
	m_outputList.AddString(_T("working..."));

	//-------------------------------
	// Get the instance for C: drive.
	BSTR driveName = SysAllocString(L"Win32_LogicalDisk.DeviceID=\"C:\"");
	if (!driveName)
	{
		TRACE(_T("SysAllocString failed: not enough memory\n"));
		return;
	}
	BSTR cimType = SysAllocString(L"CIMTYPE");
	if (!cimType)
	{
		SysFreeString(driveName);
		TRACE(_T("SysAllocString failed: not enough memory\n"));
		return;
	}		
	BSTR keyQual = SysAllocString(L"key");
	if (!keyQual)
	{
		SysFreeString(driveName);
		SysFreeString(cimType);
		TRACE(_T("SysAllocString failed: not enough memory\n"));
		return;
	}

    if((hRes = m_pIWbemServices->GetObject(driveName,
										0L,
										NULL,
										&pDriveInst,
										NULL)) == S_OK)
	{

		m_outputList.ResetContent();

		//-------------------------------
		// Get the property names
		if((hRes = pDriveInst->GetNames(NULL, 
										WBEM_FLAG_ALWAYS | 
										WBEM_FLAG_NONSYSTEM_ONLY, 
										NULL, 
										&psaNames)) == S_OK)
		{
			//-------------------------------
			// Get the upper and lower bounds of the Names array
			if((hRes = SafeArrayGetLBound(psaNames, 1, &lLower)) != S_OK) 
			{
				TRACE(_T("Couldn't get safe array lbound\n"));
				SafeArrayDestroy(psaNames);
				return;
			}

			//-------------------------------
			if((hRes = SafeArrayGetUBound(psaNames, 1, &lUpper)) != S_OK) 
			{
				TRACE(_T("Couldn't get safe array ubound\n"));
				SafeArrayDestroy(psaNames);
				return;
			}

		
			//-------------------------------
			// For all properties...
			for (lCount = lLower; lCount <= lUpper; lCount++) 
			{
				//-----------------------------------------------
				// I'm formatting each property as:
				//   name (type) ==> value
				//-----------------------------------------------

				//-------------------------------
				// get the property name for this element
				if((hRes = SafeArrayGetElement(psaNames, 
												&lCount, 
												&PropName)) == S_OK)
				{
					clMyBuff = PropName;

					// print variable type for property value
					clMyBuff += _T(" (");

					// Get pointer to property qualifiers
					// this mess is due to the fact that system properties don't have qualifiers
					if ((pDriveInst->GetPropertyQualifierSet(PropName, &pQualSet)) == S_OK) 
					{
						// Get and print syntax attribute (if any)
						if ((pQualSet->Get(cimType, 0L, &pVal, NULL)) == S_OK) 
						{
						   clMyBuff += V_BSTR(&pVal);
						} 
						else if (hRes != WBEM_E_NOT_FOUND) 
						{  // some other error
						   TRACE(_T("Could not get syntax qualifier\n"));
						   break;
						}
						VariantClear(&pVal);

						//-------------------------------
						// If this is a key field, print an asterisk
						if(((hRes = pQualSet->Get(keyQual, 
												0L, 
												&pVal, 
												NULL)) == S_OK) && 
							(pVal.boolVal))
						{ // Yes, it's a key
						   clMyBuff += _T(")*");
						} 
						else if (hRes == WBEM_E_NOT_FOUND) 
						{  // not a key qualifier
						   clMyBuff += _T(")");
						} 
						else 
						{ // some other error
						   TRACE(_T("Could not get key qualifier\n"));
						   break;
						}
						// done with the qualifierSet.
						if (pQualSet)
						{ 
							pQualSet->Release(); 
							pQualSet = NULL;
						}
					} 
					else 
					{
						clMyBuff += _T(")");
					} //endif pDriveClass->GetPropertyQualifierSet()

					//-------------------------------
					// Get the value for the property.
					if((hRes = pDriveInst->Get(PropName, 
												0L, 
												&varString, 
												NULL, NULL)) == S_OK) 
					{
						// Print the value
						clMyBuff += _T("   ==> ");
						clMyBuff += ValueToString(&varString, &pBuf);
						
						m_outputList.AddString(clMyBuff);

						free(pBuf); // allocated by ValueToString()
					}
					else
					{
						TRACE(_T("Couldn't get Property Value\n"));
						break;
					} //endif pDriveClass->Get()

					VariantClear(&varString);
					VariantClear(&pVal);
				}
				else // SafeArrayGetElement() failed
				{
					TRACE(_T("Couldn't get safe array element\n"));
					break;
				} //endif SafeArrayGetElement()

			} // endfor

			// cleanup.
			SysFreeString(PropName);
			SysFreeString(keyQual);
			SysFreeString(cimType);
			SafeArrayDestroy(psaNames);
			VariantClear(&varString);
			VariantClear(&pVal);
		}
		else // pDriveClass->GetNames() failed
		{
			TRACE(_T("Couldn't GetNames\n"));
		} //endif pDriveClass->GetNames()

		// done with drive instance.
		if (pDriveInst)
		{ 
			pDriveInst->Release(); 
			pDriveInst = NULL;
		}
	} //endif GetObject()
}