Exemple #1
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;	
	}
}
Exemple #2
0
//==============================================================================
// 1D array of ints, dim unspecified, allow Nx1 or 1xN arrays
int g_CheckVariantArray( int * pnDim1, VARIANT vMtx, int ** ppiMtx ){
  SAFEARRAY * psaMtx;
  int nDims;
  long iDim1, iDim2;
  VARTYPE tSaType;

  psaMtx = vMtx.parray;
  *pnDim1 = 0;

  if( vMtx.vt != (VT_ARRAY|VT_I4)){
    CP_printf("\ng_CheckVariantArray(): wrong VARIANT type, expecting array of ints!\n");
    return 1;
  }

  SafeArrayGetVartype( psaMtx, &tSaType );
  if( tSaType != VT_I4 ){
    CP_printf("\ng_CheckVariantArray(): wrong array type, expecting array of ints!\n");
    return 1;
  }

  nDims = SafeArrayGetDim( psaMtx );
  if( nDims !=2 && nDims !=1 ) {    // Allow Nx1 or 1xN arrays
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting 1xN, or Nx1 array!\n");
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 1, &iDim1 );
  if( iDim1 != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting 1xN, or Nx1 array!\n");
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 1, &iDim1 );

  if( nDims == 2 ) {
    SafeArrayGetLBound( psaMtx, 2, &iDim2 );
    if( iDim2 != 0) {
      CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting 1xN, or Nx1 array!\n");
      return 1;
    }
    SafeArrayGetUBound( psaMtx, 2, &iDim2 );
  }
  else 
    iDim2 = 0;

  // stupid Matlab hack allowing any 2D array with one redundant dim
  if( (iDim2 != 0) && (iDim1 != 0)) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting 1xN, or Nx1 array!\n");
    return 1;
  }

  *pnDim1 = iDim1 + iDim2 + 1;  // if we get here, one size is always zero
  SafeArrayAccessData(psaMtx, (void **) ppiMtx);  // Get data pointer

  return 0;
}
Exemple #3
0
//==============================================================================
// 2D array of doubles 
int g_CheckVariantArray( int nDim1, int nDim2, VARIANT vMtx, double ** ppdMtx ){
  SAFEARRAY * psaMtx;
  int nDims;
  long iDim;
  VARTYPE tSaType;

  psaMtx = vMtx.parray;

  if( vMtx.vt != (VT_ARRAY|VT_R8)){
    CP_printf("\ng_CheckVariantArray(): wrong VARIANT type, expecting array of doubles!\n");
    return 1;
  }

  SafeArrayGetVartype( psaMtx, &tSaType );
  if( tSaType != VT_R8 ){
    CP_printf("\ng_CheckVariantArray(): wrong array type, expecting array of doubles!\n");
    return 1;
  }

  nDims = SafeArrayGetDim( psaMtx );
  if( nDims !=2 ) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dx%d array!\n", 
                                                            nDim1, nDim2 );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 1, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dx%d array!\n", 
                                                            nDim1, nDim2 );
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 1, &iDim );
  if( iDim+1 != nDim1) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dx%d array!\n",
                                                            nDim1, nDim2 );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 2, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dx%d array!\n", 
                                                            nDim1, nDim2 );
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 2, &iDim );
  if( iDim+1 != nDim2) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dx%d array!\n",
                                                            nDim1, nDim2 );
    return 1;
  }
  SafeArrayAccessData(psaMtx, (void **) ppdMtx);  // Get data pointer

  return 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);
		//}
	}
}
HRESULT
GetLPBYTEtoOctetString(VARIANT * pVar, LPBYTE * ppByte)
{
    HRESULT hr = E_FAIL;
    void HUGEP *pArray;
    long lLBound, lUBound, cElements;

    if ((!pVar) || (!ppByte))
	return E_INVALIDARG;
    if ((pVar->n1.n2.vt) != (VT_UI1 | VT_ARRAY))
	return E_INVALIDARG;

    hr = SafeArrayGetLBound(V_ARRAY(pVar), 1, &lLBound);
    hr = SafeArrayGetUBound(V_ARRAY(pVar), 1, &lUBound);

    cElements = lUBound - lLBound + 1;
    hr = SafeArrayAccessData(V_ARRAY(pVar), &pArray);
    if (SUCCEEDED(hr)) {
	LPBYTE pTemp = (LPBYTE) pArray;
	*ppByte = (LPBYTE) CoTaskMemAlloc(cElements);
	if (*ppByte)
	    memcpy(*ppByte, pTemp, cElements);
	else
	    hr = E_OUTOFMEMORY;
    }
    SafeArrayUnaccessData(V_ARRAY(pVar));

    return hr;
}
 /**
 * Finds the associated Win32_NetworkAdapterConfiguration for Win32_NetworkAdapter adapterObj.
 * Iterates through the IP addresses associated with the adapter calling
 * stringToAdaptorIp() to choose the highest priority address (according to EnumIPSelectionPriority)
 * as the adapter address which is used to populate adapter->userData->ipAddr.
 * If two addresses have the same highest priority, then the first one seen is chosen.
 */
