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?
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?
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.
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.
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.
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.
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.
\.\Simplesys although I get a compile warning “Invalid escape sequence
‘\S’” the function now returns a positive integer, 28.
Obviously, if you used \.\Simplesys, you will get warning C4129,
because ‘\S’ doesn’t exist in Escape Sequence.
You should use OPEN_EXISTING instead of CREATE_ALWAYS in CreateFile.
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?