COM Server returning array of objects

In summary I have an in-process COM Server written in C++ that I want to return an array or collection of objects so that a VB Client app or VC++ Client app can then enumerate through that list.

COM Server has 2 interfaces, WidgetManager and Widget.  COM Server is created using ATL.

WidgetManager has one method, GetList, that I want to return a list/array/collection of Widget objects.  The WidgetManager should return its list of global Widget data.  The idea is that the Client calls WidgetManager.GetList() to get a list of Widgets.  I only want the Client to have a copy of th Widgets.  Client then goes through the list calling methods on the Widget interface for each Widget in the collection.

The Client can be Visual Basic or VC++ only so don't need to support Automation.

Question :- what should my GetList() method signature look like ?  I need to define this for the application programmers - VB or VC++.

Could anybody give me some sample code ?
Who is Participating?
Check out;en-us;205277 ("How to pass arrays and strings between Visual Basic and C functions or between Visual Basic and C++ functions by using Visual Basic 6.0"). The idea is to use SAFEARRAYs for that purpose.
ascotAuthor Commented:
Thanks for the response.  The link is very useful for VB Clients.  What I'm really looking for is "Pass an array of user defined types by using type libraries"
From the example that looks like I need
HRESULT ATL_Func1([in, out] SAFEARRAY (myType)*ppsaMyArray, [out, retval] long *plResult);

But then how do I call an interface that is defined using SAFEARRAY from a C++ client ?
Why wouldn't you just declare a SAFEARRAY variable in your c++ client?

ascotAuthor Commented:
The links mentioned by jkr were very useful - however I have now discovered the COM enumerators and I think that is the way forward  as I understand that it will enable me to expose an STL collection of Widgets that a VB Client can then iterate through as though it were a VB Collection of Widgets.  
I am closing this and awarding the points to jkr
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.