Link to home
Start Free TrialLog in
Avatar of ascot
ascot

asked on

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 ?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ascot
ascot

ASKER

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?

corey
Avatar of ascot

ASKER

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