Solved

Collection Classes

Posted on 1998-07-31
2
153 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now