Hello all,

Well I´m learning how wdm drivers work and reading Walter Oney´s book,
I was testing the driver and I can create a handle to the driver
normaly but when I try to read or to write to the driver I receive an
error.
an the getlasterror function returns me 1 (Incorrect function).
I have already added the driver into the system with the inf file.
What it is missing? or what could be the mistake?

HANDLE hdevice = CreateFile("\\\\.\\piofake"/, GENERIC_READ |
GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hdevice == INVALID_HANDLE_VALUE)
{
printf("Can't open PIOFAKE device - %d\n", GetLastError());
return 1;
}

// Read what's left in buffer
DWORD TxdBytes;
char *Rvalue;
Rvalue = new char[10];
if( !ReadFile(hdevice, &Rvalue, 3, &TxdBytes, NULL) )
{
printf("Could not read value %d\n", GetLastError());
}

Re: WDM driver for WinXP writefile and readfile error by Tim

Tim
Thu Oct 14 03:12:43 CDT 2004

xirueel@hotmail.com (Felisberto Coimbra) wrote:
>
>Well I´m learning how wdm drivers work and reading Walter Oney´s book,
>I was testing the driver and I can create a handle to the driver
>normaly but when I try to read or to write to the driver I receive an
>error.
>an the getlasterror function returns me 1 (Incorrect function).
>I have already added the driver into the system with the inf file.
>What it is missing? or what could be the mistake?

ReadFile goes almost directly to the IRP_MJ_READ handler in your driver.

Have you implemented such a handler? Many sample drivers only implement an
ioctl handler.

I believe user-mode error 1 maps to an NTSTATUS of
STATUS_INVALID_PARAMETER. Does your ReadFile function validate its
parameters in any way? Does it ever return STATUS_INVALID_PARAMETER?
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.