I’m learing about device driver development. What’s wrong in this? I’m unable to open a device created by my test driver?
Thanks
-Matt
DRIVER
WCHAR deviceNameBuffer = L"\Device\SVCTABLEXT";
UNICODE_STRING deviceNameUnicodeString;
WCHAR deviceLinkBuffer = L"\DosDevices\SVCTABLEXT";
UNICODE_STRING deviceLinkUnicodeString;
DbgPrint(“==> DriveEntry (SVCTABLEXT Driver)\n”);
RtlInitUnicodeString (
&deviceNameUnicodeString,
deviceNameBuffer
);
ntStatus = IoCreateDevice (
DriverObject,
0,
&deviceNameUnicodeString,
FILE_DEVICE_SVCTABLE,
0,
TRUE,
&deviceObject
);
if (NT_SUCCESS(ntStatus))
{
RtlInitUnicodeString (
&deviceLinkUnicodeString,
deviceLinkBuffer
);
ntStatus = IoCreateSymbolicLink (
&deviceLinkUnicodeString,
&deviceNameUnicodeString
);
if (!NT_SUCCESS(ntStatus))
{
DbgPrint(“Symbolic link creation failed\n”);
}
APPLICATION
hDevice =
CreateFile(
DEVICE_NAME,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (hDevice == (HANDLE) -1)
{
printf(“Error when opening device\n”);
exit(0);
}
I think you have to use the following as your device name in your test code
to open it:
#define DEVICE_NAME \\.\SVCTABLEXT1
I usually define deviceNameUnicodeString as L"
<file:> \Device\SVCTABLEXT0" and
deviceLinkUnicodeString as L" \DosDevices\SVCTABLEXT1
<file:> “. I don’t know why, but that works fine.
Z.S.Wang
WCHAR deviceNameBuffer = L”\Device\SVCTABLEXT";
UNICODE_STRING deviceNameUnicodeString;
WCHAR deviceLinkBuffer =
L"\DosDevices\SVCTABLEXT";
UNICODE_STRING deviceLinkUnicodeString;
DbgPrint(“==> DriveEntry (SVCTABLEXT Driver)\n”);
RtlInitUnicodeString (
&deviceNameUnicodeString,
deviceNameBuffer
);
ntStatus = IoCreateDevice (
DriverObject,
0,
&deviceNameUnicodeString,
FILE_DEVICE_SVCTABLE,
0,
TRUE,
&deviceObject
);
if (NT_SUCCESS(ntStatus))
{
RtlInitUnicodeString (
&deviceLinkUnicodeString,
deviceLinkBuffer
);
ntStatus = IoCreateSymbolicLink (
&deviceLinkUnicodeString,
&deviceNameUnicodeString
);
if (!NT_SUCCESS(ntStatus))
{
DbgPrint(“Symbolic link creation failed\n”);
}
APPLICATION
hDevice =
CreateFile(
DEVICE_NAME,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (hDevice == (HANDLE) -1)
{
printf(“Error when opening device\n”);
exit(0);
}</file:></file:>
Thanks. Problem solved… I was accessing from a terminal server and needed
to open the Device using \.\Global\DEVICENAME
-Matt
----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Tuesday, October 24, 2000 7:42 PM
Subject: [ntdev] RE: error opening a device
> I think you have to use the following as your device name in your test
code
> to open it:
>
> #define DEVICE_NAME \\.\SVCTABLEXT1
>
> I usually define deviceNameUnicodeString as L"
> <file:> \Device\SVCTABLEXT0" and
> deviceLinkUnicodeString as L" \DosDevices\SVCTABLEXT1
> <file:> “. I don’t know why, but that works
fine.
>
> Z.S.Wang
>
>
> WCHAR deviceNameBuffer = L”\Device\SVCTABLEXT";
> UNICODE_STRING deviceNameUnicodeString;
> WCHAR deviceLinkBuffer =
> L"\DosDevices\SVCTABLEXT";
> UNICODE_STRING deviceLinkUnicodeString;
>
> DbgPrint(“==> DriveEntry (SVCTABLEXT Driver)\n”);
>
> RtlInitUnicodeString (
> &deviceNameUnicodeString,
> deviceNameBuffer
> );
>
> ntStatus = IoCreateDevice (
> DriverObject,
> 0,
> &deviceNameUnicodeString,
> FILE_DEVICE_SVCTABLE,
> 0,
> TRUE,
> &deviceObject
> );
>
> if (NT_SUCCESS(ntStatus))
> {
> RtlInitUnicodeString (
> &deviceLinkUnicodeString,
> deviceLinkBuffer
> );
>
> ntStatus = IoCreateSymbolicLink (
> &deviceLinkUnicodeString,
> &deviceNameUnicodeString
> );
>
> if (!NT_SUCCESS(ntStatus))
> {
> DbgPrint(“Symbolic link creation failed\n”);
> }
>
>
>
> APPLICATION
>
>
> hDevice =
> CreateFile(
> DEVICE_NAME,
> GENERIC_READ | GENERIC_WRITE,
> 0,
> NULL,
> OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL,
> NULL
> );
>
> if (hDevice == (HANDLE) -1)
> {
> printf(“Error when opening device\n”);
> exit(0);
> }
>
>
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@dolce.it
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
></file:></file:>