Tech Support > Microsoft Windows > Drivers > Question Reguarding Handles
Question Reguarding Handles
Posted by Flash on March 1st, 2008


Hello I made a simple driver to practice using IoControl between my usermode
program and driver. My problem is, when I try opening a file handle from my
usermode program, it always returns INVALID_HANDLE_VALUE (-1). This is my
code for initializing the device:

RtlInitUnicodeString(&DeviceName, L"\\Device\\Test");
status = IoCreateDevice(pDriverObject, 0, &DeviceName, FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN, FALSE, &pDeviceObject);

So, if I assume correctly, it creates a the device object in <path to
driver>\Device\Test ? This is the path I have been trying to get the handle
from.
I put my usermode application in the same directory as the driver, and call:

HANDLE hDevice = CreateFile(L"\\Device\\Test", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

This always returns invalid even when my driver is running. Thank your for
any help you can provide.

Posted by Sasha Bublyk on March 1st, 2008


Look at symbolic links - function IoCreateSymbolicLink.

----
Sasha Bublyk
www.sycorelogic.com


"Flash" <Flash@discussions.microsoft.com> повідомив/повідомила в
news:43DAD6EE-38ED-480E-BA49-9694C875DFE2@microsoft.com...

Posted by Don Burn on March 1st, 2008


You are missing a few things here. Devices is not win32 accessible, to have
a name a program can access you needt to create a symbolic linke for the
form \\DosDevices\\Test using IoCreateSymbolicLink. In the application you
open "\\\\.\\Test" as the device name

You should take a look at the src\geneal\ioctl sample in the current WDK.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"Flash" <Flash@discussions.microsoft.com> wrote in message
news:43DAD6EE-38ED-480E-BA49-9694C875DFE2@microsoft.com...


Posted by Flash on March 1st, 2008


If I use symbolic links, when I do CreateFile() can I use "\\\\.\\Test" as
the directory reguardless of the path to the driver?

"Don Burn" wrote:

Posted by David Craig on March 1st, 2008


Look at the sample Don mentions. Use the app and driver in the documented
way and see how it works. We are not going to write it for you unless you
pay one of the consultants such as Don to do so.

"Flash" <Flash@discussions.microsoft.com> wrote in message
news:19ED9E47-26EE-469F-BBDD-D63A13F05196@microsoft.com...


Posted by Flash on March 2nd, 2008


I never asked for you to write it for me, but anyway I got it working so
thanks.

"David Craig" wrote: