Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Collection Classes

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\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…

610 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