Esempio n. 1
0
STDMETHODIMP CPyCOMTest::GetSafeArrays(SAFEARRAY** attrs,
                                      SAFEARRAY**attrs2,
                                      SAFEARRAY** ints)
{
	HRESULT hr;
	*attrs = *attrs2 = *ints = NULL;
	if (S_OK != (hr=MakeFillIntArray(attrs, 5, VT_I4)))
		return hr;
	if (S_OK != (hr=MakeFillIntArray(attrs2, 10, VT_I4))) {
		SafeArrayDestroy(*attrs);
		return hr;
	}
	if (S_OK != (hr=MakeFillIntArray(ints, 20, VT_I4))) {
		SafeArrayDestroy(*attrs);
		SafeArrayDestroy(*attrs2);
		return hr;
	}
	return S_OK;
}
Esempio n. 2
0
SEXP rCreateObject(SEXP p) {

	// 1 - Get data from SEXP
	p = CDR(p); // Skip the first parameter: because function name
	char* strTypeName = readStringFromSexp(p); p = CDR(p);
	SAFEARRAY* parameters = readParametersFromSexp(p);

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

	// 2.2 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"CreateInstance", args, &result, &errorMsg);
	
	if(FAILED(hr)) {
		Rprintf(errorMsg);
		error("Exception during netNew !");
		free(errorMsg);
		return R_NilValue;
	}

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

	return convertToSEXP(result);
}
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////////////
// Destroy : Destroy the safeArray object (can't destroy it object is locked)
bool CSafeArrayHelper::Destroy()
{
	if (NULL != m_pSA)
	{
		// Maybe the object is locked!
		if (SUCCEEDED(SafeArrayDestroy( m_pSA )))
			m_pSA = NULL;
	}
	return (m_pSA == NULL);
}
Esempio n. 4
0
int wdFreeScriptArgs(ScriptArgs* scriptArgs)
{
	if (!scriptArgs || !scriptArgs->args) 
		return ENOSUCHCOLLECTION;

	SafeArrayDestroy(scriptArgs->args);
	delete scriptArgs;

	return SUCCESS;
}
Esempio n. 5
0
static void doc_navigate_task_destr(task_header_t *t)
{
    task_doc_navigate_t *task = (task_doc_navigate_t*)t;

    SysFreeString(task->url);
    SysFreeString(task->headers);
    if(task->post_data)
        SafeArrayDestroy(task->post_data);
    heap_free(task);
}
Esempio n. 6
0
void
RDCOM_SafeArray_finalizer(SEXP s)
{
  SAFEARRAY *arr;
  arr = (SAFEARRAY*) R_ExternalPtrAddr(s);
  if(arr) {
    SafeArrayDestroy(arr);
    R_ClearExternalPtr(s);
  }
}
Esempio n. 7
0
static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
{
    SysFreeString(task->url);
    SysFreeString(task->headers);
    if(task->post_data)
        SafeArrayDestroy(task->post_data);
    if(free_task)
        heap_free(task);
    return E_OUTOFMEMORY;
}
Esempio n. 8
0
static HRESULT WINAPI IRecordInfoImpl_RecordClear(IRecordInfo *iface, PVOID pvExisting)
{
    IRecordInfoImpl *This = impl_from_IRecordInfo(iface);
    int i;
    PVOID var;

    TRACE("(%p)->(%p)\n", This, pvExisting);

    if(!pvExisting)
        return E_INVALIDARG;

    for(i=0; i<This->n_vars; i++) {
        if(This->fields[i].varkind != VAR_PERINSTANCE) {
            ERR("varkind != VAR_PERINSTANCE\n");
            continue;
        }
        var = ((PBYTE)pvExisting)+This->fields[i].offset;
        switch(This->fields[i].vt) {
            case VT_BSTR:
               SysFreeString(*(BSTR*)var);
                *(BSTR*)var = NULL;
                break;
            case VT_I2:
            case VT_I4:
            case VT_R4:
            case VT_R8:
            case VT_CY:
            case VT_DATE:
            case VT_ERROR:
            case VT_BOOL:
            case VT_DECIMAL:
            case VT_I1:
            case VT_UI1:
            case VT_UI2:
            case VT_UI4:
            case VT_I8:
            case VT_UI8:
            case VT_INT:
            case VT_UINT:
                break;
            case VT_INT_PTR:
            case VT_UINT_PTR:
                *(void**)var = NULL;
                break;
            case VT_SAFEARRAY:
                SafeArrayDestroy(var);
                break;
            default:
                FIXME("Not supported vt = %d\n", This->fields[i].vt);
                break;
        }
    }
    
    return S_OK;
}
Esempio n. 9
0
HRESULT CMmQvRequestColl::RequestLastQuotes(IBatchPriceProviderPtr spProvider)
{
	typedef CComRecPtr<QuoteUpdateParams, &LIBID_PRICEPROVIDERSLib >  _QuoteUpdateParams;
	HRESULT hr = S_OK;
	try
	{
		long lSize = static_cast<long>(m_coll.size());
		if(lSize)
		{
			_QuoteUpdateParams request;
			request.Init();
			SAFEARRAYBOUND sab = { lSize, 0};

			LPSAFEARRAY psa = ::SafeArrayCreateEx(VT_RECORD, 1, &sab, (PVOID)request.GetRecordInfo());
			if(psa)
			{
				QuoteUpdateParams* pvData = NULL;
				if(SUCCEEDED(hr = ::SafeArrayAccessData(psa, (void**)&pvData)))
				{
					memset(pvData, 0,  m_coll.size() * sizeof(QuoteUpdateParams));
					int i = 0;
					for(CollType::iterator itr = m_coll.begin(); itr!=m_coll.end(); ++itr, ++i)
					{

						IMmQvRequestAtomPtr spRequestAtom = itr->second;
						spRequestAtom->get_QuoteUpdateParam(request);
						request.CopyTo(&pvData[i]);

						if(request->Symbol)
						{
							SysFreeString(request->Symbol);
							request->Symbol = NULL;
						}
						if(request->Exchange)
						{
							SysFreeString(request->Exchange);
							request->Exchange = NULL;
						}
					}	
					::SafeArrayUnaccessData(psa);
					spProvider->RequestMultipleQuotes(&psa);
				}
				SafeArrayDestroy(psa);
			}
		}
	}catch(_com_error& err)
	{
		return Error((PTCHAR)EgLib::CComErrorWrapper::ErrorDescription(err), IID_IMmQvRequestColl, err.Error());
	}
	/*catch (...)
	{
	}*/
	return S_OK;
}
Esempio n. 10
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);
			}
		}

	}
}
Esempio n. 11
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;
	}
