Hi,
I have a USB device which i connect to with CreateFile() through an USB WDM
interrupt driver. I later use WriteFile() on the same handle. This software
and hardware combination works on probably more than 99% of the different
PC's used but a few have a problem on Windows XP (maybe other OS too).
I sent them a debug output version of the application which shows that
WriteFile() fails with GetLastError = 87 "The parameter is incorrect",
CreateFile() succeeds, i am trying to write 1 byte, it writes 0 bytes,
returns false and then lasterror is 87. I have made the debug application
output all of the parameters and it shows that the handle to the device is
the same as createfile returned, the buffer is valid, the content of the
buffer (1 byte) is valid. Im using non-overlapped io so the last parameter
is null and all parameters should be correct.
Why is the error 'incorrect parameter'?
So any clues what is going wrong? I suspect the USB communication to be
causing it, but how can the device be connected correctly then.
Source example below:
unsigned char sendbuf[10];
DWORD dwBytesWritten;
BOOL res;
HANDLE hDevice = CreateFile(\\\\.\\MyDevice,GENERIC_READ |
GENERIC_WRITE,0,0, OPEN_EXISTING,0,0);
if (hDevice == INVALID_HANDLE_VALUE) return -1;
sendbuf[0] = 2;
res = WriteFile(hDevice,sendbuf,1,&dwBytesWritten,0);
At this point res = 0, dwBytesWritten = 0 and GetLastError reports error 87
Best regards,
Martin