Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 624169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:10:17+00:00 2026-05-13T19:10:17+00:00

I have an ATL COM object which needs to expose a collection of other

  • 0

I have an ATL COM object which needs to expose a collection of other COM objects, so clients can find out how many objects are in the collection (via a simple Count property which I can provide) and access the objects using its index. This collection of objects is dynamic – the count is not fixed – and I don’t know how many there will be when my main (parent) object is constructed (so I can’t create these objects in my FinalConstruct for example). The objects I want to expose only have read-only properties.

What I want to do is somehow create a std::vector of these objects the first time they are required. I want to use ATL smart COM pointers where possible so I don’t need to manually manage reference counts, etc. but I’m not sure whether I should be using CComPtr, ‘CComQIPtr’, etc.

Assuming the objects I want to return are called IChild, I was hoping I could do something like this:

std::vector<CComPtr<IChild> > children;
...
CComPtr<IChild> child;
// Somehow instantiate an IChild?
...
children.push_back(child);

STDMETHODIMP Parent::GetAt(LONG index, IChild** pRet)
{
  *pRet = children[index];
}

If anyone has any pointers on how I can achieve this, I would be very welcome. There is an excellent article on exposing a static object, but I can’t find anything on the particular problem in hand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:10:18+00:00Added an answer on May 13, 2026 at 7:10 pm

    Yes, std::vector< CComPtr<IChild> > is the way to do it – you will get a dynamic array of IChild* that manages the lifetime of IChild-derived objects. Once you want to convert the IChild* to a derived interface you’ll have to use QueryInterface() the same way as you would use dynamic_cast with C++ objects.

    There’s no point to use CComQIPtr for the array. The primary use of CComQIPtr is to have a convenient way to call QueryInterface() on a pointer to an object that maybe implements the interface of interest. Instead of calling QueryInterface() and checking the result you invoke the CComQIPtr constructor and check whether the resulting object contains a non-null pointer. You could use CComQIPtr in the code that uses your array, but there’s no point in using it for the array itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a COM object implemented with C++/ATL that includes a method which will
I have a ATL COM component method which has an [out] BSTR* parameter. I
I have an ATL COM component method which takes a BSTR as an in
I have a ATL COM project that was compiling fine in VC6 which gives
I have an ATL COM object that I am using from C#. The interface
I've written an ATL/ActiveX object which exposes various properties and methods through its COM
I have generated an ATL COM object using VS2008 and the code contains references
I created a Windows NT service, which exports a COM interface using ATL (out-of-proc
I have a requirement to create an ATL COM service which does some operation
I have a working Browser Helper Object (BHO) which is essentially an ATL based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.