Passing COM objects as parameters to other COM objects 
Author Message
 Passing COM objects as parameters to other COM objects

Hi

I need to transfer a reference to a COM object as a parameter to another COM
object in C++. What do I need to implement on both sides? On the 'sender
side' to allow the object to be passed by reference, and on the 'receiver
side' what is actually received?

I can't find any reference on MSDN or on previous newsgroup posts...

Cheers,

Paul.



Sun, 23 Nov 2003 18:31:00 GMT  
 Passing COM objects as parameters to other COM objects


Fri, 19 Jun 1992 00:00:00 GMT  
 Passing COM objects as parameters to other COM objects
Pass them as IUnknown and dynamically_cast them back to what they were...


Quote:
> Hi

> I need to transfer a reference to a COM object as a parameter to another
COM
> object in C++. What do I need to implement on both sides? On the 'sender
> side' to allow the object to be passed by reference, and on the 'receiver
> side' what is actually received?

> I can't find any reference on MSDN or on previous newsgroup posts...

> Cheers,

> Paul.



Sun, 23 Nov 2003 19:07:40 GMT  
 Passing COM objects as parameters to other COM objects
OK, so is there any sample code around at all?

What I actually need to do is send from Visual Basic Scripting. i.e.

Result = MyObject2.MyMethod(MyObject1)

On the C++ receiver side would this actually receive a pointer to IUnknown?
If so, how do I then get access to the other interfaces.

Paul.



Quote:
> Pass them as IUnknown and dynamically_cast them back to what they were...



> > Hi

> > I need to transfer a reference to a COM object as a parameter to another
> COM
> > object in C++. What do I need to implement on both sides? On the 'sender
> > side' to allow the object to be passed by reference, and on the
'receiver
> > side' what is actually received?

> > I can't find any reference on MSDN or on previous newsgroup posts...

> > Cheers,

> > Paul.



Sun, 23 Nov 2003 19:09:45 GMT  
 Passing COM objects as parameters to other COM objects


Quote:
> OK, so is there any sample code around at all?

> What I actually need to do is send from Visual Basic Scripting. i.e.

I know NOTHING of VB

Quote:
> Result = MyObject2.MyMethod(MyObject1)

> On the C++ receiver side would this actually receive a pointer to

IUnknown?

Don't know

Quote:
> If so, how do I then get access to the other interfaces.

If it does, you can cast it to the apropriate interface by doing :
    IMyInterface myInt = dynamic_cast<IUnknown*>(myIncomingPointer);

But this is WAY OFF TOPIC at this groupt, consider sending posts about ATL,
ActiveX, COM etc... to


Quote:

> Paul.

[snip]


Sun, 23 Nov 2003 19:30:50 GMT  
 Passing COM objects as parameters to other COM objects

Quote:
> Pass them as IUnknown and dynamically_cast them back to what they were...

Um. Don't dynamic cast. Use QueryInterface.

You can pass any interface pointer directly. You don't need to send IUnknown
only for C++. However, if you are using scripting, then IUnknown it is.

In C++, to pass an object into a function, use in idl

[in] IUnknown *p

as a function parameter. Do not call AddRef or Release on the pointer,
either in the calling function or the called, unless the parameter is being
saved for future reference. Then it is best to use a smart pointer class,
such as CComPtr<> to do it for you.

If you are not using scripting, you can replace IUnknown with the interface
of your choice so you don't have to bother QueryInterfacing into what you
really want.

Christian.



Sun, 23 Nov 2003 19:54:42 GMT  
 Passing COM objects as parameters to other COM objects
Paul, I have a similar situation and what i do is as Thomas said on the C++
side receive the object as IUknown* but I then use QueryInterface to get the
required interface pointer rather than using dynamic_cast as the former is
safer.



Quote:



> > OK, so is there any sample code around at all?

> > What I actually need to do is send from Visual Basic Scripting. i.e.

> I know NOTHING of VB

> > Result = MyObject2.MyMethod(MyObject1)

> > On the C++ receiver side would this actually receive a pointer to
> IUnknown?

> Don't know

> > If so, how do I then get access to the other interfaces.

> If it does, you can cast it to the apropriate interface by doing :
>     IMyInterface myInt = dynamic_cast<IUnknown*>(myIncomingPointer);

> But this is WAY OFF TOPIC at this groupt, consider sending posts about
ATL,
> ActiveX, COM etc... to


> > Paul.
> [snip]



Mon, 24 Nov 2003 03:13:48 GMT  
 Passing COM objects as parameters to other COM objects
No I don't think so, script will not like IUnknown.

You best pass IDispatch for script (in VB it will be of type Object or
variant, in VBScript it would be a variant).

...and I agree with your comment about not using casts....casting an
interface pointer parameter (that was not conditioned with iid_is in the IDL
prototype) that is a good way to cause an access violation if the pointer is
to a proxy.

Peter Partch


Quote:
> > Pass them as IUnknown and dynamically_cast them back to what they
were...

> Um. Don't dynamic cast. Use QueryInterface.

> You can pass any interface pointer directly. You don't need to send
IUnknown
> only for C++. However, if you are using scripting, then IUnknown it is.

> In C++, to pass an object into a function, use in idl

> [in] IUnknown *p

> as a function parameter. Do not call AddRef or Release on the pointer,
> either in the calling function or the called, unless the parameter is
being
> saved for future reference. Then it is best to use a smart pointer class,
> such as CComPtr<> to do it for you.

> If you are not using scripting, you can replace IUnknown with the
interface
> of your choice so you don't have to bother QueryInterfacing into what you
> really want.

> Christian.



Mon, 24 Nov 2003 21:10:34 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Passing COM objects as parameters to other COM objects

2. C++ COM-Object with COM-Object as parameter

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

4. Passing a COM object as a parameter?

5. Passing VB dictionaries as parameters to ATL COM objects

6. Passing a COM object to a non-COM aware class

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

8. Passing an Excel COM object to a C++ COM Server

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

10. Invoking COM object from COM object

11. COM Object returning COM Object Reference

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

 

 
Powered by phpBB® Forum Software