Click here to Skip to main content
15,908,444 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to get account expire value from Active Directory Pin
Randor 12-Oct-09 3:10
professional Randor 12-Oct-09 3:10 
QuestionSendMessage Aplication beetween switch xp users [modified] Pin
maulik_patel12-Oct-09 2:30
maulik_patel12-Oct-09 2:30 
AnswerRe: SendMessage Aplication beetween switch xp users Pin
«_Superman_»12-Oct-09 7:51
professional«_Superman_»12-Oct-09 7:51 
GeneralRe: SendMessage Aplication beetween switch xp users Pin
maulik_patel12-Oct-09 18:36
maulik_patel12-Oct-09 18:36 
QuestionCompilation error Pin
shilpi_gupta070812-Oct-09 2:01
shilpi_gupta070812-Oct-09 2:01 
AnswerRe: Compilation error Pin
Randor 12-Oct-09 2:15
professional Randor 12-Oct-09 2:15 
QuestionRe: Compilation error Pin
David Crow12-Oct-09 2:49
David Crow12-Oct-09 2:49 
AnswerRe: Compilation error Pin
shilpi_gupta070812-Oct-09 2:52
shilpi_gupta070812-Oct-09 2:52 
Questionminix Pin
rad-212-Oct-09 1:48
rad-212-Oct-09 1:48 
AnswerRe: minix Pin
Rajesh R Subramanian12-Oct-09 2:23
professionalRajesh R Subramanian12-Oct-09 2:23 
Questionminix 3 Pin
rad-212-Oct-09 1:38
rad-212-Oct-09 1:38 
AnswerRe: minix 3 Pin
JosephHill31-Oct-09 17:20
JosephHill31-Oct-09 17:20 
QuestionDirectShow: Building Graph for input over network Pin
priteek12-Oct-09 1:30
priteek12-Oct-09 1:30 
AnswerRe: DirectShow: Building Graph for input over network Pin
Code-o-mat12-Oct-09 10:02
Code-o-mat12-Oct-09 10:02 
QuestionHow to implement PrintScreen functionality in VC++6.0 Pin
Arun Abraham Jose12-Oct-09 1:14
Arun Abraham Jose12-Oct-09 1:14 
QuestionRe: How to implement PrintScreen functionality in VC++6.0 Pin
CPallini12-Oct-09 1:57
mveCPallini12-Oct-09 1:57 
QuestionRe: How to implement PrintScreen functionality in VC++6.0 Pin
David Crow12-Oct-09 2:52
David Crow12-Oct-09 2:52 
AnswerRe: How to implement PrintScreen functionality in VC++6.0 Pin
kilt13-Oct-09 2:20
kilt13-Oct-09 2:20 
GeneralRe: How to implement PrintScreen functionality in VC++6.0 Pin
Henry Minute13-Oct-09 5:21
Henry Minute13-Oct-09 5:21 
GeneralRe: How to implement PrintScreen functionality in VC++6.0 Pin
Arun Abraham Jose14-Oct-09 3:21
Arun Abraham Jose14-Oct-09 3:21 
QuestionGet List of Devices Currently Attached in a thread [modified] Pin
tibbasultanpur12-Oct-09 0:04
tibbasultanpur12-Oct-09 0:04 
i am using this function to get device lists.

void CDeviceList::GetDeviceList(std::vector<string> &info)
{
	int i = 0;
	HRESULT hr;

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

    CComPtr<IEnumMoniker> 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<string> 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

modified on Tuesday, October 13, 2009 12:03 AM

AnswerPlease reformat your code snippets Pin
CPallini12-Oct-09 0:20
mveCPallini12-Oct-09 0:20 
AnswerRe: Get List of Devices Currently Attached in a thread Pin
David Crow12-Oct-09 3:01
David Crow12-Oct-09 3:01 
GeneralRe: Get List of Devices Currently Attached in a thread Pin
tibbasultanpur12-Oct-09 18:17
tibbasultanpur12-Oct-09 18:17 
QuestionRe: Get List of Devices Currently Attached in a thread Pin
David Crow13-Oct-09 2:54
David Crow13-Oct-09 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.