static void readIpAddressesWin32(IWbemServices *pNamespace, IWbemClassObject *adapterObj, SFLAdaptor *adaptor)
{
	IEnumWbemClassObject *configEnum;
	HRESULT hr = associatorsOf(pNamespace, adapterObj,
							   L"Win32_NetworkAdapterSetting",
							   L"Win32_NetworkAdapterConfiguration",
							   L"Setting", &configEnum);
	if (SUCCEEDED(hr)) {
		IWbemClassObject *configObj;
		ULONG configCount;
		hr = configEnum->Next(WBEM_INFINITE, 1, &configObj, &configCount);
		if (SUCCEEDED(hr) && configCount == 1) {
			VARIANT addresses;
			hr = configObj->Get(L"IPAddress", 0, &addresses, 0, 0);
			if (WBEM_S_NO_ERROR == hr && addresses.vt == (VT_ARRAY | VT_BSTR))  {
				SAFEARRAY *sa = V_ARRAY(&addresses);
				LONG lstart, lend;
				hr = SafeArrayGetLBound(sa, 1, &lstart);
				hr = SafeArrayGetUBound(sa, 1, &lend);
				BSTR *pbstr;
				hr = SafeArrayAccessData(sa, (void HUGEP **)&pbstr);
				if (SUCCEEDED(hr)) {
					for (LONG idx=lstart; idx <= lend; idx++) {		
						PCWSTR addrStr = pbstr[idx];
						stringToAdaptorIp(addrStr, adaptor);
					}
					SafeArrayUnaccessData(sa);
				}
			}
			VariantClear(&addresses);
			configObj->Release();
		}
		configEnum->Release();
	}
}
//Function for handling Octet Strings returned by variants
//It allocates memory for data, copies the data to the buffer, and returns a pointer to the buffer.
//Caller must free the buffer with CoTaskMemFree.
HRESULT GetLPBYTEtoOctetString(VARIANT *pVar, //IN. Pointer to variant containing the octetstring.
                               LPBYTE *ppByte //OUT. Return LPBYTE to the data represented in octetstring.
							   )
{
HRESULT hr = E_FAIL;
//Check args
if ((!pVar)||(!ppByte))
  return E_INVALIDARG;
//Check the variant type for unsigned char array (octet string).
if ((pVar->vt)!=(VT_UI1|VT_ARRAY))
  return E_INVALIDARG;

void HUGEP *pArray;
long lLBound, lUBound;
hr = SafeArrayGetLBound(V_ARRAY(pVar), 1, &lLBound);
hr = SafeArrayGetUBound(V_ARRAY(pVar), 1, &lUBound);
//Get the count of elements
long cElements = lUBound-lLBound + 1;
hr = SafeArrayAccessData( V_ARRAY(pVar),
							  &pArray );
if (SUCCEEDED(hr))
{
 LPBYTE pTemp = (LPBYTE)pArray;
 *ppByte = (LPBYTE) CoTaskMemAlloc(cElements);
 if (*ppByte)
    memcpy(*ppByte, pTemp, cElements);
 else
	hr = E_OUTOFMEMORY;
}
SafeArrayUnaccessData( V_ARRAY(pVar) );

return hr;
}
Exemple #8
0
    safearray_t( SAFEARRAY *& p ) : psa_( p ), pdata_(0), size_(0) {
        SafeArrayAccessData( psa_, reinterpret_cast<void **>(&pdata_) );
		LONG lBound, uBound;
		SafeArrayGetLBound( psa_, 1, &lBound );
		SafeArrayGetUBound( psa_, 1, &uBound );
		size_ = uBound - lBound + 1;
    }
