Passing COM object pointers through VARIANT from ActiveX component 
Author Message
 Passing COM object pointers through VARIANT from ActiveX component

Hello!

I have problems creating and retrieving a pointer on a COM object.
Here's the scenario:

I have created an ActiveX component. The component has a method which
creates
a COM object and returns an IDispatch pointer to the object:

STDMETHODIMP CMyClass::Evaluate(BSTR Expression, VARIANT *Result, INT
*RetVal)
{
 ...
 // this is the case when the method creates FirstObject
 Result->vt = VT_DISPATCH | VT_BYREF;
 Result->ppdispVal = NULL;

 IDispatch *pRes = NULL;
 if(CoCreateInstance(CLSID_FirstObject,
     NULL,
     CLSCTX_ALL,
     IID_IFirstObject,          reinterpret_cast<void**>(&pRes)) != S_OK)
   return S_FALSE;
 Result->ppdispVal = &pRes;
 (static_cast<CFirstObject*>(*(Result->ppdispVal)) )->m_data = res;
 ...

Quote:
}

In my MFC app, I try to call that method and retrieve the pointer. I use
IDispatch pointer as
a parameter passed to the method because the method can create to kinds of
objects.
But the main problem in this story is that the method returns VARIANT that
contains a pointer of type IDispatch,
and everything seems ok, but when i query interface (it's done automatically
because i use smart pointers) i cannot get pointer to any of the
interfaces(COM objects) that the method creates.

 . . .
 VARIANT res;
 int result = ptrMyClass->Evaluate((BSTR)bstrtExp, &res);

 if(res.vt == (VT_DISPATCH | VT_BYREF))
 {

  if( (*(res.ppdispVal)) != NULL )
  {
   IFirstObjectPtr ptrMatrix;
   ISecondObjectPtr ptrSecond;

   ptrMatrix = *(res.ppdispVal);
   if(ptrMatrix == NULL)
   {
    ptrSecond = *(res.ppdispVal);
    if(ptrSecond == NULL)
    {
 /* Here is the problem, returned VARIANT structure contains a pointer to
interface but it is not a  pointer to any of the COM objects that method can
create*/
     MessageBox("ERROR - result is not 'FirstObject' nor 'SecondObject'!");
     return;
    }
   }

   // . . .
  }
  else
  {
   MessageBox("Null IDispatch interface pointer - no result!");
  }

 }

Any ideas?
Thanks a lot



Thu, 15 Apr 2004 23:47:47 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. passing COM object pointers to another COM object in ATL

2. passing objects from VB as VARIANT to COM server object failing

3. passing objects from VB as VARIANT to COM server object failing

4. Passing an array of VARIANTs to a COM component

5. COM/ATL novice:passing object pointers through methods on a COM interface

6. Passing a VARIANT by ref to a COM object

7. Passing COM objects as parameters to other COM objects

8. Passing COM objects as parameters to other COM objects

9. Passing COM object to JAVA through ActiveX = Grrrrrr

10. Return a pointer to a nested COM object from a COM object method

11. Passing pointers to COM objects

12. Can I pass CObject pointer to COM object

 

 
Powered by phpBB® Forum Software