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

  • Home
  • SEARCH
  • 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 8247703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:56:23+00:00 2026-06-07T22:56:23+00:00

I’m hoping someone can help with this question. I’m also hoping that this question

  • 0

I’m hoping someone can help with this question. I’m also hoping that this question has a simple answer. I feel like I’m missing something very obvious, but I’m new to C++ and have been unable to get past this issue.

I want to pass an IUpdateCollection to a function, put IUpdates into the collection, and then be able to access the collection outside of the function. In the code below, everything compiles/runs, but the count of items in the IUpdateCollection is 5 while inside the Searcher function, but when I later try to count the items in the IUpdateCollection from outside the function, the count is 0.

What am I missing here?

Thanks!

class W
{
public:
    // constructor
    W()
    {       
        //create the COM object to return the IUpdateSession interface pointer
        hr = CoCreateInstance( )
    }

    int Searcher(IUpdateCollection* pUpdateCollection)
    {                           

        //put the updates into our pUpdateCollection
        hr = pSearchResult->get_Updates(&pUpdateCollection);
        if(FAILED(hr) || pUpdateCollection == NULL)
        { cout << "Failed to put updates in the collection"; return -103; };

        long lUpdatesCount = NULL;
        hr = pUpdateCollection->get_Count(&lUpdatesCount);
        if(FAILED(hr) || pSearchResult == NULL)
        { cout << "Failed to get count of udpates in collection"; return -104; };

        cout << lUpdatesCount << endl;  //console outputs the actual count here, which at the moment is 5

        pUpdateSearcher->Release();     
        return 0;
    }
private:
    HRESULT hr;
    IUpdateSession* pUpdateSession; 
};

int main(int argc, char* argv[])
{
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    HRESULT hr;


    W myW;
    //pass the pUpdateCollection to the W.Searcher function
    myW.Searcher(pUpdateCollection);

    //get count of updates in collection
    long lUpdatesCount = NULL;
    pUpdateCollection->get_Count(&lUpdatesCount);

    cout << lUpdatesCount << endl;  //console outputs 0 here instead of the same count that it outputted in W.Searcher().  WHY?
    CoUninit();

    system("pause");
    return 0;
}
  • 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-06-07T22:56:25+00:00Added an answer on June 7, 2026 at 10:56 pm

    Use smart pointers like _com_ptr_t and _bstr_t. USing the raw pointers and directly operating BSTRs is nothing but pain.

    #import-ing the COM DLL will create the typed smart pointers for you, including easy to use CreateInstance methods. Smart pointer also eliminate the need to explicitly check for HR after each call, they raise exceptions.

    As to your question: it depends on the implementation/specification/documentation of your COM object. Perhaps releasing the IUpdateSearcher clears up the count, but is just speculation on my part. The relevant code would be the COM server, not the client.

    didn’t notice this is WUA, documented behavior

    ISearchResult::Updates assigns the IUpdateCollection. Therefore you are passing in a value of the pointer, change it in the function scope, then expect the change to apply outside the scope. The very same thing you’re doing, but using int:

    void f(int a)
    {
      a=5;
    }
    
    void main()
    {
      int a = 7;
      f(a);
      printf("%d", a); -- of course is 7, not 5
    }
    

    You would solve the ‘problem’ for int by passing by ref or a pointer. Same applies to your COM pointer. And using _com_ptr_t would have clearly showed the issue 🙂

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.