Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After this line:</p> <pre><code>SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL; </code></pre> <p>Add this:</p> <pre><code>DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256; pDetData = (_SP_DEVICE_INTERFACE_DETAIL_DATA_A*) malloc (dwDetDataSize); pDetData-&gt;cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA); </code></pre> <p>After this line:</p> <pre><code>qDebug ()&lt;&lt;pDetData-&gt;DevicePath; </code></pre> <p>Add this:</p> <pre><code>free(pDetData); </code></pre> <p>But eventually you're going to have to read the docs for <a href="http://msdn.microsoft.com/en-us/library/ff551120%28VS.85%29.aspx" rel="nofollow noreferrer"><code>SetupDiGetDeviceInterfaceDetail()</code></a>. Do it, there are lots of functions that work like this, with pointers to variable-size structs.</p> <p><strong>-------- Edited to add: --------</strong></p> <p>You're really going about this the wrong way. I see you're following the advice you got <a href="http://www.qtcentre.org/threads/31090-How-to-get-vendor-id-and-product-id-of-a-USB-device-on-windows-system" rel="nofollow noreferrer">here</a>, and it's taken you down the wrong path. <code>idVendor</code> and <code>idProduct</code> can only be found in the <code>USB_DEVICE_DESCRIPTOR</code> (<a href="http://msdn.microsoft.com/en-us/library/ff539280.aspx" rel="nofollow noreferrer">MSDN</a>).</p> <p>It looks like you already know how to get the device handle (using <code>CreateFile()</code>). After that, you call <code>WinUsb_Initialize()</code> (<a href="http://msdn.microsoft.com/en-us/library/ff540277.aspx" rel="nofollow noreferrer">MSDN</a>). That gets you a <code>WINUSB_INTERFACE_HANDLE</code>.</p> <p>Once you have that handle, you want to call <code>WinUsb_GetDescriptor()</code> (<a href="http://msdn.microsoft.com/en-us/library/ff540257.aspx" rel="nofollow noreferrer">MSDN</a>), with the <code>DescriptorType</code> set to <code>URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE</code>. I can't test code now, but it will look something like this:</p> <pre><code>USB_DEVICE_DESCRIPTOR udd; memset(&amp;udd, 0, sizeof(udd)); ULONG LengthTransferred = 0; WinUsb_GetDescriptor( winusb_interface_handle, // returned by WinUsbInitialize URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE, 0, // not sure if we need this 0x409, // not sure if we need this &amp;udd, sizeof(udd), &amp;LengthTransferred); </code></pre> <p>After that, <code>udd-&gt;idVendor</code> and <code>udd-&gt;idProduct</code> should have what you want.</p> <p>Microsoft used to supply sample code for all this in the DDK, and probably still does, but I don't have access to one.</p> <p><strong>---------- Edited to add: ----------</strong></p> <p>Daniel K writes that the code should really be:</p> <pre><code>USB_DEVICE_DESCRIPTOR udd; memset(&amp;udd, 0, sizeof(udd)); ULONG LengthTransferred = 0; WinUsb_GetDescriptor( winusb_interface_handle, // returned by WinUsbInitialize USB_DEVICE_DESCRIPTOR_TYPE, // Daniel K's suggestion 0, 0x409, // asks for English &amp;udd, sizeof(udd), &amp;LengthTransferred); </code></pre> <p>See the comments for further details.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload