示例#1
0
STDMETHODIMP
ase_com_aseproxy::QueryInterface(REFIID iid, void **ppvObject)
{
    DBG_COM(fprintf(stderr, "wrap: %p QI\n", this));
    if (ppvObject == NULL) {
        return E_POINTER;
    }
    if (IsEqualIID(iid, IID_IUnknown)) {
        IUnknown *pu = this;
        pu->AddRef();
        *ppvObject = pu;
        return S_OK;
    } else if (IsEqualIID(iid, IID_IDispatch)) {
        IDispatch *pd = this;
        pd->AddRef();
        *ppvObject = pd;
        return S_OK;
    } else {
        IID sinkiid = value.get_event_sink_iid_synchronized();
        if (IsEqualIID(iid, sinkiid)) {
            IDispatch *pd = this;
            pd->AddRef();
            *ppvObject = pd;
            return S_OK;
        }
    }
    *ppvObject = 0;
    return E_NOINTERFACE;
}
示例#2
0
JNIEXPORT jobject JNICALL Java_com_jacob_com_DispatchProxy_MarshalFromStream
  (JNIEnv *env, jobject _this)
{
  IStream *ps = extractStream(env, _this);
  if (!ps) 
  {
    ThrowComFail(env, "Could not get IStream from DispatchProxy", -1);
    return NULL;
  }
  IDispatch *pD;
  HRESULT hr = CoGetInterfaceAndReleaseStream(ps, IID_IDispatch, (void **)&pD);
  // zero out the stream pointer on the object
  // since the stream can only be read once
  jclass argClass = env->GetObjectClass(_this);
  jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
  env->SetIntField(_this, ajf, (unsigned int)0);

  if (!SUCCEEDED(hr))
  {
    ThrowComFail(env, "Could not Marshal Dispatch from IStream", hr);
    return NULL;
  }
  jclass autoClass = env->FindClass("com/jacob/com/Dispatch");
  jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(I)V");
  // construct a Dispatch object to return
  // I am copying the pointer to java
  if (pD) pD->AddRef();
  jobject newAuto = env->NewObject(autoClass, autoCons, pD);
  return newAuto;
}
示例#3
0
} METHOD_END

IDispatch *CComDispatchImpl::GetIDispatch(bool bAddRef) {
	IDispatch *disp = GetDispatch();
	if (bAddRef)
		disp->AddRef();
	return disp;
}
void LogVariant(const wxString& prefix, const wxVariant& v)
{
    const wxString type = v.GetType();

    wxString info;
    const wxString& name = v.GetName();
    if (type == wxS("arrstring")) {
        wxArrayString as = v.GetArrayString();
        info.Printf(wxS("%svariant type: \"%s\", element count: %zu, name: \"%s\"."),
            prefix, type, as.size(), name);        
        wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info);
        for (size_t i = 0; i < as.size(); i++) 
        {
            info.Printf(wxS("   string #%zu value: \"%s\""), i, as[i]);
            if ( i == LogVariantMaxItemsInList )
            {
                wxLogTrace(wxTRACE_AutoExcel, wxS("And %zu more strings"), as.size() - i);
                break;
            }
            else            
                wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info);
        }
        return;
    }
    if (type == wxS("list")) {
        info.Printf(wxS("%sVariant type: \"%s\", element count: %zu, name: \"%s\"."),
            prefix, type, v.GetCount(), name);
        wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info);
        for (size_t i = 0; i < v.GetCount(); i++)
        {
            if ( i == LogVariantMaxItemsInList )
            {
                wxLogTrace(wxTRACE_AutoExcel, wxS("And %zu more variants"), v.GetCount() - i);
                break;
            } else            
            {
                const wxVariant& vTmp = v[i];
                info.Printf(wxS("   variant #%zu type: \"%s\", value: \"%s\", name: \"%s\"."),
                    i, vTmp.GetType(), vTmp.MakeString(), vTmp.GetName());        
                wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info);
            }
        }
        return;
    }
    if (type == wxS("void*") && v.GetVoidPtr() != NULL) {
        wxString automationName;
        wxExcelObject object;
        IDispatch* dispatch = (IDispatch*)v.GetVoidPtr();
        dispatch->AddRef();
        object.GetAutomationObject_()->SetDispatchPtr(dispatch);
        info.Printf(wxS("%svariant type: \"IDispatch - %s\", value: \"%s\", name: \"%s\"."),
            prefix, object.GetAutomationObjectName_(false), v.MakeString(), name);    
    } else {
        info.Printf(wxS("%svariant type: \"%s\", value: \"%s\", name: \"%s\"."),
            prefix, type, v.MakeString(), name);        
    }
    wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info);
}
示例#5
0
    GvComEventOutObserverConnection(EventOutObserver *Observer=NULL,IDispatch* UserData=NULL,double *TheTimestampPtr=NULL)
	{	
		observer = Observer;
		userData = UserData;
		timeStampPtr = TheTimestampPtr;

#ifdef DOREF
		if (observer) observer->AddRef();
		if (userData) userData->AddRef();
#endif
	};
