newbies question

Hello all,

I’m a complete newbie with windows driver development and I’ve been attempting to make a simple driver to attach onto the keyboard stack (final goal is to make the lights flash) but I seem to have gotten stuck. My driver attaches to the stack which I can see in devicetree and my status is always 0. After creating the device and obtaining the target device the pointers are non null so I’m assuming that those are correct.

The problem I encounter is that when I press a button it works the first time, and then the keyboard stops working.I would have assumed that since I’ve set all of my major functions to pass that it should have been called when the button was pressed but its not printing anything like it should be if it were being called.

Since this is an assignment I’m hoping people here could give me some tips rather than stating what the problem is? Heres the code with a few pieces removed (sorry for all the debugging).

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;

DbgPrint(“Hello from driver1!\n”);

UNICODE_STRING filteredDeviceName;
RtlInitUnicodeString(&filteredDeviceName, L"\Device\KeyboardClass0");

PDEVICE_OBJECT target_device = NULL;
PDEVICE_OBJECT my_device = NULL;
DbgPrint(“%d\n”, status);
DbgPrint(“running 1\n”);

status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &my_device);
DbgPrint(“%d\n”, status);
P_DEVICE_EXTENSION ext = (P_DEVICE_EXTENSION) (my_device -> DeviceExtension);
status = IoAttachDevice(my_device, &filteredDeviceName, &(ext -> TargetDeviceObject));
DbgPrint(“%d\n”, status);

unsigned i;
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
DbgPrint(“adding handler for %d\n”, i);
DriverObject->MajorFunction[i] = pass;

DriverObject->DriverUnload = unload;
DriverObject->DriverStartIo = NULL;
DriverObject->DriverExtension->AddDevice = addDevice;
DriverObject->DeviceObject = my_device;

ext -> DeviceObject = my_device;

DbgPrint(“%p\n”, my_device);
DbgPrint(“%p\n”, ext -> TargetDeviceObject);
DbgPrint(“%d\n”, status);
DbgPrint(“%d\n”, STATUS_SUCCESS);

return status;
}

void unload(IN PDRIVER_OBJECT DriverObject)
{
IoDeleteDevice(DriverObject->DeviceObject);
DbgPrint(“Goodbye from driver1!\n”);
}

NTSTATUS pass(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
DbgPrint(“passing\n”);
P_DEVICE_EXTENSION deviceExtension = NULL;

IoSkipCurrentIrpStackLocation(Irp);
deviceExtension = (P_DEVICE_EXTENSION) DeviceObject->DeviceExtension;

return IoCallDriver(deviceExtension->TargetDeviceObject, Irp);
}
Thanks in advance.

Did you get this code from ctrl2cap? Throw it away. Start with the kbfiltr example which properly attaches through pnp

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?4/?4/?2013 3:52 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] newbies question

Hello all,

I’m a complete newbie with windows driver development and I’ve been attempting to make a simple driver to attach onto the keyboard stack (final goal is to make the lights flash) but I seem to have gotten stuck. My driver attaches to the stack which I can see in devicetree and my status is always 0. After creating the device and obtaining the target device the pointers are non null so I’m assuming that those are correct.

The problem I encounter is that when I press a button it works the first time, and then the keyboard stops working.I would have assumed that since I’ve set all of my major functions to pass that it should have been called when the button was pressed but its not printing anything like it should be if it were being called.

Since this is an assignment I’m hoping people here could give me some tips rather than stating what the problem is? Heres the code with a few pieces removed (sorry for all the debugging).

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;

DbgPrint(“Hello from driver1!\n”);

UNICODE_STRING filteredDeviceName;
RtlInitUnicodeString(&filteredDeviceName, L"\Device\KeyboardClass0<file:>“);

PDEVICE_OBJECT target_device = NULL;
PDEVICE_OBJECT my_device = NULL;
DbgPrint(”%d\n", status);
DbgPrint(“running 1\n”);

status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &my_device);
DbgPrint(“%d\n”, status);
P_DEVICE_EXTENSION ext = (P_DEVICE_EXTENSION) (my_device -> DeviceExtension);
status = IoAttachDevice(my_device, &filteredDeviceName, &(ext -> TargetDeviceObject));
DbgPrint(“%d\n”, status);

unsigned i;
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
DbgPrint(“adding handler for %d\n”, i);
DriverObject->MajorFunction[i] = pass;

DriverObject->DriverUnload = unload;
DriverObject->DriverStartIo = NULL;
DriverObject->DriverExtension->AddDevice = addDevice;
DriverObject->DeviceObject = my_device;

ext -> DeviceObject = my_device;

DbgPrint(“%p\n”, my_device);
DbgPrint(“%p\n”, ext -> TargetDeviceObject);
DbgPrint(“%d\n”, status);
DbgPrint(“%d\n”, STATUS_SUCCESS);

return status;
}

void unload(IN PDRIVER_OBJECT DriverObject)
{
IoDeleteDevice(DriverObject->DeviceObject);
DbgPrint(“Goodbye from driver1!\n”);
}

