• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

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

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

e.g.
 [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 ?
0
ascot
Asked:
ascot
  • 2
  • 2
1 Solution
 
jkrCommented:
>>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
}
0
 
ascotAuthor Commented:
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

0
 
jkrCommented:
Hmm, since there are not too many details given, the explanation will be a tad bit general, so, you'd start declaring

[
uuid(a03d1424-b1ec-11d0-8c3a-00c04fc31d2f),
helpstring("IWidget interface"),
pointer_default(unique);
dual,
oleautomation
]
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);
0
 
ascotAuthor Commented:
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 ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now