Exemple #9
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;
	}
//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;
}
Exemple #11
0
static HRESULT VBArray_ubound(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    VBArrayInstance *vbarray;
    int dim;
    HRESULT hres;

    TRACE("\n");

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

    if(argc) {
        hres = to_int32(ctx, argv[0], &dim);
        if(FAILED(hres))
            return hres;
    } else
        dim = 1;

    hres = SafeArrayGetUBound(vbarray->safearray, dim, &dim);
    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)
        *r = jsval_number(dim);
    return S_OK;
}
Exemple #12
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;
}
zend_object_iterator *php_com_saproxy_iter_get(zend_class_entry *ce, zval *object, int by_ref)
{
	php_com_saproxy *proxy = SA_FETCH(object);
	php_com_saproxy_iter *I;
	int i;

	if (by_ref) {
		zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
		return NULL;
	}

	I = ecalloc(1, sizeof(*I));
	I->iter.funcs = &saproxy_iter_funcs;
	Z_PTR(I->iter.data) = I;

	I->proxy = proxy;
	ZVAL_COPY(&I->proxy_obj, object);

	I->indices = safe_emalloc(proxy->dimensions + 1, sizeof(LONG), 0);
	for (i = 0; i < proxy->dimensions; i++) {
		convert_to_long(&proxy->indices[i]);
		I->indices[i] = (LONG)Z_LVAL(proxy->indices[i]);
	}

	SafeArrayGetLBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &I->imin);
	SafeArrayGetUBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &I->imax);

	I->key = I->imin;

	return &I->iter;
}
Exemple #14
0
STDMETHODIMP CPoint::Length(/* in */ VARIANT var, /*[out, retval]*/ double *pSum) {
  assert(pSum);
  assert(var.vt == (VT_ARRAY | VT_UNKNOWN));
  SAFEARRAY *psa = var.parray;
  assert(SafeArrayGetDim(psa) == 1);
  long ubound, lbound;
  HRESULT hr = SafeArrayGetUBound(psa, 1, &ubound);
  if(!SUCCEEDED(hr)) return hr;
  hr = SafeArrayGetLBound(psa, 1, &lbound);
  if(!SUCCEEDED(hr)) return hr;
  IUnknown **prgn;
  hr = SafeArrayAccessData(psa, (void**)&prgn);
  if(!SUCCEEDED(hr)) return hr;
  *pSum = 0;
  for (long i = lbound + 1; i <= ubound; i++) {
    IPoint *p1, *p2;
    hr = prgn[i-1]->QueryInterface(IID_IPoint, (void**)&p1);
    if(!SUCCEEDED(hr)) return hr;
    hr = prgn[i]->QueryInterface(IID_IPoint, (void**)&p2);
    if(!SUCCEEDED(hr)) return hr;
    long x1, x2, y1, y2;
    hr = p1->GetCoords(&x1, &y1);
    if(!SUCCEEDED(hr)) return hr;
    hr = p2->GetCoords(&x2, &y2);
    if(!SUCCEEDED(hr)) return hr;
    *pSum += sqrt(pow((double)(x2-x1), 2.0) + pow((double)(y2-y1), 2.0));
    p1->Release();
    p2->Release();
  }
  SafeArrayUnaccessData(psa);
  return S_OK;
}
void BOSSamp::BuildObject(LPDISPATCH commArea) 
{
	// TODO: Add your dispatch handler code here

	//
	// Map commArea onto a CICS OLE Buffer object
	//
	CclBuffer pBuffer = CclBuffer(commArea);
	//
	// Extract the variant from the CICS OLE buffer object, and calculate
	// the bounding information
	//
	COleVariant variant = COleVariant(pBuffer.Data());
	unsigned long i,saSize=0;
	long uBound, lBound;
	void * saData;
	for ( i = 1; i<= SafeArrayGetDim (variant.parray ); i++ );
	{
		SafeArrayGetLBound ( variant.parray, i , &lBound );
		SafeArrayGetUBound ( variant.parray, i, &uBound );
		saSize = saSize + uBound - lBound + 1;
	}
	SafeArrayAccessData ( variant.parray, &saData );
	//
	// Create a new CICS C++ Buffer object, prime it with the contents of the
	// safe array
	//
	CclBuf* buffer = new CclBuf(saSize,saData);
	SafeArrayUnlock(variant.parray);
	//
	// Extract the business objects from the buffer
	//
	int dataLength = buffer->dataLength();
	name = CString((char *)buffer->dataArea());
	if (name.GetLength() > dataLength) { name = name.Left(dataLength); }
	int nameLen = name.GetLength() + 1;
	if (nameLen < dataLength)
	{
		yearsService = *(short *)buffer->dataArea(nameLen);
		if (nameLen + sizeof(yearsService) < dataLength )
		{
			doB = *(CTime *)buffer->dataArea(nameLen + sizeof(yearsService));
		}
		else
		{
			doB = CTime::GetCurrentTime();
		}
	}
	else
	{
		yearsService = 0;
		doB = CTime::GetCurrentTime();
	}
	//
	// Detach and release the 'mapped' buffer object
	//
	pBuffer.DetachDispatch();
	pBuffer.ReleaseDispatch();
}
long GetSafeArrayLen(LPSAFEARRAY psa)
{
	long ubound = 0;

	SafeArrayGetUBound(psa, 1, &ubound);

	return ubound + 1;
}
Exemple #17
0
//==============================================================================
// 2D array of ints, both dims unspecified 
int g_CheckVariantArray( int * pnDim1, int * pnDim2, VARIANT vMtx, int ** ppiMtx ){
  SAFEARRAY * psaMtx;
  int nDims;
  long iDim;
  VARTYPE tSaType;

  psaMtx = vMtx.parray;
  *pnDim1 = 0;
  *pnDim2 = 0;

  if( vMtx.vt != (VT_ARRAY|VT_I4)){
    CP_printf("\ng_CheckVariantArray(): wrong VARIANT type, expecting array of ints!\n");
    return 1;
  }

  SafeArrayGetVartype( psaMtx, &tSaType );
  if( tSaType != VT_I4 ){
    CP_printf("\ng_CheckVariantArray(): wrong array type, expecting array of 4-byte integers!\n");
    return 1;
  }

  nDims = SafeArrayGetDim( psaMtx );
  if( nDims !=2 ) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions\n" );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 1, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions!\n" );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 2, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions\n" );
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 1, &iDim );
  iDim++;   // we return the size, which is upperbound +1
  * pnDim1 = iDim; 
  SafeArrayGetUBound( psaMtx, 2, &iDim );
  iDim++;   // we return the size, which is upperbound +1
  * pnDim2 = iDim; 
  SafeArrayAccessData(psaMtx, (void **) ppiMtx);  // Get data pointer

  return 0;
}
Exemple #18
0
long CSafeArray::GetUBound(UINT nDim)
{
	ASSERT(m_pArray!=NULL);
	long lRetv=-1;
	HRESULT hr=SafeArrayGetUBound(m_pArray, nDim, &lRetv);
	ASSERT(SUCCEEDED(hr));
	return lRetv;
}
Exemple #19
0
unsigned vtSize(VARIANT &vt) {
	if (V_VT(&vt) != (VT_ARRAY | VT_UI1))
		return 0;
	long lb,ub;
	if (FAILED(SafeArrayGetLBound(V_ARRAY(&vt),1,&lb)) ||
		FAILED(SafeArrayGetUBound(V_ARRAY(&vt),1,&ub)))
		return 0;
	return ub - lb + 1;
}
Exemple #20
0
static HRESULT WINAPI DEVENUM_IPropertyBag_Write(
    LPPROPERTYBAG iface,
    LPCOLESTR pszPropName,
    VARIANT* pVar)
{
    RegPropBagImpl *This = impl_from_IPropertyBag(iface);
    LPVOID lpData = NULL;
    DWORD cbData = 0;
    DWORD dwType = 0;
    HRESULT res = S_OK;

    TRACE("(%p)->(%s, %p)\n", This, debugstr_w(pszPropName), pVar);

    switch (V_VT(pVar))
    {
    case VT_BSTR:
    case VT_LPWSTR:
        TRACE("writing %s\n", debugstr_w(V_UNION(pVar, bstrVal)));
        lpData = V_UNION(pVar, bstrVal);
        dwType = REG_SZ;
        cbData = (lstrlenW(V_UNION(pVar, bstrVal)) + 1) * sizeof(WCHAR);
        break;
    case VT_I4:
    case VT_UI4:
        TRACE("writing %u\n", V_UNION(pVar, ulVal));
        lpData = &V_UNION(pVar, ulVal);
        dwType = REG_DWORD;
        cbData = sizeof(DWORD);
        break;
    case VT_ARRAY | VT_UI1:
    {
        LONG lUbound = 0;
        LONG lLbound = 0;
        dwType = REG_BINARY;
        res = SafeArrayGetLBound(V_UNION(pVar, parray), 1, &lLbound);
        res = SafeArrayGetUBound(V_UNION(pVar, parray), 1, &lUbound);
        cbData = (lUbound - lLbound + 1) /* * sizeof(BYTE)*/;
        TRACE("cbData: %d\n", cbData);
        res = SafeArrayAccessData(V_UNION(pVar, parray), &lpData);
        break;
    }
    default:
        FIXME("Variant type %d not handled\n", V_VT(pVar));
        return E_FAIL;
    }

    if (RegSetValueExW(This->hkey,
                       pszPropName, 0,
                       dwType, lpData, cbData) != ERROR_SUCCESS)
        res = E_FAIL;

    if (V_VT(pVar) & VT_ARRAY)
        res = SafeArrayUnaccessData(V_UNION(pVar, parray));

    return res;
}
HRESULT CSoftHIDInputKbdMapper::ProcessKbdOutput(SAFEARRAY* psa)
/*++
Routine Description:
    Processes keyboard output report.

Synchronization: 
    None
 
Arguments:
    psa - pointer to safearray containing Output Report data
    
Return Value:
    S_OK
        Success
    E_UNEXPECTED
        Unxpected size of Output Report data buffer
    E_FAIL
        Could not report indicator status to keyboard object.
--*/
{
    BYTE HUGEP*                   pArrayData = NULL;
    LONG                          lLBound = 0;
    LONG                          lUBound = 0;
    HRESULT                       hr = S_OK;
    KEYBOARD_INDICATOR_PARAMETERS Indicator; ZeroMemory(&Indicator, sizeof(Indicator));

    IfFalseHrGo(NULL != m_piSoftKeyboard, E_FAIL);

    // Get SAFEARRAY size
    IfFailHrGo(SafeArrayGetLBound(psa, 1, &lLBound));
    IfFailHrGo(SafeArrayGetUBound(psa, 1, &lUBound));
    // Check the size of Output Report data
    IfFalseHrGo(1 == (lUBound - lLBound + 1), E_UNEXPECTED);

    IfFailHrGo(::SafeArrayAccessData(psa, (void HUGEP**)&pArrayData));

    // Only 5 least significant bits are valid in output report byte.
    // TODO: this would be controlled by OutputReportMask property later.
    Indicator.usLedFlags = pArrayData[0] & 0xE0;

    IfFailHrGo(::SafeArrayUnaccessData(psa));

    IfFailHrGo(m_piSoftKeyboard->put_Indicators(&Indicator));

Exit:
    // the safe array was allocated by the call to
    // m_piSoftProtXlator->ReadOutputPort in CSoftHID::Run.
    // Now we are done with it so we should free it here.
    if (NULL != psa)
    {
        (void)::SafeArrayDestroy(psa);
    }

    return hr;

} // CSoftHIDInputKbdMapper::ProcessKbdOutput
Exemple #22
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;
}
Exemple #23
0
HRESULT CDisk::GetFormat(VARIANT *buf, DSK_FORMAT **bufout, unsigned length)
{
	long lBound, uBound;
	unsigned char HUGEP* FAR pData;
	SAFEARRAY *psa;
	HRESULT hr;
	unsigned n;
	DSK_FORMAT *fmt;

	if (V_VT(buf) != (VT_ARRAY | VT_UI1)) 
	{
		return Error("Passed parameter must be an array of unsigned characters", IID_IDisk, E_INVALIDARG);
	}
	psa = V_ARRAY(buf);
      // Check dimensions of the array.
	if (SafeArrayGetDim(psa) != 1)
	{
		return Error("Passed parameter must be a 1-dimensional array", IID_IDisk, E_INVALIDARG);
	}

	// Get array bounds.
	hr = SafeArrayGetLBound(psa, 1, &lBound);
	if (FAILED(hr))
	{
		return Error("Could not get array bounds", IID_IDisk, hr);
	}
	hr = SafeArrayGetUBound(psa, 1, &uBound);
	if (FAILED(hr))
	{
		return Error("Could not get array bounds", IID_IDisk, hr);
	}
	if (uBound + 1 - lBound < (long)length*4)
	{
		return Error("Passed array is too short", IID_IDisk, E_INVALIDARG);
	}
	// Get a pointer to the elements of the array.
	hr = SafeArrayAccessData(psa, (void HUGEP * FAR *)&pData);
	if (FAILED(hr))
	{
		return Error("Could not access array data", IID_IDisk, E_INVALIDARG);
	}
	*bufout = (DSK_FORMAT *)dsk_malloc(length * sizeof(DSK_FORMAT));
	if (!bufout) return MapError(DSK_ERR_NOMEM);
	fmt = bufout[0];
	for (n = 0; n < length; n++)
	{
		fmt->fmt_cylinder = *pData++;
		fmt->fmt_head     = *pData++;
		fmt->fmt_sector   = *pData++;
		fmt->fmt_secsize  = 128 << (*pData++);
		++fmt;
	}
	SafeArrayUnaccessData(psa);
	return S_OK;
}
Exemple #24
0
//==============================================================================
// 2D array of doubles, second dim unspecified 
int g_CheckVariantArray( int nDim1, int * pnDim2, VARIANT vMtx, double ** ppdMtx ){
  SAFEARRAY * psaMtx;
  int nDims;
  long iDim;
  VARTYPE tSaType;

  psaMtx = vMtx.parray;
  *pnDim2 = 0;

  SafeArrayGetVartype( psaMtx, &tSaType );
  if( tSaType != VT_R8 ){
    CP_printf("\ng_CheckVariantArray(): wrong array type, expecting array of doubles!\n");
    return 1;
  }

  nDims = SafeArrayGetDim( psaMtx );
  if( nDims !=2 ) {
    CP_printf("\ng_CheckVariantArray(): wrong number of dimensions, expecting 2D array!\n" );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 1, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dxN array!\n", nDim1 );
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 1, &iDim );
  if( iDim+1 != nDim1) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dxN array!\n", nDim1 );
    return 1;
  }
  SafeArrayGetLBound( psaMtx, 2, &iDim );
  if( iDim != 0) {
    CP_printf("\ng_CheckVariantArray(): wrong array dimensions, expecting %dxN array!\n", nDim1 );
    return 1;
  }
  SafeArrayGetUBound( psaMtx, 2, &iDim );
  iDim++;   // we return the size, which is upperbound +1
  * pnDim2 = iDim; 
  SafeArrayAccessData(psaMtx, (void **) ppdMtx);  // Get data pointer

  return 0;
}
Exemple #25
0
static HRESULT VBArray_toArray(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    VBArrayInstance *vbarray;
    jsdisp_t *array;
    jsval_t val;
    VARIANT *v;
    int i, size = 1, ubound, lbound;
    HRESULT hres;

    TRACE("\n");

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

    for(i=1; i<=SafeArrayGetDim(vbarray->safearray); i++) {
        SafeArrayGetLBound(vbarray->safearray, i, &lbound);
        SafeArrayGetUBound(vbarray->safearray, i, &ubound);
        size *= ubound-lbound+1;
    }

    hres = SafeArrayAccessData(vbarray->safearray, (void**)&v);
    if(FAILED(hres))
        return hres;

    hres = create_array(ctx, 0, &array);
    if(FAILED(hres)) {
        SafeArrayUnaccessData(vbarray->safearray);
        return hres;
    }

    for(i=0; i<size; i++) {
        hres = variant_to_jsval(v, &val);
        if(SUCCEEDED(hres)) {
            hres = jsdisp_propput_idx(array, i, val);
            jsval_release(val);
        }
        if(FAILED(hres)) {
            SafeArrayUnaccessData(vbarray->safearray);
            jsdisp_release(array);
            return hres;
        }
        v++;
    }

    SafeArrayUnaccessData(vbarray->safearray);

    if(r)
        *r = jsval_obj(array);
    else
        jsdisp_release(array);
    return S_OK;
}
Exemple #26
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);
            }
        }
    }
}
Exemple #27
0
PyObject *PyObject_FromSAFEARRAYRecordInfo(SAFEARRAY *psa)
{
	PyObject *ret = NULL, *ret_tuple = NULL;
	IRecordInfo *info = NULL;
	BYTE *source_data = NULL, *this_dest_data = NULL;
	long lbound, ubound, nelems, i;
	ULONG cb_elem;
	PyRecordBuffer *owner = NULL;
	HRESULT hr = SafeArrayGetRecordInfo(psa, &info);
	if (FAILED(hr)) goto exit;
	hr = SafeArrayAccessData(psa, (void **)&source_data);
	if (FAILED(hr)) goto exit;
	// Allocate a new chunk of memory
	hr = SafeArrayGetUBound(psa, 1, &ubound);
	if (FAILED(hr)) goto exit;
	hr = SafeArrayGetLBound(psa, 1, &lbound);
	if (FAILED(hr)) goto exit;
	nelems = ubound-lbound;
	hr = info->GetSize(&cb_elem);
	if (FAILED(hr)) goto exit;
	owner = new PyRecordBuffer(nelems * cb_elem);
	if (PyErr_Occurred()) goto exit;
	owner->AddRef(); // unref'd at end - for successful failure cleanup
	ret_tuple = PyTuple_New(nelems);
	if (ret_tuple==NULL) goto exit;
	this_dest_data = (BYTE *)owner->data;
	for (i=0;i<nelems;i++) {
		hr = info->RecordInit(this_dest_data);
		if (FAILED(hr)) goto exit;

		hr = info->RecordCopy(source_data, this_dest_data);
		if (FAILED(hr)) goto exit;
		PyTuple_SET_ITEM(ret_tuple, i, new PyRecord(info, this_dest_data, owner));
		this_dest_data += cb_elem;
		source_data += cb_elem;
	}
	ret = ret_tuple;
	Py_INCREF(ret); // for decref on cleanup.
exit:
	if (FAILED(hr)) {
		if (info)
			PyCom_BuildPyException(hr, info, IID_IRecordInfo);
		else
			PyCom_BuildPyException(hr);
		Py_XDECREF(ret);
		ret = NULL;
	}
	if (owner != NULL) owner->Release();
	Py_XDECREF(ret_tuple);
	if (info) info->Release();
	if (source_data!=NULL) SafeArrayUnaccessData(psa);
	return ret;
}
bool wxSafeArrayBase::GetUBound(size_t dim, long& bound) const
{
    wxCHECK_MSG( m_array, false, wxS("Uninitialized safe array") );
    wxCHECK_MSG( dim > 0, false, wxS("Invalid dimension index") );

    HRESULT hr = SafeArrayGetUBound(m_array, dim, &bound);
    if ( FAILED(hr) )
    {
        wxLogApiError(wxS("SafeArrayGetUBound()"), hr);
        return false;
    }
    return true;
}
Exemple #29
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;
}
	void com_array_reader::calc_bound()
	{
		if (FAILED(SafeArrayGetLBound(m_psa, 1, &m_lbound)))
			goto error_get_bound;

		if (FAILED(SafeArrayGetUBound(m_psa, 1, &m_ubound)))
			goto error_get_bound;

		return;

error_get_bound:
		m_ubound = -1;
		m_lbound = 0;
	}