End Google Ads 201810 - BS.net 01 --> void CDeviceList::GetDeviceList(std::vector& info)
{
int i = 0;
HRESULT hr;

// enumerate all video capture devices
CComPtr pCreateDevEnum;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&pCreateDevEnum);
if (hr != NOERROR)
{
return;
}

CComPtr pEm;
hr = pCreateDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEm, 0);
if (hr != NOERROR)
{
return;
}


pEm->Reset();
ULONG cFetched;
IMoniker *pM;
char* name = new char[255];
char* loc = NULL;

while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
{
IPropertyBag *pBag;
hr = pM->BindToStorage(0,0,IID_IPropertyBag,(void**)&pBag);
if(SUCCEEDED(hr))
{
VARIANT var;
var.vt = VT_BSTR;
hr = pBag->Read(L"FriendlyName", &var, NULL);
wcstombs(name, var.bstrVal, 255);

if (hr == NOERROR)
{
loc = strstr(name,"(VFW)");
if (loc==NULL)
{
info.push_back(name);
}
}
SAFE_RELEASE(pBag);
}
SAFE_RELEASE(pM);
}
delete[] name;
}



I have written a class cDeviceHandler. I want when i start thread it should compare two device lists and display message. code of cDeviceHandler class is given below:


#include "StdAfx.h"
#include "DeviceHandler.h"

CDeviceHandler::CDeviceHandler(void)
{
//get device list in a string vector devList
dList.GetDeviceList(devList);
}

void CDeviceHandler::start(void)
{
startThread = TRUE;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, this, 0, NULL);
}

void CDeviceHandler::stop(void)
{
startThread = FALSE;
}

int CDeviceHandler::ThreadProc(LPVOID lpParam)
{
CDeviceHandler* ptr = (CDeviceHandler*) lpParam;

while(ptr->startThread)
{
vector nList;
ptr->dList.GetDeviceList(nList);

char * cDeviceName = new char[260];
int status = ptr->CompareLists(ptr->devList,nList,cDeviceName);
switch(status)
{
case 0: {
TRACE("No Device Arrived nor Removed\n");
}
break;
case 1: {
TRACE("Device Removed \"%s\"\n",cDeviceName);
}
break;
case 2: {
TRACE("Device Arrived \"%s\"\n",cDeviceName);
}
break;
}
delete[] cDeviceName;
ptr->devList = nList;
Sleep(500);
}
return 0;
}

whenever i try to get new device list using
ptr->dList.GetDeviceList(nList);

previous device list is discarded and all member variables of current object are reset. Why is this happening?? can anyone explain it to me?

Regards,
K. Masood