Tech Support > Microsoft Windows > Development Resources > WriteFile fails on few systems
WriteFile fails on few systems
Posted by Martin on August 5th, 2004


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




Posted by Sten Westerback on August 6th, 2004



"Martin" <ingen@overhovedetxyz.dk> wrote in message
news:ceu9md$rka$1@news.cybercity.dk...
I would suspect that too. It's totally possible that a faulty driver claims
"yes, you are now connected to the device" but then when you try to
write to it then it realises that it some of the drivers internal structures
are corrupt so that it can't actually write anything.

Another possibility would be some changes in XP
but i can't see any XP related comments in CreateFile
docs that wouldn't apply also to Win2k and Win2k3.

I assume you forgot to type " " in the news article...
Maybe CREATE_ALWAYS would work better?

Instead of 0 i would recommend NULL.

- Sten





Similar Posts