Esempio n. 12
0
DLL void AtmoCreateTransferBuffers(int FourCC,int bytePerPixel,int width,int height) {
    if(pixelDataArr != NULL)
       SafeArrayDestroy(pixelDataArr); 
    if(bitmapInfoArr != NULL)
       SafeArrayDestroy(bitmapInfoArr); 

    int size = width * height * bytePerPixel;
    pixelDataArr  = SafeArrayCreateVector(VT_UI1,0,size);

    bitmapInfoArr = SafeArrayCreateVector(VT_UI1,0,sizeof(BITMAPINFOHEADER));

    BITMAPINFOHEADER *header;
    SafeArrayAccessData(bitmapInfoArr,(void **)&header);
    header->biSize = sizeof(BITMAPINFOHEADER);
    header->biWidth = width;
    header->biHeight = height;
    header->biBitCount = bytePerPixel*8;
    header->biCompression = FourCC;
    SafeArrayUnaccessData(bitmapInfoArr);
}
Esempio n. 13
0
CAtmoLightFilter::~CAtmoLightFilter( )
{
    OleInitialize(NULL); 

    log("destroying atmo filtern\n");

    if(m_AtmoInitialized)
    {
        IAtmoRemoteControl *remoteControl = getAtmoRemoteControl();
        if(remoteControl)
        {
        if( m_CurrentAtmoEffect != cemLivePicture)
        {
            remoteControl->setEffect( m_CurrentAtmoEffect, &m_CurrentAtmoEffect );
        } else {
            IAtmoLiveViewControl *liveControl = getAtmoLiveViewControl();
            if(liveControl)
                {
                    liveControl->setLiveViewSource( lvsGDI );
                    liveControl->Release();
                }
        }
        remoteControl->Release(); 
        }
        if(m_pixel_buffer)
           SafeArrayDestroy( m_pixel_buffer );

        if(m_bitmap_header)
           SafeArrayDestroy( m_bitmap_header );
    }

    OleUninitialize();
    log("atmo filter destroyed\n\n\n");

    if(m_log_file)
       fclose( m_log_file );
    
    free( m_pszAtmoWin );
    free( m_pszLogFileName );
    free( m_pszImageLogPath );
}
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 );
}
Esempio n. 15
0
// 写HTML到document
void CLog::WriteDocument(const CString& content)
{
	SAFEARRAY *arr = SafeArrayCreateVector(VT_VARIANT, 0, 1);
	VARIANT *str = NULL;
	if (FAILED(SafeArrayAccessData(arr, (LPVOID*)&str)))
		return;
	str->vt = VT_BSTR;
	str->bstrVal = content.AllocSysString();
	SafeArrayUnaccessData(arr);
	m_logDocument->write(arr);
	SafeArrayDestroy(arr);
}
Esempio n. 16
0
HRESULT CMainFrameDropTarget::PasteHTML(PASTEURLDATA* pPaste)
{
    HRESULT hrPasteResult = S_FALSE; // default: nothing was pasted
    if (pPaste->m_bstrURLs[0] != L'\0')
    {
        HRESULT hr;
        CComPtr<IHTMLDocument2> doc;
        if (SUCCEEDED(hr = doc.CoCreateInstance(CLSID_HTMLDocument, NULL)))
        {
            SAFEARRAY* psfHtmlLines = SafeArrayCreateVector(VT_VARIANT, 0, 1);
            if (psfHtmlLines != NULL)
            {
                VARIANT* pva;
                if (SafeArrayAccessData(psfHtmlLines, (void**)&pva) == S_OK)
                {
                    pva->vt = VT_BSTR;
                    pva->bstrVal = pPaste->m_bstrURLs;
                    VERIFY( SafeArrayUnaccessData(psfHtmlLines) == S_OK );

                    // Build the HTML document
                    //
                    // NOTE: 'bstrHTML' may contain a complete HTML document (see CF_HTML) or
                    // just a fragment (without <HTML>, <BODY>, ... tags).
                    //
                    // WOW! We even can pump partially (but well defined) HTML stuff into the
                    // document (e.g. contents without <HTML>, <BODY>...) *and* we are capable
                    // of accessing the HTML object model (can use 'get_links'...)
                    if ((hr = doc->write(psfHtmlLines)) == S_OK)
                        hrPasteResult = PasteHTMLDocument(doc, pPaste);
                    else
                        hrPasteResult = E_FAIL;
                }
                else
                    hrPasteResult = E_OUTOFMEMORY;

                // Destroy the array *and* all of the data (BSTRs!)
                if (SafeArrayAccessData(psfHtmlLines, (void**)&pva) == S_OK)
                {
                    // 'Remove' the BSTR which was specified before, to *NOT* have it deleted by 'SafeArrayDestroy'
                    pva->vt = VT_NULL;
                    pva->bstrVal = NULL;
                    VERIFY( SafeArrayUnaccessData(psfHtmlLines) == S_OK );
                }
                VERIFY( SafeArrayDestroy(psfHtmlLines) == S_OK );
            }
            else
                hrPasteResult = E_OUTOFMEMORY;
        }
        else
            hrPasteResult = E_FAIL;
    }
    return hrPasteResult;
}
Esempio n. 17
0
STDMETHODIMP SoundDA::SetChannelProperty(long User, NESTABLEPROP *pChan, VARIANT *newValue)
{
    int chan=pChan->Index;   

    if (chan>2) return E_EXCEEDS_MAX_CHANNELS;
   
    long numChans;
    
    HRESULT hRes = _EngineChannelList->GetNumberOfChannels(&numChans);
    if (FAILED(hRes)) return hRes;
        

        if (User==HwChan) 
        {
            variant_t val = (variant_t*)newValue;
            if (V_VT(newValue)==VT_R8 && (double)val!=chan)
                return E_INVALID_CHANNEL;
        }
        // Winsound supports only an input range of [-1 1]
        else if (User==OUTPUTRANGE)
        {
            if (V_ISARRAY (newValue) || V_ISVECTOR (newValue))
            {                            
                SAFEARRAY *ps = newValue->parray;
                if (ps==NULL)
                    return E_OUTOFMEMORY;
                                
                double *pr;
                
                HRESULT hr = SafeArrayAccessData (ps, (void **) &pr);
                if (FAILED (hr)) 
                {
                    SafeArrayDestroy (ps);
                    return hr;
                }
                
                if (pr[0]!=-1 || pr[1]!=1)
                {
                    SafeArrayUnaccessData (ps);
                    return E_INV_OUTPUT_RANGE;
                }
                
                SafeArrayUnaccessData (ps);
            }

        }


    if (numChans!=_nChannels)
        _nChannels = numChans;       
    
    return S_OK;
}
	long  SmtTinFclsAdoLayer::AppendTinNodes(const SmtTin *pTin)
	{
		m_SmtRecordset.PutCollect("geom_pointnum",_variant_t(pTin->GetPointCount()));

		int nPoints = pTin->GetPointCount();
	
		if (nPoints < 1)
			return SMT_ERR_DB_OPER;

		RawPoint *pRawPoints = new RawPoint[nPoints];

		for (int i = 0; i < pTin->GetPointCount();i++)
		{
			SmtPoint oPoint = pTin->GetPoint(i);
			pRawPoints[i].x = oPoint.GetX();
			pRawPoints[i].y = oPoint.GetY();
		}

		char   *pBuf = (char*)pRawPoints;
		int    nLen  = sizeof(RawPoint)*nPoints;

		VARIANT varBLOB;
		SAFEARRAY *pSa = NULL;
		SAFEARRAYBOUND rgSaBound[1];
		if(pBuf)
		{ 
			rgSaBound[0].lLbound = 0;
			rgSaBound[0].cElements = nLen;

			char *pSABuf = NULL;
			pSa = SafeArrayCreate(VT_UI1, 1, rgSaBound);  
			if(SafeArrayAccessData(pSa,(void **)&pSABuf) == NOERROR)
			{
				memcpy(pSABuf,pBuf,nLen);
			}
			SafeArrayUnaccessData(pSa);

		/*	pSa = SafeArrayCreate(VT_UI1, 1, rgSaBound);  
			for (long i = 0; i < (long)nLen; i++)
				SafeArrayPutElement (pSa, &i, pBuf++); */

			varBLOB.vt = VT_ARRAY | VT_UI1;  
			varBLOB.parray = pSa;  
			m_SmtRecordset.GetField("geom_points")->AppendChunk(varBLOB);
		} 

		SafeArrayDestroy(pSa);

		SMT_SAFE_DELETE_A(pRawPoints);

		return SMT_ERR_NONE;
	}
