?
Solved

Collection Classes

Posted on 1998-07-31
2
Medium Priority
?
162 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 200 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

752 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