Solved

Collection Classes

Posted on 1998-07-31
2
161 Views
Last Modified: 2013-11-25
I'm implementing a library of COM objects using ATL.  I need to expose numerous collections to the client.  My primary clients will be written in VB, so the ideal resulting syntax would be:
v= obj(index).value
o= obj(index).otherValue
Or
v= obj.item(index).value
o= obj.item(index).otherValue

I've seen these two variations in syntax used before, how do I implement them with ATL?  Please provide references and code examples.

Thanks.

0
Comment
Question by:rayb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
endeavor earned 50 total points
ID: 1320038
Make sure you have the Item method specified as the default member (id(0)) of your collection class in your .idl file. For example:

interface IMyCollection : IDispatch
{
    [id(0), helpstring ("method Item")] HRESULT _stdcall Item([in] VARIANT * Index, [out, retval] VARIANT * pItem);

}

The key here is to specify id(0) for the member you want ot be the default.  Then you can use either:

v = myCollection.Item(Index)  

Or

v = myCollection(Index)

I have found it really helpful to use the OLE/COM Object Viewer to decompile other type libraries (such as Visual Basic for Applications).  If you want things to act the same as other objects just make sure your .idl specifications match.

-- George


0
 
LVL 2

Author Comment

by:rayb
ID: 1320039
This works great, George.
Thanks.

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

690 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