Hi guys! After 13 years of losing my real programming skills by getting sucked into Java I've decided to dive back into C++. I wrote a small program to read from a webcam and display the output and now I'm going back and trying to make a framework out of this application. I have one method that just is not working how I would expect and I'm sure the experts here can help.
Here is what I have. This method interrogates the device driver to extract information about a device and builds an object that stores this information then places that object in a vector. This seems to work fine.
HRESULT WebCamDeviceList::RegisterDevice(UINT32 index, IMFActivate* vDevice, IMFMediaSource* vMediaSource, IMFSourceReader* vMediaReader) {
HRESULT hr = S_OK;
LPWSTR dFriendlyName = NULL;
UINT32 dName = NULL;
hr = vDevice[index].GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &dFriendlyName, &dName);
if(SUCCEEDED(hr)) {
WebCamDevice* wDevice = new WebCamDevice();
wDevice->SetIndex(index);
wDevice->SetName(dName);
wDevice->SetFriendlyName(dFriendlyName);
wDevice->LoadConfiguration(vMediaSource, vMediaReader);
_DeviceList.push_back(wDevice);
} else {
MessageBox(NULL,TEXT("Unable to retieve device name"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
}
return hr;
}
This piece of code retrieves that object pointer from the vector and passes it back to the caller. Using the debugger the retrieval of the object pointer seems to work fine. The problem is that the "device" parameter is passed back with no values almost like it went out of scope and if it was Java I would assume the GCer got it.
HRESULT WebCamDeviceList::GetDevice(size_t index, WebCamDevice** device) {
HRESULT hr = S_OK;
WebCamDevice* cDevice = NULL;
if (index < _DeviceList.size()) {
cDevice = _DeviceList[index];
}
device = &cDevice;
return hr;
}
If this helps here is the caller. The line "deviceList->GetDevice(index, &device)" passes back a empty object even though right before it exits I can see the pointer is valid with the debugger.
WebCamDeviceList* deviceList = new WebCamDeviceList();
deviceList->LoadDevices();
deviceList->GetCount(&numberDevices);
size_t index = 0;
mainWindow = new GuiMain(hWnd,hInstance);
while( index < numberDevices ) {
WebCamDevice* device = NULL;
deviceList->GetDevice(index, &device);
if(device->GetFriendlyName() != NULL) {
SendMessage(mainWindow->DeviceListBox, LB_ADDSTRING, 0, (LPARAM)device->GetFriendlyName());
}
index++;
}
This has to be something very simple and I feel like a fool not understanding what is going on since I used to do this for a living but Java has destroyed my pointer and memory management skills.
Thank you in advance for any help.
Kevin