Esempio n. 19
0
LRESULT CSkypeAPIEventWindow::OnFireBinaryTransferEnd(UINT nMsg, WPARAM wLPWSTRTransferID, LPARAM lPtrSafeArray, BOOL& bHandled)
{
	try {
		SAFEARRAY * psa = (SAFEARRAY *) lPtrSafeArray;
		m_ptrAccess->BinaryTransferEnd(SysAllocString((LPWSTR) wLPWSTRTransferID), & psa);
		free((LPWSTR) wLPWSTRTransferID);
		SafeArrayDestroy(psa);
	} catch(...) {
	}

	bHandled = true;
	return 0;
}
Esempio n. 20
0
void wxSafeArrayBase::Destroy()
{
    if ( m_array )
    {
        Unlock();
        HRESULT hr = SafeArrayDestroy(m_array);
        if ( FAILED(hr) )
        {
            wxLogApiError(wxS("SafeArrayDestroy()"), hr);
        }
        m_array = NULL;
    }
}
Esempio n. 21
0
/* val2 contains the variable argument list. If no such arguments are supplied
	then the safearray is invalid. SafeArrayCopy then returns E_INVALIDARG
*/
STDMETHODIMP CBasic::varargfunc1(/*[in]*/ long val1,/*[in]*/ LPSAFEARRAY val2)
{
	m_long = val1;

	HRESULT hr = S_OK;
	if (FAILED(hr = SafeArrayDestroy(m_safearray)))
		return hr;
	if (FAILED(hr = SafeArrayCopy(val2, & m_safearray)))
	{
		if (hr != E_INVALIDARG)
			return hr;	
	}
	return S_OK;
}
Esempio n. 22
0
STDMETHODIMP C_ECBLoader::get_Styles(STRING_ARRAY *pVal)
{
    if (!pVal) {
        return E_POINTER;
    }

    try {

        if (*pVal) {
            SafeArrayDestroy(*pVal);
        }

        int len = styles.GetLength();

        SAFEARRAYBOUND rgsabound[] = { len, 0 };
        SAFEARRAY* psa = SafeArrayCreate(VT_BSTR, 1, rgsabound);

        BSTR *bs;

        SafeArrayAccessData(psa, (LPVOID*)&bs);

        for (int n = 0; n < len; n++) {
            *bs++ = styles[n]->toBSTR();
        }

        SafeArrayUnaccessData(psa);

        SafeArrayCopy(psa, pVal);
        SafeArrayDestroy(psa);
    }
    catch (C_STLNonStackException const &exception) {
        exception.Log(_T("Exception in C_ECBLoader::get_Styles"));
    }


    return S_OK;
}
Esempio n. 23
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;
	}
	long  SmtTinFclsAdoLayer::AppendTinTriangles(const SmtTin *pTin)
	{
		m_SmtRecordset.PutCollect("geom_trianglenum",_variant_t(pTin->GetTriangleCount()));

		int nTrianges = pTin->GetTriangleCount();

		if (nTrianges < 1)
			return SMT_ERR_DB_OPER;

		SmtTriangle *pTriBuf = new SmtTriangle[nTrianges];

		for (int i = 0; i < pTin->GetTriangleCount();i++)
			pTriBuf[i] = pTin->GetTriangle(i);
		
		char   *pBuf = (char*)pTriBuf;
		int    nLen  = sizeof(SmtTriangle)*nTrianges;

		VARIANT varBLOB;
		SAFEARRAY *pSa = NULL;
		SAFEARRAYBOUND rgSaBound[1];
		if(pBuf)
		{ 
			rgSaBound[0].lLbound = 0;
			rgSaBound[0].cElements = nLen;

			char *pSABuf = NULL;
			pSa = SafeArrayCreate(VT_UI1, 1, rgSaBound);  
			if(SafeArrayAccessData(pSa,(void **)&pSABuf) == NOERROR)
			{
				memcpy(pSABuf,pBuf,nLen);
			}
			SafeArrayUnaccessData(pSa);

			/*pSa = SafeArrayCreate(VT_UI1, 1, rgSaBound);  
			for (long i = 0; i < (long)nLen; i++)
				SafeArrayPutElement (pSa, &i, pBuf++);*/ 

			varBLOB.vt = VT_ARRAY | VT_UI1;  
			varBLOB.parray = pSa;  
			m_SmtRecordset.GetField("geom_triangles")->AppendChunk(varBLOB);
		} 

		SafeArrayDestroy(pSa);

		SMT_SAFE_DELETE_A(pTriBuf);

		return SMT_ERR_NONE;
	}
