SCAN FUNCTIONS

High Level Code generation in C, C++, Visual C++
scan devices compiled with Visual Studio 2010


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;
}
scan devices compiled with Visual Studio 2010



insert one line to filter out COMPORTS
   if(strstr(cMyBuf,"COM"))                 // <<====== Filter only COMPORTS
        m_ctrListbox.AddString(cMyBuf);
scan open windows compiled with Visual Studio 2010