Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to filter imaging devices(Logiteck Camera etc in system present) like com port.
My code is
C++
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
Updated 18-Dec-12 0:38am
v2
Comments
Richard MacCutchan 18-Dec-12 6:51am    
OK, what's your question?

1 solution

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:
C++
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():
C++
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.
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900