Click here to Skip to main content
13,000,179 members (64,718 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: , +
I want to filter imaging devices(Logiteck Camera etc in system present) like com port.
My code is
int CWin2Dlg::ScanAll(void)
{
	SP_DEVINFO_DATA			devInfo;
	HDEVINFO			devs;
	DWORD   devIndex=0,		nr;
	char				cMyBuf[512];
   devs    = SetupDiGetClassDevs(0, 0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES | DIGCF_PROFILE );
	if(devs == INVALID_HANDLE_VALUE) return(-1);
	devInfo.cbSize = sizeof(devInfo);
	for(devIndex = 0; SetupDiEnumDeviceInfo(devs, devIndex, &devInfo); devIndex++)
	{
		memset(cMyBuf,0,sizeof(cMyBuf));
		SetupDiGetDeviceRegistryPropertyA(devs, &devInfo, SPDRP_FRIENDLYNAME, 0, (BYTE*)cMyBuf, sizeof(cMyBuf), &nr);
		//if(strlen(cMyBuf) != NULL)
		if(strstr(cMyBuf,"COM"))      // <<====== Filter only COMPORTS
			pComboBox.AddString(cMyBuf);
	}
 
	SetupDiDestroyDeviceInfoList(devs);
	return 0;
}
Posted 18-Dec-12 0:29am
Updated 18-Dec-12 0:38am
v2
Comments
Richard MacCutchan 18-Dec-12 6:51am
   
OK, what's your question?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You did not tell us the problem. But with SetupDiEnumDeviceInfo(), you must check the return value and call GetLastError() to detect when no more items are available:
BOOL bResult = TRUE; // (devs != INVALID_HANDLE_VALUE);
while (bResult)
{
    bResult = SetupDiEnumDeviceInfo(devs, devIndex++, &devInfo);
    if (!bResult)
    {
        if (ERROR_NO_MORE_ITEMS == GetLastError())
            bResult = TRUE;
        break;
    }
    // get property here
}

To check for specific device types, you must pass a GUID to SetupDiGetClassDevs():
const GUID GUID_DEVINTERFACE_IMAGING = { 
    0x6bdd1fc6, 0x810f, 0x11d0, { 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f }
};
devs = SetupDiGetClassDevs(&GUID_DEVINTERFACE_IMAGING, 0, 0, DIGCF_PRESENT | DIGCF_INTERFACE | DIGCF_PROFILE );

See System-Defined Device Setup Classes Available[^] in the MSDN for GUIDs.
  Permalink  
Comments
Member 7909353 18-Dec-12 23:35pm
   
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100