Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
QuestionInitialize into const char** Pin
m_mun11-Oct-09 23:15
m_mun11-Oct-09 23:15 
AnswerRe: Initialize into const char** Pin
Iain Clarke, Warrior Programmer11-Oct-09 23:20
Iain Clarke, Warrior Programmer11-Oct-09 23:20 
GeneralRe: Initialize into const char** Pin
m_mun11-Oct-09 23:43
m_mun11-Oct-09 23:43 
AnswerRe: Initialize into const char** Pin
CPallini12-Oct-09 0:08
mveCPallini12-Oct-09 0:08 
GeneralRe: Initialize into const char** Pin
m_mun12-Oct-09 0:32
m_mun12-Oct-09 0:32 
AnswerRe: Initialize into const char** Pin
«_Superman_»12-Oct-09 8:58
professional«_Superman_»12-Oct-09 8:58 
Question40 bit decimal to binary Pin
Makakuin11-Oct-09 21:03
Makakuin11-Oct-09 21:03 
AnswerRe: 40 bit decimal to binary Pin
CPallini11-Oct-09 22:19
mveCPallini11-Oct-09 22:19 
Questionhow to check if a thread handle is available Pin
Hari_1611-Oct-09 19:49
Hari_1611-Oct-09 19:49 
AnswerRe: how to check if a thread handle is available Pin
Iain Clarke, Warrior Programmer11-Oct-09 20:47
Iain Clarke, Warrior Programmer11-Oct-09 20:47 
AnswerRe: how to check if a thread handle is available Pin
CPallini11-Oct-09 22:21
mveCPallini11-Oct-09 22:21 
Questionconvert pdf to tif file in C Pin
billcodes11-Oct-09 18:49
billcodes11-Oct-09 18:49 
AnswerRe: convert pdf to tif file in C Pin
Iain Clarke, Warrior Programmer11-Oct-09 20:55
Iain Clarke, Warrior Programmer11-Oct-09 20:55 

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.