title: Unique Identifier for Mouse,Keyboard and other HID devices
body: <p>I have an MFC application that used to find the details of devices in the windows. The PnPID of USB Storage devices is unique in every system. but in the case of mouse-keyboard, the PnPID is different on every computer for the same device. is there is any way to find the unique identifier of Mouse, Keyboard, and HID using C++. If anyone knows about the unique identifier for HID devices or mouse and keyboard please share.Here is my code.</p>
  
  <pre><code>while(SetupDiEnumDeviceInfo(hDevInfo,lCount++,&amp;DevInfoData))
          {
              ///////////////////////////////////////
              DWORD   dwDataTypeHardwareid;
              LPTSTR  pszBufferHardwareid     = NULL;
              LPTSTR  pszBufferPnPid      = NULL;
              DWORD   dwBuffSizeHardwareid    = 0; 
              int     iRetValHardwareid       = 1;
              ///////////////////////////////////////
              iRetValHardwareid = SetupDiGetDeviceRegistryProperty(hDevInfo, &amp;DevInfoData, SPDRP_HARDWAREID, &amp;dwDataTypeHardwareid, (PBYTE)pszBufferHardwareid, dwBuffSizeHardwareid, &amp;dwBuffSizeHardwareid);
              DWORD dwErr = GetLastError();
  
              if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
              {
                  if (pszBufferHardwareid) 
                      LocalFree(pszBufferHardwareid);
                  //// / //
                  pszBufferHardwareid = (char *)LocalAlloc(LPTR,dwBuffSizeHardwareid * 2);
                  iRetValHardwareid=SetupDiGetDeviceRegistryProperty(hDevInfo, &amp;DevInfoData, SPDRP_HARDWAREID, &amp;dwDataTypeHardwareid, (PBYTE)pszBufferHardwareid, dwBuffSizeHardwareid, &amp;dwBuffSizeHardwareid);
              }       
              if(StrStrI(pszBufferHardwareid,"HID\\"))
              {
                  if(StrStrI(pszBufferClass,"Mouse"))
                  {
                      CM_Get_Device_ID(DevInfoData.DevInst, pszBufferPnPid, MAX_PATH, 0); //**Not unique in different machines**
                      CString strDevid = (CString)pszBufferPnPid;
                      strDevid.Trim();
                      strDevid.MakeUpper();
                      SaveDeviceDetails(strDevid); //Method to save device details to DB
                  }
              }
          }
  </code></pre>