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 ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why wouldn't you just declare a SAFEARRAY variable in your c++ client?
corey
corey
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
I am closing this and awarding the points to jkr
ASKER
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 ?