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
Solved

Collection Classes

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
abstract class with all non abstract mentods 6 79
canBalance challenge 34 96
Microsoft C++ code failing in executable that worked 9 108
Problem to App source 6 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

808 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