Hi!
I need to write a driver that can disable keys when asked to (from user mode app) and managed to do that by modifying ctrl2cap, but now my problem is how to do the same with USB keyboards.
I searched this forum thoroughly and found that the kbfilter example (kmdf version) was the best place to start, but I can’t get it to run on XP. I have put it before kbdclass and it does something, because neither PS2 or USB keyboards works… In vista this does not happen and it seems to work, but why not on XP?
I hope you can point me to the right direction 
Just a guess, but if you aren’t using the coinstaller when installing your sample, then it will work on Vista [because KMDF is part of the Vista OS], but not an anything earlier [because the coinstaller is what will install KMDF on those OS when it is not already there].
-----Original Message-----
Hi!
I need to write a driver that can disable keys when asked to (from user mode app) and managed to do that by modifying ctrl2cap, but now my problem is how to do the same with USB keyboards.
I searched this forum thoroughly and found that the kbfilter example (kmdf version) was the best place to start, but I can’t get it to run on XP. I have put it before kbdclass and it does something, because neither PS2 or USB keyboards works… In vista this does not happen and it seems to work, but why not on XP?
I hope you can point me to the right direction 
Good guess, because I am not using it. Thank you!
You can use kbdfilter examle in XP DDK on 2K/XP.
Allen
Okay, I have my driver almost done, but I don’t know what I’m doing wrong when trying to communicate with my control device. Code that fails:
VOID ControlDeviceEvtIoDeviceControl(IN WDFQUEUE Queue, IN WDFREQUEST Request, IN size_t OutputBufferLength, IN size_t InputBufferLength, IN ULONG IoControlCode)
{
NTSTATUS status;
ULONG i;
ULONG itemCount;
WDFDEVICE hFilterDevice;
PDEVICE_EXTENSION devExt;
ULONG *outputBuffer = 0;
ULONG bufLen = 0;
DbgPrint(“Ioctl IO: %d OutputLen: %d InputLen: %d\n”, IoControlCode, OutputBufferLength, InputBufferLength);
status = WdfRequestRetrieveOutputBuffer(Request, sizeof(ULONG), (PVOID)outputBuffer, &bufLen);
if(!NT_SUCCESS(status))
{
DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”, status);
}
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, 0);
}
That results a bluescreen. Outputbuffer is an ULONG and without requesting the outputbuffer the dbgprint prints outputbuffer length 4 bytes. Do you need more details on this?
Any ideas? Thanks!
Hello,
the third argument ((PVOID)outputBuffer) you supply to
WdfRequestRetrieveOutputBuffer() is wrong, because it should be a pointer
to a pointer, whereas yours is the buffer’s own pointer, i.e., you’re
missing one level of indirection.
This should fix it:
status = WdfRequestRetrieveOutputBuffer(
Request,
sizeof(*outputBuffer),
&outputBuffer, // Note the &!
&bufLen
);
It probably doesn’t matter, but bufLen should also be of type size_t.
On Fri, 21 Nov 2008 11:46:51 +0100, wrote:
> Okay, I have my driver almost done, but I don’t know what I’m doing
> wrong when trying to communicate with my control device. Code that fails:
>
> VOID ControlDeviceEvtIoDeviceControl(IN WDFQUEUE Queue, IN WDFREQUEST
> Request, IN size_t OutputBufferLength, IN size_t InputBufferLength, IN
> ULONG IoControlCode)
> {
> NTSTATUS status;
> ULONG i;
> ULONG itemCount;
> WDFDEVICE hFilterDevice;
> PDEVICE_EXTENSION devExt;
> ULONG *outputBuffer = 0;
> ULONG bufLen = 0;
>
> DbgPrint(“Ioctl IO: %d OutputLen: %d InputLen: %d\n”, IoControlCode,
> OutputBufferLength, InputBufferLength);
>
> status = WdfRequestRetrieveOutputBuffer(Request, sizeof(ULONG),
> (PVOID)outputBuffer, &bufLen);
> if(!NT_SUCCESS(status))
> {
> DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”, status);
> }
>
> WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, 0);
> }
>
> That results a bluescreen. Outputbuffer is an ULONG and without
> requesting the outputbuffer the dbgprint prints outputbuffer length 4
> bytes. Do you need more details on this?
>
> Any ideas? Thanks!
Heh, I should say of course but I wont because i did not notice that. Thank
you very much for your help 
On Fri, Nov 21, 2008 at 1:03 PM, Cay Bremer wrote:
> Hello,
>
> the third argument ((PVOID)outputBuffer) you supply to
> WdfRequestRetrieveOutputBuffer() is wrong, because it should be a pointer to
> a pointer, whereas yours is the buffer’s own pointer, i.e., you’re missing
> one level of indirection.
>
> This should fix it:
> status = WdfRequestRetrieveOutputBuffer(
> Request,
> sizeof(*outputBuffer),
> &outputBuffer, // Note the &!
> &bufLen
> );
>
> It probably doesn’t matter, but bufLen should also be of type size_t.
>
>
> - Cay
>
>
>
> On Fri, 21 Nov 2008 11:46:51 +0100, wrote:
>
>> Okay, I have my driver almost done, but I don’t know what I’m doing wrong
>> when trying to communicate with my control device. Code that fails:
>>
>> VOID ControlDeviceEvtIoDeviceControl(IN WDFQUEUE Queue, IN WDFREQUEST
>> Request, IN size_t OutputBufferLength, IN size_t InputBufferLength, IN ULONG
>> IoControlCode)
>> {
>> NTSTATUS status;
>> ULONG i;
>> ULONG itemCount;
>> WDFDEVICE hFilterDevice;
>> PDEVICE_EXTENSION devExt;
>> ULONG
>> *outputBuffer = 0;
>> ULONG
>> bufLen = 0;
>>
>> DbgPrint(“Ioctl IO: %d OutputLen: %d InputLen: %d\n”,
>> IoControlCode, OutputBufferLength, InputBufferLength);
>>
>> status = WdfRequestRetrieveOutputBuffer(Request, sizeof(ULONG),
>> (PVOID)outputBuffer, &bufLen);
>> if(!NT_SUCCESS(status))
>> {
>> DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”,
>> status);
>> }
>>
>> WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, 0);
>> }
>>
>> That results a bluescreen. Outputbuffer is an ULONG and without requesting
>> the outputbuffer the dbgprint prints outputbuffer length 4 bytes. Do you
>> need more details on this?
>>
>> Any ideas? Thanks!
>>
>
> —
> NTDEV is sponsored by OSR
>
> 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
>
xxxxx@gmail.com wrote:
Okay, I have my driver almost done, but I don’t know what I’m doing wrong when trying to communicate with my control device. Code that fails:
…
if(!NT_SUCCESS(status))
{
DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”, status);
}
Don’t ever print NTSTATUS using %d. A quick scan through ntstatus.h
will show you why this is such a bad idea. If you get -1073741790,
quick, what error is that?
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Alright, thanks!
On Fri, Nov 21, 2008 at 7:20 PM, Tim Roberts wrote:
> xxxxx@gmail.com wrote:
> > Okay, I have my driver almost done, but I don’t know what I’m doing wrong
> when trying to communicate with my control device. Code that fails:
> > …
> > if(!NT_SUCCESS(status))
> > {
> > DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”,
> status);
> > }
> >
>
> Don’t ever print NTSTATUS using %d. A quick scan through ntstatus.h
> will show you why this is such a bad idea. If you get -1073741790,
> quick, what error is that?
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> 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
>
Everything is working very nicely now and I have learned a lot while doing
this, but is there a way to install an upper filter for keyboards without a
reboot? I can do that by installing (i have an installer that copies the
.sys file, modifies registry and uses wdfcoinstaller) my driver and
unpluggin and then replugging a USB keyboard, but how about PS2? It seems
like PS2 cant be disabled or uninstalled without a reboot. Can I force the
current drivers to unload and load again so that my filter driver would be
loaded too?
Thanks 
On Sat, Nov 22, 2008 at 2:10 AM, Reima M?kinen wrote:
> Alright, thanks!
>
>
> On Fri, Nov 21, 2008 at 7:20 PM, Tim Roberts wrote:
>
>> xxxxx@gmail.com wrote:
>> > Okay, I have my driver almost done, but I don’t know what I’m doing
>> wrong when trying to communicate with my control device. Code that fails:
>> > …
>> > if(!NT_SUCCESS(status))
>> > {
>> > DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”,
>> status);
>> > }
>> >
>>
>> Don’t ever print NTSTATUS using %d. A quick scan through ntstatus.h
>> will show you why this is such a bad idea. If you get -1073741790,
>> quick, what error is that?
>>
>> –
>> Tim Roberts, xxxxx@probo.com
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> 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
>>
>
>
“is there a way to install an upper filter for keyboards without a reboot?”
yes,you can do that if just need to add the driver.
“yes,you can do that if just need to add the driver.”
So that it is loaded and fully working too?
Ps2 forces a reboot, sorry.
d
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Reima M?kinen
Sent: Tuesday, December 09, 2008 12:57 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Newbie question about keyboard filter (kbfilter example)
Everything is working very nicely now and I have learned a lot while doing this, but is there a way to install an upper filter for keyboards without a reboot? I can do that by installing (i have an installer that copies the .sys file, modifies registry and uses wdfcoinstaller) my driver and unpluggin and then replugging a USB keyboard, but how about PS2? It seems like PS2 cant be disabled or uninstalled without a reboot. Can I force the current drivers to unload and load again so that my filter driver would be loaded too?
Thanks 
On Sat, Nov 22, 2008 at 2:10 AM, Reima M?kinen > wrote:
Alright, thanks!
On Fri, Nov 21, 2008 at 7:20 PM, Tim Roberts > wrote:
xxxxx@gmail.commailto:xxxxx wrote:
> Okay, I have my driver almost done, but I don’t know what I’m doing wrong when trying to communicate with my control device. Code that fails:
> …
> if(!NT_SUCCESS(status))
> {
> DbgPrint(“WdfRequestRetrieveOutputBuffer failed: %d”, status);
> }
>
Don’t ever print NTSTATUS using %d. A quick scan through ntstatus.h
will show you why this is such a bad idea. If you get -1073741790,
quick, what error is that?
–
Tim Roberts, xxxxx@probo.commailto:xxxxx
Providenza & Boekelheide, Inc.
—
NTDEV is sponsored by OSR
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
— NTDEV is sponsored by OSR 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</mailto:xxxxx></mailto:xxxxx>