Enumerate (list) USB webcams
-
I need to be able to list webcams that are plugged in. I can use DeviceChange to tell when a webcam is plugged or unplugged and I am then using the function shown below to create a list of all video devices. This works for all "normal" webcam devices since they appear and disappear from the list when I call the function after they are plugged in or unplugged. Unfortunately, I also have an older webcam, Logitech "Quickcam", that is ALWAYS listed regardless of whether it is plugged in or not... That represents a pathological case. I need a way to determine if it is really plugged in WITHOUT disrupting it in case my software is currently using it. I have scoured all 5 device driver and USB books I know of, scoured MSDN, scoured the internet, tried LOTS of code including USBView which ALMOST provides the information but DISPLAYS A DIFFERENT NAME (not the "FriendlyName" I expected!) so I cannot correlate the information. Anyone know of a solution? (I think this is a REALLY tough problem... I will be unavailable for a couple of weeks but I really need to find a solution and will respond as soon as possible...) VideoDeviceList *CMotionDetectDlg::GetVideoDeviceList() { static VideoDeviceList VideoList; USES_CONVERSION; UINT uIndex = 0; HRESULT hr; BOOL bCheck = FALSE; //Clear all previous video list entries for(int i = 0; i < NUMELMS(VideoList.videoMoniker); i++) { if(VideoList.videoMoniker[i]){ VideoList.videoMoniker[i]->Release(); VideoList.videoMoniker[i] = NULL; } } VideoList.videoString.RemoveAll(); VideoList.numberOfDevices = 0; // enumerate all video capture devices ICreateDevEnum *pCreateDevEnum = 0; hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&pCreateDevEnum); if(hr != NOERROR) { MessageBox(NULL, "Error Creating Device Enumerator"); return NULL; } IEnumMoniker *pEm = 0; hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEm, 0); if(hr != NOERROR) { CString message; message = CString("No Video capture device was found.\r\n\r\n") + CString("Please plug in a webcam or other video capture device."); //MessageBox(message, "Notice"); if(pEm)pEm->Release(); return NULL; } pEm->Reset(); ULONG cFetched; IMoniker *pM; while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK) { IPropertyBag *pBag=0; hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag); if(SUCCEEDED(hr)) { //VARIA