Brian Muth
7/22/2007 5:09:00 AM
"Brian Jones" <brian@aol.com> wrote in message
news:%231qg%23GAzHHA.3696@TK2MSFTNGP03.phx.gbl...
> Hello,
> I'm new to COM development. Here's what I want to do:
>
> In unmanaged C++:
>
> 1) Create an interface called ITeam
> 2) Create another interface called IPerson
> 3) Create a method in ITeam called GetTeamMembers. this will return an
> array of IPerson's.
>
> In unmanaged C# or VB.NET:
>
> I want to call the above GetTeamMembers method, and process it using a
> foreach loop.
>
> Hopefully this isn't too complicated.
I'm afraid it's a little more complicated that you think.
In order to use the foreach construct, you need to build an interface that
derives from IDispatch and implements
[id(DISPID_NEWENUM), propget] HRESULT _NewEnum([out, retval] IUnknown**
ppEnum);
This returns an interface called a COM enumerator. A typical interface would
be IEnumVariant, which can handle enumerating over a collection of variants.
Since you are posting in an ATL newsgroup, you might be interested in
knowing that there are a number of useful ATL templates to help with the
enumeration implementation, specifically CComEnumOnSTL and IEnumOnSTLImpl<>.
You might be able to Google for some examples, but the very best reference
is Chapter 7 of the highly esteemed book ATL Internals. There are over 50
pages dedicated to this subject (Collections and Enumerators), which I think
reflects that fact that this is a little more complicated than what you are
probably anticipating.
Brian