I've never used this interface before, but it seems similar to other COM routines that return a list. As the documentation says, call it first with NULL to determine how many items exist, the allocate memory for the list, then call it again with your list. If I'm reading the docs correctly the list is an array of wide string pointers. The caller need only allocate the list of pointers. The function allocates memory for each string in the list and assigns them to your pointer list. Later, the caller is responsible for freeing the memory for each string. The code flow should be something like this:
Code:
int doit()
{
DWORD count=0;
HRESULT hr;
wchar_t **devlist;
IPortableDeviceManager *p;
//assume p is instantiated and points to the proper interface.
hr=p->GetDevices(NULL,&count);
//check hr
//count should be number of devices (maybe do sanity check).
devlist=new wchar_t *[count];
hr=p->GetDevices(devlist,&count);
for(int i=0;i<count;i++){
DoWhateverWith(devlist[i]);
}
//cleanup
for(int i=0;i<count;i++){
CoTaskMemFree(devlist[i]);
}
delete[] devlist;
}
Bookmarks