title: Finding USB comport numbers using VID,PID,+SN
body: <p>I am looking for example code in ansi c/c++ that will find usb devices by their pid/vid/sn# and then find the associated comport number.  I have multiple FTDI usb serial ports connected to a pc and need to identify each port by the known SN#.  This code I found will display the HWID info but how do I use it to get the comport number?  Here is a response to the below code for one of the devices: USB\VID_0403&amp;PID_6001\FTAME7HK
  Are there an online tutorial that runs through examples for this type of code?</p>
  
  <pre><code>    #include &lt;windows.h&gt; 
      #include &lt;ansi_c.h&gt;
      #include &lt;Setupapi.h&gt;
      #include &lt;devguid.h&gt;
      #include &lt;Setupapi.h&gt;
      HDEVINFO deviceInfoSet;
      GUID *guidDev = (GUID*) &amp;GUID_DEVCLASS_USB; 
      TCHAR buffer [4000];
      DWORD buffersize =4000;
      int memberIndex = 0;
      main()
      {
      deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);   
      while (TRUE) {
      SP_DEVINFO_DATA deviceInfoData;
      ZeroMemory(&amp;deviceInfoData, sizeof(SP_DEVINFO_DATA));
      deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
      if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &amp;deviceInfoData) == FALSE) {
        if (GetLastError() == ERROR_NO_MORE_ITEMS)
          {
          break;
          }
     }
     DWORD nSize=0 ;
     SetupDiGetDeviceInstanceId (deviceInfoSet, &amp;deviceInfoData, buffer, sizeof(buffer), &amp;nSize);
     buffer [nSize] ='\0';
     printf ("%s\n", buffer);
     memberIndex++;
     }
     if (deviceInfoSet) {
     SetupDiDestroyDeviceInfoList(deviceInfoSet);
     }
     getchar();
     return 0;    
     }
  </code></pre>