[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Exposing an STL Vector of my objects via COM Interface Using ATL

Posted on 2005-05-06
Medium Priority
Last Modified: 2013-12-14
I'm trying to expose an STL Vector of my objects via COM Interface Using ATL.

I can find examples where built in types are being used e.g. the STL vector is storing wstring objects and clients are expecting BSTR objects.  But I have a COM Server that stores a list of Widget objects.  So I want the STL vector to store Widget objects and the client to also expect Widget objects.
COM Server is in process. Client is VB or C++.

I create my Simple Object using the ATL COM Wizard which generates an interface IWidgetManager.
I then open the IDL file and add the three properties necessary to turn IWidgetManager into a read-only collection interface i.e. Count, Item, _NewEnum.
If the Client is expecting BSTR objects, the resulting IDL file would look like this

interface IWords : IDispatch
    [id(DISPID_NEWENUM), propget]
    HRESULT _NewEnum([out, retval] IUnknown** ppUnk);

    [id(DISPID_VALUE), propget]
    HRESULT Item(
        [in] long Index,
        [out, retval] BSTR* pVal);    

    [id(0x00000001), propget]    
    HRESULT Count([out, retval] long* pVal);

But I want my client to expect the the same objects that I am queuing i.e. Widgets

 [id(DISPID_VALUE), propget]
    HRESULT Item(
        [in] long Index,
        [out, retval] Widget* pVal);

I have 2 questions:-
1. Is what I am doing sensible i.e. My COM Server is returning a list of Widgets and I expect the Client to then understand Widgets.  Am I doing some close coupling here that will come back to haunt me when I have learned a bit more i .e. should I actually be returning a list of Interface objects i.e. IWidgets ??
2. Given the description above - how do I tell the idl/midl about the Widget class ?
Question by:ascot
  • 2
  • 2
LVL 86

Expert Comment

ID: 13945879
>>Client is VB or C++.

If your client is VB, you should create an IDispatch-derived IWidget interface to ensure the compatibility, e.g.

interface IWebBrowser : IDispatch {

// IWidget methods here

Author Comment

ID: 13948484
Thanks for the feedback.  Would you mind expanding on that though please jkr - I don't have as much knowledge as it might seem I have from the question

LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 13962839
Hmm, since there are not too many details given, the explanation will be a tad bit general, so, you'd start declaring

helpstring("IWidget interface"),
interface IWidget : IDispatch
// IWidget methods here
    [id(DISPID_GETNAME), propget]
   HRESULT GetName( [out, retval] BSTR* pNamel);    


you can use the IWidget type like you wrote above:

 [id(DISPID_VALUE), propget]
   HRESULT Item(
       [in] long Index,
        [out, retval] IWidget* pVal);

Author Comment

ID: 13969697
Thanks for the further explanation jkr.  I understand what you mean now.  However, I have concluded that it makes sense to develop my component as a .NET component and use CCW to call from existing COM clients.
That way all the COM headache stuff is hidden from me.
I am closing this question and awarding the points to jkr.  Don't suppose you can help on the threading model question that I have outstanding can you ?

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
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…

873 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