示例#6
0
	/**
	 * Accepts a dispatch object and sets the type to VT_DISPATCH.
	 * There is currently no way to pass NULL into this method
	 * to create something like "NOTHING" from VB
	 * */
	JNIEXPORT void JNICALL Java_com_tangram_Variant_putVariantDispatch(JNIEnv *env, jobject _this, jobject _that)
	{
		VARIANT *v = extractVariant(env, _this);
		IDispatch *disp = extractDispatch(env, _that);
		if (v) {
			VariantClear(v); // whatever was there before
			V_VT(v) = VT_DISPATCH;
			V_DISPATCH(v) = disp;
			// I am handing the pointer to COM
			// SF 3435567 support null dispatch pointer
			if (disp)
				disp->AddRef();
		}
		else ThrowComFail(env, "putObject failed", -1);
	}
示例#7
0
	/**
	 * Converts the data to a Dispatch object and then returns it as a Dispatch
	 */
	JNIEXPORT jobject JNICALL Java_com_tangram_Variant_toVariantDispatch(JNIEnv *env, jobject _this)
	{
		VARIANT *v = extractVariant(env, _this);
		if (v) {
			HRESULT hr;
			if (FAILED(hr = VariantChangeType(v, v, 0, VT_DISPATCH))) {
				ThrowComFail(env, "VariantChangeType failed", hr);
				return NULL;
			}
			jclass autoClass = env->FindClass("com/tangram/Dispatch");
			jmethodID autoCons =
				env->GetMethodID(autoClass, "<init>", "(J)V");
			// construct a Dispatch object to return
			IDispatch *disp = V_DISPATCH(v);
			// I am copying the pointer to java
			if (disp) disp->AddRef();
			jobject newAuto = env->NewObject(autoClass, autoCons, disp);
			return newAuto;
		}
		return NULL;
	}
STDMETHODIMP CWaveOutRenderer::NonDelegatingQueryInterface(REFIID riid, void** o)
{
    if (!o)
        return E_POINTER;

    *o = NULL;
    if (IID_IDispatch == riid)
    {
        IDispatch* d = this;
        d->AddRef();
        *o = d;
        return S_OK;
    }

    if (IID_IBasicAudio == riid)
    {
        IBasicAudio* b = this;
        b->AddRef();
        *o = b;
        return S_OK;
    }

    return CBaseRenderer::NonDelegatingQueryInterface (riid, o);
}
示例#9
0
JNIEXPORT jobject JNICALL Java_org_racob_com_DispatchProxy_MarshalFromStream
  (JNIEnv *env, jobject _this, jint pointer)
{
  IStream *ps = (IStream *) pointer;
  if (!ps) {
    ThrowComFail(env, "Could not get IStream from DispatchProxy", -1);
    return NULL;
  }
  
  IDispatch *pD;
  HRESULT hr = CoGetInterfaceAndReleaseStream(ps, IID_IDispatch, (void **)&pD);

  if (!SUCCEEDED(hr)) {
    ThrowComFail(env, "Could not Marshal Dispatch from IStream", hr);
    return NULL;
  }
  jclass autoClass = env->FindClass("org/racob/com/Dispatch");
  jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(I)V");
  // construct a Dispatch object to return
  // I am copying the pointer to java
  if (pD) pD->AddRef();
  jobject newAuto = env->NewObject(autoClass, autoCons, pD);
  return newAuto;
}
示例#10
0
IDispatch* CItemHolder::GetDispatch(IActiveScriptSite* pSite, LPOLESTR pstrName, bool fSameApt)
{
	IDispatchEx* pDispEx = m_pDispEx;
	IDispatch* pDisp = m_pDisp;
	ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X name=%ls sameptr=%d\n"), GetCurrentThreadId(), pstrName, fSameApt);
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
	if (fSameApt)
	{
#endif
		if (pDisp == NULL && pDispEx == NULL)
		{
			ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X\n"), GetCurrentThreadId());
			IUnknown* pUnk = NULL;
			ITypeInfo* pTypeInfo = NULL;
			HRESULT hr = pSite->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &pUnk, &pTypeInfo);
			if (hr == S_OK)
			{
				if (pTypeInfo) pTypeInfo->Release();
				if (pUnk->QueryInterface(IID_IDispatchEx, (void**)&pDispEx) == S_OK)
				{
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
					HRESULT hr = m_pGIPDispEx.Globalize(pDispEx);
					ATLTRACE(_T("Globalize Item = %08X\n"), hr);
#endif
					m_pDispEx = pDispEx;
				}
				else
				{
					pDispEx = NULL;
					if (pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp) == S_OK)
					{
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
						HRESULT hr = m_pGIPDisp.Globalize(pDisp);
						ATLTRACE(_T("Globalize Item = %08X\n"), hr);
#endif
						m_pDisp = pDisp;
					}
				}
				pUnk->Release();
			}
		}

		if (pDispEx)
		{
			pDispEx->AddRef();
		}
		else if (pDisp)
		{
			pDisp->AddRef();
		}
