Open device name with CreateFile

I am working on a simple device driver that I want to connect to the driver from user mode using IRP.

I have problems opening the device driver. Using DeviceTree , I can see the name of the device, for example, \ Device \ MyDevice.

But when I try to open it like this:

hand := CreateFile('\Device\MyDevice', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 

I always get INVALID_HANDLE_VALUE and GetLastError (the system cannot find the path specified)

What am I doing wrong? I know that the driver works because I see it working and printing in DebugView. So any tips?

enter image description here

+8
windows winapi driver
source share
1 answer

Here is a good explanation of Tim Robinson's MVP (Windows SDK) :

The form names \Device\xxx are internal NT object manager names that are not available for Win32. You can access your device only if it creates a symbolic link to \Device\MyDevice from the \??\ directory. Objects in the kernel directory \??\ displayed through \\.\ In Win32. Use Winobj in the DDK (or download it from www.sysinternals.com) to verify.

NOTE : Currently, the root of the NT namespace is provided via the GLOBALROOT symbolic link, so any NT path is accessible to Win32, including \Device\xxx : use \\.\GLOBALROOT\Device\xxx . In this case, a symbolic link to the device is not required.

+10
source share

All Articles