Newbie COM question about passing arrays
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. Can someone point me to any articles
or sample code to do this, or just let me know some keywords I should search
Google for? I don't know where to start for passing arrays in COM.
Thanks.
-Brian
Date:Sat, 21 Jul 2007 18:43:44 -0700
Author:
|
Re: Newbie COM question about passing arrays
"Brian Jones" 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
Date:Sat, 21 Jul 2007 22:08:58 -0700
Author:
|