#ifdef __IRubyWrapper_INTERFACE_DEFINED__
	}
	else
	{
		if (m_pGIPDisp.IsOK() == false && m_pGIPDispEx.IsOK() == false)
		{
			ATLTRACE(_("CItemHolder::GetDispatch in Thread:%08X\n"), GetCurrentThreadId());
			IUnknown* pUnk = NULL;
			ITypeInfo* pTypeInfo = NULL;
			HRESULT hr = pSite->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &pUnk, &pTypeInfo);
			if (hr == S_OK)
			{
				if (pTypeInfo) pTypeInfo->Release();
				if (pUnk->QueryInterface(IID_IDispatchEx, (void**)&pDispEx) != S_OK)
				{
					pDispEx = NULL;
					if (pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp) != S_OK)
					{
						pDisp = NULL;
					}
				}
				pUnk->Release();
			}
		}
		if (m_pGIPDispEx.IsOK())
		{
			IDispatchEx* p;
			HRESULT hr = m_pGIPDispEx.Localize(&p);
			ATLTRACE(_("Localize DispEx = %08X\n"), hr);
			return p;
		}
		if (m_pGIPDisp.IsOK())
		{
			IDispatch* p;
			HRESULT hr = m_pGIPDisp.Localize(&p);
			ATLTRACE(_("Localize Disp = %08X\n"), hr);
			return p;
		}
	}
