|
|
SCAN FUNCTIONS |
High Level Code generation in C, C++, Visual C++ |
1 scan devices and display into a listbox
ScanDevices01 download source ScanDevices01 download exe 1 scan devices: view only COMPORTS ScanDevices02 download source ScanDevices02 download exe 1 scan open windows ScanDevices02 download source ScanDevices02 download exe feedback or questions:orgler@tin.it |
Create your own MFC Dialog Project or copy the source insert on the top a few lines and add the function ScanAll #include "Setupapi.h" #pragma comment(lib, "Setupapi.lib") int CScanDevicesDlg::ScanAll(void) { SP_DEVINFO_DATA devInfo; HDEVINFO devs; DWORD devIndex, 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)); SetupDiGetDeviceRegistryProperty(devs, &devInfo, SPDRP_FRIENDLYNAME, 0, (BYTE*)cMyBuf, sizeof(cMyBuf), &nr); if(strlen(cMyBuf) != NULL) m_ctrListbox.AddString(cMyBuf); } SetupDiDestroyDeviceInfoList(devs); return 0; } insert one line to filter out COMPORTS if(strstr(cMyBuf,"COM")) // <<====== Filter only COMPORTS m_ctrListbox.AddString(cMyBuf); |