A
A
Alexey Skahin2011-07-06 14:33:41
C++ / C#
Alexey Skahin, 2011-07-06 14:33:41

Working with a USB device?

I have a code that returns a list of USB devices, with physical paths obtained by the SetupDiGetInterfaceDeviceDetail function.
Devices connected: webcam, mouse, barcode scanner, flash drive.
Physical addresses are normally obtained, devices open at these addresses without errors.
But then, I can’t read anything from these devices
The full code is here: files.pihel.jino.ru/files/2e6d893fe1333553bfdd30d7...
This part is of particular interest:

while(1) {<br/>
memset(inBuffer, 0, 2);<br/>
bResult = ReadFile(hUsbLink,inBuffer, 1,&readed,&ovl_wht);<br/>
if (bResult) {<br/>
_tprintf(TEXT(&quot;%s&quot;), inBuffer);<br/>
strcat(sBuffer, inBuffer);<br/>
} else {<br/>
le = GetLastError();<br/>
printf(&quot;error code: %u &quot;, le);<br/>
}<br/>
}<br/>

I always get error #1 (ERROR_INVALID_FUNCTION)
How can I read something from these devices?
Why do I always get the error...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kostik450, 2011-07-06
@kostik450

I had the same error when the buffer size was not a multiple of 512 bytes when working with a hard drive (sector size).
"Play around" with the buffer size - it's probably a multiple of 64 bytes, or something like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question