#endif
	return (pDispEx) ? pDispEx : pDisp;
}
示例#11
0
HRESULT
R_convertRObjectToDCOM(SEXP obj, VARIANT *var)
{
  HRESULT status;
  int type = R_typeof(obj);

  if(!var)
    return(S_FALSE);

#ifdef RDCOM_VERBOSE
  errorLog("Type of argument %d\n", type);
#endif

 if(type == EXTPTRSXP && EXTPTR_TAG(obj) == Rf_install("R_VARIANT")) {
   VARIANT *tmp;
   tmp = (VARIANT *) R_ExternalPtrAddr(obj);
   if(tmp) {
     //XXX
     VariantCopy(var, tmp);
     return(S_OK);
   }
 }

 if(ISCOMIDispatch(obj)) {
   IDispatch *ptr;
   ptr = (IDispatch *) derefRIDispatch(obj);
   V_VT(var) = VT_DISPATCH;
   V_DISPATCH(var) = ptr;
   //XX
   ptr->AddRef();
   return(S_OK);
 }

 if(ISSInstanceOf(obj, "COMDate")) {
    double val;
    val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0];
    V_VT(var) = VT_DATE;
    V_DATE(var) = val;
    return(S_OK);
 } else if(ISSInstanceOf(obj, "COMCurrency")) {
    double val;
    val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0];
    V_VT(var) = VT_R8;
    V_R8(var) = val;
    VariantChangeType(var, var, 0, VT_CY);
    return(S_OK);
 } else if(ISSInstanceOf(obj, "COMDecimal")) {
    double val;
    val = NUMERIC_DATA(GET_SLOT(obj, Rf_install(".Data")))[0];
    V_VT(var) = VT_R8;
    V_R8(var) = val;
    VariantChangeType(var, var, 0, VT_DECIMAL);
    return(S_OK);
 }


 /* We have a complex object and we are not going to try to convert it directly
    but instead create an COM server object to represent it to the outside world. */
  if((type == VECSXP && Rf_length(GET_NAMES(obj))) || Rf_length(GET_CLASS(obj)) > 0  || isMatrix(obj)) {
    status = createGenericCOMObject(obj, var);
    if(status == S_OK)
      return(S_OK);
  }

  if(Rf_length(obj) == 0) {
   V_VT(var) = VT_VOID;
   return(S_OK);
  }

  if(type == VECSXP || Rf_length(obj) > 1) {
      createRDCOMArray(obj, var);
      return(S_OK);
  }

  switch(type) {
    case STRSXP:
      V_VT(var) = VT_BSTR;
      V_BSTR(var) = AsBstr(getRString(obj, 0));
      break;

    case INTSXP:
      V_VT(var) = VT_I4;
      V_I4(var) = R_integerScalarValue(obj, 0);
      break;

    case REALSXP:
	V_VT(var) = VT_R8;
	V_R8(var) = R_realScalarValue(obj, 0);
      break;

    case LGLSXP:
      V_VT(var) = VT_BOOL;
      V_BOOL(var) = R_logicalScalarValue(obj, 0) ? VARIANT_TRUE : VARIANT_FALSE;
      break;

    case VECSXP:
      break;
  }
  
  return(S_OK);
}
示例#12
0
SEXP
R_convertDCOMObjectToR(VARIANT *var)
{
  SEXP ans = R_NilValue;

  VARTYPE type = V_VT(var);

#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
  errorLog("Converting VARIANT to R %d\n", V_VT(var));
#endif


  if(V_ISARRAY(var)) {
#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
  errorLog("Finishing convertDCOMObjectToR - convert array\n");
#endif
    return(convertArrayToR(var));
  } else if(V_VT(var) == VT_DISPATCH || (V_ISBYREF(var) && ((V_VT(var) & (~ VT_BYREF)) == VT_DISPATCH)) ) {
    IDispatch *ptr;
    if(V_ISBYREF(var)) {

#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
      errorLog("BYREF and DISPATCH in convertDCOMObjectToR\n");
#endif

      IDispatch **tmp = V_DISPATCHREF(var);
      if(!tmp)
	return(ans);
      ptr = *tmp;
    } else
      ptr = V_DISPATCH(var);
       //xxx
    if(ptr) 
      ptr->AddRef();
    ans = R_createRCOMUnknownObject((void*) ptr, "COMIDispatch");
#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
    errorLog("Finished convertDCOMObjectToR  COMIDispatch\n");
#endif
    return(ans);
  }



  if(V_ISBYREF(var)) {
    VARTYPE rtype = type & (~ VT_BYREF);

#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
    errorLog("ISBYREF() in convertDCOMObjectToR: ref type %d\n", rtype);
#endif

    if(rtype == VT_BSTR) {
        BSTR *tmp;
        const char *ptr = "";
#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
	errorLog("BYREF and BSTR convertDCOMObjectToR  (scalar string)\n");
#endif
        tmp = V_BSTRREF(var);
        if(tmp)
  	  ptr = FromBstr(*tmp);
        ans = R_scalarString(ptr);
	return(ans);
    } else if(rtype == VT_BOOL || rtype == VT_I4 || rtype == VT_R8){
      return(createVariantRef(var, rtype));
    } else {
        fprintf(stderr, "Unhandled by-reference conversion type %d\n", V_VT(var));fflush(stderr);
	return(R_NilValue);        
    }
  }

  switch(type) {

    case VT_BOOL:
      ans = R_scalarLogical( (Rboolean) (V_BOOL(var) ? TRUE : FALSE));
      break;

    case VT_UI1:
    case VT_UI2:
    case VT_UI4:
    case VT_UINT:
      VariantChangeType(var, var, 0, VT_I4);
      ans = R_scalarReal((double) V_I4(var));
      break;

    case VT_I1:
    case VT_I2:
    case VT_I4:
    case VT_INT:
      VariantChangeType(var, var, 0, VT_I4);
      ans = R_scalarInteger(V_I4(var));
      break;

    case VT_R4:
    case VT_R8:
    case VT_I8:
      VariantChangeType(var, var, 0, VT_R8);
      ans = R_scalarReal(V_R8(var));
      break;

    case VT_CY:
    case VT_DATE:
    case VT_HRESULT:
    case VT_DECIMAL:
      VariantChangeType(var, var, 0, VT_R8);
      ans = numberFromVariant(var, type);
      break;

    case VT_BSTR:
      {
	char *ptr = FromBstr(V_BSTR(var));
        ans = R_scalarString(ptr);
      }
      break;

    case VT_UNKNOWN:
      {
       IUnknown *ptr = V_UNKNOWN(var);
       //xxx
       if(ptr)
         ptr->AddRef();
       ans = R_createRCOMUnknownObject((void**) ptr, "COMUnknown");
      }
       break;
  case VT_EMPTY:
  case VT_NULL:
  case VT_VOID:
    return(R_NilValue);
    break;


/*XXX Need to fill these in */
  case VT_RECORD:
  case VT_FILETIME:
  case VT_BLOB:
  case VT_STREAM:
  case VT_STORAGE:
  case VT_STREAMED_OBJECT:
    /*  case LPSTR: */
  case VT_LPWSTR:
  case VT_PTR:
  case VT_ERROR:
  case VT_VARIANT:
  case VT_CARRAY:
  case VT_USERDEFINED:
  default:
    fprintf(stderr, "Unhandled conversion type %d\n", V_VT(var));fflush(stderr);
    //XXX this consumes the variant. So the variant clearance in Invoke() does it again!
    ans = createRVariantObject(var, V_VT(var));
  }

#if defined(RDCOM_VERBOSE) && RDCOM_VERBOSE
  errorLog("Finished convertDCOMObjectToR\n");
#endif

  return(ans);
}