Esempio n. 25
0
template <> void
BlobEncoder::encode(const std::string &item)
{
    SAFEARRAYBOUND bound[1] = {0, 0};
    bound[0].cElements = item.size();
    blob = SafeArrayCreate(VT_UI1, 1, bound);
    if (S_OK != SafeArrayLock(blob)) {
        SafeArrayDestroy(blob);
        blob = 0;
        throw qpid::Exception("Error locking blob area for string");
    }
    memcpy_s(blob->pvData, item.size(), item.data(), item.size());
    this->vt = VT_ARRAY | VT_UI1;
    this->parray = blob;
    SafeArrayUnlock(blob);
}
Esempio n. 26
0
/*
 *  Constructs an 1-dimensional array containing variant strings.  The strings
 *  are copied from an incoming array of C-Strings.
 */
BOOL CXLAutomation::AddArgumentCStringArray(LPOLESTR lpszArgName, WORD wFlags, LPOLESTR *paszStrings, int iCount)
{
	SAFEARRAY *psa;
	SAFEARRAYBOUND saBound;
	VARIANTARG *pvargBase;
	VARIANTARG *pvarg;
	int i, j;
	
	saBound.lLbound = 0;
	saBound.cElements = iCount;
	
	psa = SafeArrayCreate(VT_VARIANT, 1, &saBound);
	if (psa == NULL)
		return FALSE;
	
	SafeArrayAccessData(psa, (void**) &pvargBase);
	
	pvarg = pvargBase;
	for (i = 0; i < iCount; i++) 
	{
		// copy each string in the list of strings
		ClearVariant(pvarg);
		pvarg->vt = VT_BSTR;
		if ((pvarg->bstrVal = SysAllocString(*paszStrings++)) == NULL) 
		{
			// memory failure:  back out and free strings alloc'ed up to
			// now, and then the array itself.
			pvarg = pvargBase;
			for (j = 0; j < i; j++) 
			{
				SysFreeString(pvarg->bstrVal);
				pvarg++;
			}
			SafeArrayDestroy(psa);
			return FALSE;
		}
		pvarg++;
	}
	
	SafeArrayUnaccessData(psa);

	// With all memory allocated, setup this argument
	AddArgumentCommon(lpszArgName, wFlags, VT_VARIANT | VT_ARRAY);
	m_aVargs[m_iArgCount++].parray = psa;
	return TRUE;

}
//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;
}
Esempio n. 28
0
//存Buffer
bool CRsDupRgn::SaveBufferField(CBaseDBEntity *pGoods, const char* szFiledName, _RecordsetPtr &rs)
{
	if(pGoods == NULL)	return false;
	if(szFiledName == NULL) return false;

	VARIANT varBLOB;
	SAFEARRAY* psa;

	CEntityProperty* ep = pGoods->GetDataEntityManager().GetEntityProperty(string(szFiledName));
	if(NULL == ep) return false;

	BYTE* buffer = NULL;
	long dataSize = ep->GetBufSize(0);
	if(dataSize)
	{
		buffer = new BYTE[dataSize];
		ep->GetBufAttr(0, (void*)buffer, dataSize);
		
		long lSize=(long)dataSize;
		SAFEARRAYBOUND rgsabound[1];
		rgsabound[0].lLbound=0;
		rgsabound[0].cElements=lSize;
		psa=SafeArrayCreate(VT_UI1,1,rgsabound);

		for(long i=0;i<lSize;i++)
		{
			SafeArrayPutElement(psa,&i,&buffer[i]);
		}
		varBLOB.vt=VT_ARRAY|VT_UI1;
		varBLOB.parray=psa;

		try
		{
			rs->GetFields()->GetItem(szFiledName)->AppendChunk(varBLOB);
		}
		catch(_com_error e)
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN, STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
			SAFE_DELETE_ARRAY(buffer);
			return false;
		}
		SafeArrayDestroy(psa);
	}
	SAFE_DELETE_ARRAY(buffer);
	return true;
}
Esempio n. 29
0
static void clean_props(vbdisp_t *This)
{
    unsigned i;

    if(!This->desc)
        return;

    for(i=0; i < This->desc->array_cnt; i++) {
        if(This->arrays[i]) {
            SafeArrayDestroy(This->arrays[i]);
            This->arrays[i] = NULL;
        }
    }

    for(i=0; i < This->desc->prop_cnt; i++)
        VariantClear(This->props+i);
}
Esempio n. 30
0
HRESULT CetfarduinoAin::SetDaqHwInfo() {
	// ----------------------------------
	// Set allowed InputRanges
	// ----------------------------------
	// The SAFEARRAYBOUND is used to create a multi dimensional array    
	SAFEARRAYBOUND rgsabound[2];  //the number of dimensions
    rgsabound[0].lLbound = 0;
	rgsabound[0].cElements = _validInputRanges.size(); // bipolar and unipolar - size of dimension 1
    rgsabound[1].lLbound = 0;
    rgsabound[1].cElements = 2;     // upper and lower range values - size of dimension 2
	
    SAFEARRAY* ps = SafeArrayCreate(VT_R8, 2, rgsabound); //use the SafeArrayBound to create the array
    if (ps == NULL) 
		throw "Failure to create SafeArray.";
	
	CComVariant vinrange;
    vinrange.parray = ps;
    vinrange.vt = VT_ARRAY | VT_R8;
    double *inRange, *min, *max;
    HRESULT hr = SafeArrayAccessData(ps, (void**)&inRange);
    if (FAILED(hr)) 
    {
        SafeArrayDestroy(ps);
        throw "Failure to access SafeArray data.";
    }       
	min = inRange;
	max = inRange + _validInputRanges.size();
	
	// Iterate through the validRanges, and transfer the Input Ranges.
	for (RangeList::iterator it = _validInputRanges.begin(); it != _validInputRanges.end(); ++it) {
		*min++ = it->minVal;
		*max++ = it->maxVal;
	}
    SafeArrayUnaccessData(ps);
    RETURN_HRESULT(_DaqHwInfo->put_MemberValue(CComBSTR(L"inputranges"), vinrange));

	// Polarity
	// Za sad je predvidjeno samo Unipolarni polaritet...
	RETURN_HRESULT(_DaqHwInfo->put_MemberValue(CComBSTR(L"polarity"), CComVariant(L"Unipolar")));

	// Description
	char driverDescrip[] = "Etf Arduino Driver: Analog Input";
	RETURN_HRESULT(_DaqHwInfo->put_MemberValue(CComBSTR(L"vendordriverdescription"), CComVariant(driverDescrip)));

	return S_OK;
}