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;
}