NTSTATUS pass(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
DbgPrint(“passing\n”);
P_DEVICE_EXTENSION deviceExtension = NULL;

IoSkipCurrentIrpStackLocation(Irp);
deviceExtension = (P_DEVICE_EXTENSION) DeviceObject->DeviceExtension;

return IoCallDriver(deviceExtension->TargetDeviceObject, Irp);
}
Thanks in advance.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

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</file:></mailto:xxxxx></mailto:xxxxx>

no, I got it from visualddk’s template.

Regardless of where you got it, that code has no place in windows since windows 2000

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, April 04, 2013 5:09 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] newbies question

no, I got it from visualddk’s template.


NTDEV is sponsored by OSR

OSR is HIRING!! See http://www.osr.com/careers

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

> for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)

DbgPrint(“adding handler for %d\n”, i);
DriverObject->MajorFunction[i] = pass;

Unless there’s a copy-paste error, you are missing a pair of curlies there.
Rethink what your loop does.

On Thu, Apr 4, 2013 at 3:51 PM, wrote:

> Hello all,
>
> I’m a complete newbie with windows driver development and I’ve been
> attempting to make a simple driver to attach onto the keyboard stack (final
> goal is to make the lights flash) but I seem to have gotten stuck. My
> driver attaches to the stack which I can see in devicetree and my status is
> always 0. After creating the device and obtaining the target device the
> pointers are non null so I’m assuming that those are correct.
>
> The problem I encounter is that when I press a button it works the first
> time, and then the keyboard stops working.I would have assumed that since
> I’ve set all of my major functions to pass that it should have been called
> when the button was pressed but its not printing anything like it should be
> if it were being called.
>
> Since this is an assignment I’m hoping people here could give me some tips
> rather than stating what the problem is? Heres the code with a few pieces
> removed (sorry for all the debugging).
>
> NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING
> RegistryPath)
> {
> NTSTATUS status = STATUS_SUCCESS;
>
>
> DbgPrint(“Hello from driver1!\n”);
>
> UNICODE_STRING filteredDeviceName;
> RtlInitUnicodeString(&filteredDeviceName,
> L"\Device\KeyboardClass0");
>
> PDEVICE_OBJECT target_device = NULL;
> PDEVICE_OBJECT my_device = NULL;
> DbgPrint(“%d\n”, status);
> DbgPrint(“running 1\n”);
>
> status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION),
> NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &my_device);
> DbgPrint(“%d\n”, status);
> P_DEVICE_EXTENSION ext = (P_DEVICE_EXTENSION) (my_device ->
> DeviceExtension);
> status = IoAttachDevice(my_device, &filteredDeviceName, &(ext ->
> TargetDeviceObject));
> DbgPrint(“%d\n”, status);
>
> unsigned i;
> for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
> DbgPrint(“adding handler for %d\n”, i);
> DriverObject->MajorFunction[i] = pass;
>
> DriverObject->DriverUnload = unload;
> DriverObject->DriverStartIo = NULL;
> DriverObject->DriverExtension->AddDevice = addDevice;
> DriverObject->DeviceObject = my_device;
>
> ext -> DeviceObject = my_device;
>
> DbgPrint(“%p\n”, my_device);
> DbgPrint(“%p\n”, ext -> TargetDeviceObject);
> DbgPrint(“%d\n”, status);
> DbgPrint(“%d\n”, STATUS_SUCCESS);
>
> return status;
> }
>
> void unload(IN PDRIVER_OBJECT DriverObject)
> {
> IoDeleteDevice(DriverObject->DeviceObject);
> DbgPrint(“Goodbye from driver1!\n”);
> }
>
> NTSTATUS pass(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
> {
> DbgPrint(“passing\n”);
> P_DEVICE_EXTENSION deviceExtension = NULL;
>
> IoSkipCurrentIrpStackLocation(Irp);
> deviceExtension = (P_DEVICE_EXTENSION)
> DeviceObject->DeviceExtension;
>
> return IoCallDriver(deviceExtension->TargetDeviceObject, Irp);
> }
> Thanks in advance.
>
> —
> NTDEV is sponsored by OSR
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

What is “visual ddk”?

Try using KMDF provided with the WDK, this is the way to go for now.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> no, I got it from visualddk’s template.
>

On 05-Apr-2013 10:04, Maxim S. Shatskih wrote:

What is “visual ddk”?

http://visualddk.sysprogs.org/

A project that attempted to integrate the WDK build and kernel debugger
into Visual Studio, long before WDK8 and VS11.
Now it is probably obsolete, but they have other interesting things such
as “VisualGDB” and VS-based debugger for VirtualBox, similar to the
VMWare’s one.

– pa

It was obsolete for the full integration the day it was released. I
spent a couple of days tracking down problems for a client then a week
to convince them to junk it.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Pavel A.” wrote in message news:xxxxx@ntdev:

> On 05-Apr-2013 10:04, Maxim S. Shatskih wrote:
> > What is “visual ddk”?
> >
> http://visualddk.sysprogs.org/
>
> A project that attempted to integrate the WDK build and kernel debugger
> into Visual Studio, long before WDK8 and VS11.
> Now it is probably obsolete, but they have other interesting things such
> as “VisualGDB” and VS-based debugger for VirtualBox, similar to the
> VMWare’s one.
>
> – pa