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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

Iterate through COM Collection from C++ Client

I've follwed the example at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/vcconimplementingstlbasedcollection.asp to implement my STL Collection in a COM Server written in C++.

However, I can't work out how to iterate the Collection from a C++ Collection.  anybody help ?
0
ascot
Asked:
ascot
  • 4
1 Solution
 
novitiateCommented:
You can either use CComEnumOnSTL or use Count and Item methods.
1 - CComEnumOnSTL

  get__NewEnum();
  for(Next())
  {
  }

2 - Count & Item
   get_Count();
   for(0 to Count)
  {
    Item()
  }

Also Refer: http://www.codemarine.com/downloads/257,1,ATL & Enumeration
_novi_
0
 
ascotAuthor Commented:
Thanks novi,

Could you recheck that URL pls as I just get Page not found
0
 
ascotAuthor Commented:
I'm afraid my query is even more basic than that novi - how I get the object to call the get_NewEnum method on ?  i.e. in the example I have given, I am talking about the IWords object
0
 
ascotAuthor Commented:
The problem is that I have created the COM Server as described in the MSDN article on implementing an STL-based collection at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/vcconimplementingstlbasedcollection.asp.

It describes editing the IDL file as follows:-
    interface IWords : IDispatch
    {
        [id(DISPID_NEWENUM), propget]                     // (3)
        HRESULT _NewEnum([out, retval] IUnknown** ppUnk);

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

        [id(0x00000001), propget]                         // (6)
        HRESULT Count([out, retval] long* pVal);
    };
Then I have followed your suggestion re get_Count() and get_NewEnum() and stipped my client down to just this:-

CoInitialize(NULL);
IWords* pWords;
HRESULT hRes=CoCreateInstance(CLSID_Words,NULL,
                  CLSCTX_INPROC_SERVER, IID_IWords, (void**)&pWords);
long lCount = pWords->get_Count();
IEnumVARIANTPtr spEnum = pWords->get_NewEnum();

when I compile I get
'get_Count' : function does not take 0 parameters
'get_NewEnum' : is not a member of 'IWords'

but OLE Viewer showing the type library shows
    [
      odl,
      uuid(8FD54638-116A-4C6E-9251-9854FB51851F),
      helpstring("IWords Interface"),
      dual,
      nonextensible,
      oleautomation
    ]
    interface IWords : IDispatch {
        [id(0xfffffffc), propget]
        HRESULT _NewEnum([out, retval] IUnknown** ppUnk);
        [id(00000000), propget]
        HRESULT Item(
                        [in] long Index,
                        [out, retval] BSTR* pVal);
        [id(0x00000001), propget]
        HRESULT Count([out, retval] long* pVal);

0
 
ascotAuthor Commented:
Got it working by changing get_NewEnum to Get_NewEnum and get_Count to GetCoiunt. !!

Don't understand why
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

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