[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Newbie COM question about passing arrays

Brian Jones

7/22/2007 1:44:00 AM

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

2 Answers

Brian Muth

7/22/2007 5:09:00 AM

0


"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




Jealani

8/3/2007 7:43:00 PM

0

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.