?
Solved

COM Server returning array of objects

Posted on 2005-05-05
4
Medium Priority
?
288 Views
Last Modified: 2013-11-25
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 ?
0
Comment
Question by:ascot
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 750 total points
ID: 13937834
Check out http://support.microsoft.com/default.aspx?scid=kb;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.
0
 

Author Comment

by:ascot
ID: 13940701
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 ?
0
 
LVL 8

Expert Comment

by:_corey_
ID: 13941428
Why wouldn't you just declare a SAFEARRAY variable in your c++ client?

corey
0
 

Author Comment

by:ascot
ID: 13945740
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
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question