Groups | Blog | Home
all groups > dotnet interop > july 2007 >

dotnet interop : Newbie COM question about passing arrays


Brian Jones
7/21/2007 6:43:44 PM
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
Brian Muth
7/21/2007 10:08:58 PM

[quoted text, click to view]

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



Jealani
8/3/2007 12:43:15 PM
did you get an answer on how to pass arrays to COM component. if so
please let me know. i shall update you if i happen to find the
solution first. thank you.
AddThis Social Bookmark Button