title: How can I find out what is wrong with a SetupDiGetClassDev interface in C#?
body: <p>How do I find out what's wrong with the device info set returned? I'm re-writing my code again and I'm still hitting the same stumbling block.</p>
  
  <pre><code>deviceInfoSet = SetupDiGetClassDevs(ref tGuid, 0, IntPtr.Zero, (uint)SetupDiFlags.DIGCF_PRESENT );
  if (deviceInfoSet.ToInt32() == INVALID_DEVICE_HANDLE)
  {
     int errCode = Marshal.GetLastWin32Error();
     errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
     statusLabel.Text += "Invalid deviceinfoset returned: " + errCode + " =&gt; " + errorMessage + ".";
  }
  </code></pre>
  
  <p>The above code doesn't cause any errors but when I use the code below:</p>
  
  <pre><code>result = true;
  while (result)
  {
      result = SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref tGuid, Index, ref anInterface);
      if (!result)
      {
          int errCode = Marshal.GetLastWin32Error();
          errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
          statusLabel.Text += "\nSetDiEnumDeviceInterface Error: " + errCode + " =&gt; " + errorMessage + ".";
          break;
      }
      Index++;
  }
  </code></pre>
  
  <p>to try and access the device info set list, error code 259 (<strong>No more data is available</strong>) is returned. I am at a loss as to what I'm doing wrong.</p>