Custom Interface [out] param in an event method 
Author Message
 Custom Interface [out] param in an event method

Is it possible/acceptable to use a custom interface pointer as a
an [out] parameter of an event (I'm using connection points via
ATL wizard)?

This is the jist of what I'd like to do:

2 interfaces (eventually more):
IMyObj1
IMyObj2

From a within CMyObj1, I would like to fire an event with
parameter of type IMyObj2 **.  E.g.:

Fire_XYZ(IMyObj2 **pObj);

My goal is to be able to use VB to get to the data in IMyObj2.

Any help would be greatly appreciated.

Thanks.
Thomas Lunsford (remove zzz through zzz to email).



Wed, 09 Jun 2004 07:54:10 GMT  
 Custom Interface [out] param in an event method
It's possible as long as your event interface itself derives from
IUnknown (e.g. not a dispinterface). BTW, why the double
indirection? Do you plan to collect it from the event handler?
Notice in that case, that you have to ensure you are not passing
a valid interface pointer on entry, as it will be leaked - you
need special code in the fire loop...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Is it possible/acceptable to use a custom interface pointer as a
> an [out] parameter of an event (I'm using connection points via
> ATL wizard)?

> This is the jist of what I'd like to do:

> 2 interfaces (eventually more):
> IMyObj1
> IMyObj2

> From a within CMyObj1, I would like to fire an event with
> parameter of type IMyObj2 **.  E.g.:

> Fire_XYZ(IMyObj2 **pObj);

> My goal is to be able to use VB to get to the data in IMyObj2.

> Any help would be greatly appreciated.

> Thanks.
> Thomas Lunsford (remove zzz through zzz to email).



Wed, 09 Jun 2004 10:08:07 GMT  
 Custom Interface [out] param in an event method
(I apologize - My last post came across from a bogus address.)

Thanks for the reply (and all your replies to these groups).

At this point my brain is quite a mess, so I'm not sure why I'm
using the double indirection.  I believe it started when I was
trying to do this with IDispatch instead of IUnknown.  When I'm
back at the office, I'll have to look back at the article that
led me to think that.  To answer your question, I just want to
be able to retrieve the data in the object passed into the event
as a parameter.

The main issue I have at this point is that the IDL generated
by the ATL wizard has the interface for IMyObj1 declared first
and outside the library section where IMyObj2 is declared.  Do
I need to manually edit the idl, or am I just using the wizard
incorrectly?

Thanks again, and I appreciate your patience as I learn.
-Thomas

Quote:

> It's possible as long as your event interface itself derives from
> IUnknown (e.g. not a dispinterface). BTW, why the double
> indirection? Do you plan to collect it from the event handler?
> Notice in that case, that you have to ensure you are not passing
> a valid interface pointer on entry, as it will be leaked - you
> need special code in the fire loop...

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



Thu, 10 Jun 2004 04:34:32 GMT  
 Custom Interface [out] param in an event method
Ok, I think I'm in the home stretch.  Things are going pretty well.
I ended up having to edit the .idl file to change my _IXYXEvents
interface to be an interface (instead of dispinterface) deriving
from IUnknown (instead of from nothing).  Thanks a lot for the help.

At this point, I just have a question about the correct way to
do things.  I'm firing an event such as this:
  Fire_XYZ(IMyObj2 **pObj);
Earlier you asked why I'm using double indirection.  My main reason
is that the compiler complains that I must use double indirection
for an [out] parameter.  Should I ignore the complaint?

Finally, in firing back IMyObj2 to the VB client, the VB client has
to set it to "nothing" or I get a memory leak.  Is it acceptable to
have the VB programmer have this responsibility, or should I do a
release somewhere on the C++/ATL side of things?

Thanks again.
-Thomas

Quote:

> All you really need to ensure is that IMyObj2 comes before the _event_
> interface. The incoming object's interface is irrelevant. Rearrange your
> IDL file if you need - do not count on the ATL wizards a lot...

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> > (I apologize - My last post came across from a bogus address.)

> > Thanks for the reply (and all your replies to these groups).

> > At this point my brain is quite a mess, so I'm not sure why I'm
> > using the double indirection.  I believe it started when I was
> > trying to do this with IDispatch instead of IUnknown.  When I'm
> > back at the office, I'll have to look back at the article that
> > led me to think that.  To answer your question, I just want to
> > be able to retrieve the data in the object passed into the event
> > as a parameter.

> > The main issue I have at this point is that the IDL generated
> > by the ATL wizard has the interface for IMyObj1 declared first
> > and outside the library section where IMyObj2 is declared.  Do
> > I need to manually edit the idl, or am I just using the wizard
> > incorrectly?

> > Thanks again, and I appreciate your patience as I learn.
> > -Thomas



> > > It's possible as long as your event interface itself derives from
> > > IUnknown (e.g. not a dispinterface). BTW, why the double
> > > indirection? Do you plan to collect it from the event handler?
> > > Notice in that case, that you have to ensure you are not passing
> > > a valid interface pointer on entry, as it will be leaked - you
> > > need special code in the fire loop...

> > > --
> > > =====================================
> > > Alexander Nickolov
> > > Microsoft MVP [VC], MCSD

> > > MVP VC FAQ: http://www.mvps.org/vcfaq
> > > =====================================



Tue, 15 Jun 2004 11:58:21 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using enum as a return value in a custom [local] interface method

2. Custom activation interface problem, IUnknown methods already defined

3. Custom AppWizard, ATL component with interface/properties/methods

4. Passing custom data as param to COM objects

5. Howto interpret method param as verbatim string?

6. calling an interface method from another method in the same class

7. Calling one Interface method into another Interface

8. Default param values thru interfaces

9. (Q)How to use POINT as param in Interface function

10. calling COM interface requiring [out] VARIANT* param...?

11. Fire event with ByRef param from ATL COM ?!

12. Checksums of a.outs

 

 
Powered by phpBB® Forum Software