Createfile error

I am trying some basic IOCTL work and have created a hello world type driver that compiles ok. I load the driver using the tool from this site, and when I try my user mode code to execute the createfile api it returns an INVALID_HANDLE error eg -1.
getlasterror returns 2. I have checked in driver loader and I can see the driver in the active services list. What am I doing wrong?

Thanks in advance

A Noob

How do you call createfile ?
Dump code

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.uk
Sent: Friday, September 19, 2008 3:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Createfile error

I am trying some basic IOCTL work and have created a hello world type driver
that compiles ok. I load the driver using the tool from this site, and when
I try my user mode code to execute the createfile api it returns an
INVALID_HANDLE error eg -1.
getlasterror returns 2. I have checked in driver loader and I can see the
driver in the active services list. What am I doing wrong?

Thanks in advance

A Noob


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

hDevice = CreateFile("\\.\Simplesys,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

I have notices if I use the path

\.\Simplesys although I get a compile warning “Invalid escape sequence ‘\S’” the function now returns a positive integer, 28.

Cancel that. Function returns 28, getlasterror returns file not found.
With \\.\Simplesys I get getlasterror returns 2

  1. desired access should not be write
  2. create disposition OPEN_EXISTING not create always
  3. always share at least FILE_SHARE_WRITE

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.uk
Sent: Friday, September 19, 2008 3:47 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Createfile error

hDevice = CreateFile("\\.\Simplesys,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

I have notices if I use the path

\.\Simplesys although I get a compile warning “Invalid escape sequence
‘\S’” the function now returns a positive integer, 28.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

PS: Read MSDN

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.uk
Sent: Friday, September 19, 2008 3:47 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Createfile error

hDevice = CreateFile("\\.\Simplesys,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

I have notices if I use the path

\.\Simplesys although I get a compile warning “Invalid escape sequence
‘\S’” the function now returns a positive integer, 28.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>>PS: Read MSDN

No need for that. I have done. There is no suggestion of how to implement, rather only a specification of the function. You’ll be glad to know I have created a symbollic link before trying this, with knowlege gained from reading the MSDN. I came here because I was stuck.

>>1) desired access should not be write

Is this the case? I need to write to send IRP do I not?

The desired access should match the operation that you intend to do. If you
send an ioctl that requires write access or call the WriteFile function then
the desired access should include FILE_WRITE.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 19, 2008 8:58 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Createfile error

>1) desired access should not be write

Is this the case? I need to write to send IRP do I not?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Is that not what I have done?

hDevice = CreateFile("\\.\Simplesys, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

How do you make sure that your link and driver is working correctly? check your device name created correct using winobj.exe.

Good idea. I will do that.

>hDevice = CreateFile("\\.\Simplesys, GENERIC_READ | GENERIC_WRITE, 0, NULL,

CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

Did you check that warning? Please check the code.Anything missing. First remove that warning.

Yes I did. I have to escape the 's so what I have put there is correct. As I say, getlasterror returns 2, which I think the MSDN suggests is FILE_NOT_FOUND. I did lift some code from the DDK, and just changed the filenames so I am a bit stumped as they are spelt correctly and using the correct case. I will try winobj.exe but don’t hold out much hope as it is spelt correctly.

Thanks

Did you implement a IRP_MJ_CREATE dispatch routine?

d

-----Original Message-----
From: “xxxxx@yahoo.co.uk
To: “Windows System Software Devs Interest List”
Sent: 09/19/08 5:46 AM
Subject: RE:[ntdev] Createfile error

hDevice = CreateFile("\\.\Simplesys,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

I have notices if I use the path

\.\Simplesys although I get a compile warning “Invalid escape sequence ‘\S’” the function now returns a positive integer, 28.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

No. Just DriverLoad, DriverUnload.

I put an L infront of the path string, and now it gives ERROR_PATH_NOT_FOUND. I also changed the 4th parameter to OPEN_EXISTING.

At 16:27 19/09/2008, xxxxx@yahoo.co.uk wrote:

No. Just DriverLoad, DriverUnload.

I put an L infront of the path string, and now it gives
ERROR_PATH_NOT_FOUND. I also changed the 4th parameter to OPEN_EXISTING.

Then Doran’s question is highly relevant. You need a minimum of an
IRP_MJ_CREATE and an IRP_MJ_CLOSE dispatch routines in your driver
for it to do anything. CreateFile calls the create dispatch routine
and the subsequent CloseHandle calls the close dispatch routine.

What you seem to have at the moment is a driver with no useful entry points.

Mark.

You can not open the device if the driver does not support the create IRP.
There is a simple sample in the WDK that you should be using as a starting
point.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of xxxxx@yahoo.co.uk
Sent: Friday, September 19, 2008 11:28 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Createfile error

No. Just DriverLoad, DriverUnload.

I put an L infront of the path string, and now it gives
ERROR_PATH_NOT_FOUND. I also changed the 4th parameter to OPEN_EXISTING.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Expanding on what you’ve already been told (correctly)… You should note that your create/close dispatch entry points can be as “useful” as:

{
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, 0);
return(STATUS_SUCCESS);
}

In fact… this is probably the most common form of create/close processing done for drivers of physical hardware devices.

Peter
OSR

> hDevice = CreateFile("\\.\Simplesys,

GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

I have notices if I use the path

\.\Simplesys although I get a compile warning “Invalid escape sequence
‘\S’” the function now returns a positive integer, 28.

  1. Obviously, if you used \.\Simplesys, you will get warning C4129,
    because ‘\S’ doesn’t exist in Escape Sequence.
  2. You should use OPEN_EXISTING instead of CREATE_ALWAYS in CreateFile.
  3. You had gotten 2 with GetLastError, which means application can’t find
    your file name. so you should check your driver, do you create the relevant
    symbolic name correctly?