enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t
open handles to hard coded \device\keyboardclassN. A suggested may is to use
IoGetDeviceInterfaces for the keyboard class guid. But,
IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
corresponding API in NTDLL that I can use in a native mode application (like
autochk).

Can anyone suggest the API to use from NTDLL that would provide
IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of
NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra

There is no other way, the native apis does not expose a way to enumerate device interfaces, but hten again using the native NtCreateFile you can open a device object that does not have a symlink to user mode.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t open handles to hard coded \device\keyboardclassN. A suggested may is to use IoGetDeviceInterfaces for the keyboard class guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any corresponding API in NTDLL that I can use in a native mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra
— 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

“NtCreateFile you can open a device object that does not have a symlink to
user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
wrote:

> There is no other way, the native apis does not expose a way to
> enumerate device interfaces, but hten again using the native NtCreateFile
> you can open a device object that does not have a symlink to user mode.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of chandra97 97
> Sent: Thursday, June 05, 2008 11:45 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> In order to enumerate all keyboard device names in a native mode, we can’t
> open handles to hard coded \device\keyboardclassN. A suggested may is to use
> IoGetDeviceInterfaces for the keyboard class guid. But,
> IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
> corresponding API in NTDLL that I can use in a native mode application (like
> autochk).
>
> Can anyone suggest the API to use from NTDLL that would provide
> IoGetDeviceInterfaces functionality.
>
> My next step would be to explore SetupDi
APIs. But those are not part of
> NTDLL. Even If I use SetupDi
APIs, will they work in native mode?
>
> Thanks in advance,
> Chandra
> — 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
>

chandra97 97 wrote:

“NtCreateFile you can open a device object that does not have a
symlink to user mode”
What is the name of the device object you are referring to?

I think you misunderstood Doron What he means is that NtCreateFile can
open devices by their kernel name, whereas CreateFile can only open
devices that have symlinks to user mode.

So, if YOU know the kernel name of the device you want to open, you can
do it with NtCreateFile.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

\Device\Kbdclass%d in the OBJECT_ATTRIBUTES

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 12:41 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

“NtCreateFile you can open a device object that does not have a symlink to user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan > wrote:

There is no other way, the native apis does not expose a way to enumerate device interfaces, but hten again using the native NtCreateFile you can open a device object that does not have a symlink to user mode.

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t open handles to hard coded \device\keyboardclassN. A suggested may is to use IoGetDeviceInterfaces for the keyboard class guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any corresponding API in NTDLL that I can use in a native mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra
— 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

— 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>

Ok Thanks for clarifying that. I mentioned this device name in my question
in the beginning.

I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that
in some test runs I’m not able to get handle to \Device\Kbdclass3. Even
though my USB keyboard is attached right from the beginning I start the
machine. Like I said this does not happen all the time. In some cases I get
3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many
other cases I just get 2 handles (keyboardclass0, 1). In that case can’t
read USB keyboard. I confirmed this in windbg by looking at the handle table
of my native process.

Can you explain why this intermittent behavior. What can I do to fix this?

On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan
wrote:

> \Device\Kbdclass%d in the OBJECT_ATTRIBUTES
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 12:41 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> “NtCreateFile you can open a device object that does not have a symlink to
> user mode”
> What is the name of the device object you are referring to?
>
> On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
> wrote:
>
> There is no other way, the native apis does not expose a way to
> enumerate device interfaces, but hten again using the native NtCreateFile
> you can open a device object that does not have a symlink to user mode.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of chandra97 97
> Sent: Thursday, June 05, 2008 11:45 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> In order to enumerate all keyboard device names in a native mode, we can’t
> open handles to hard coded \device\keyboardclassN. A suggested may is to use
> IoGetDeviceInterfaces for the keyboard class guid. But,
> IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
> corresponding API in NTDLL that I can use in a native mode application (like
> autochk).
>
> Can anyone suggest the API to use from NTDLL that would provide
> IoGetDeviceInterfaces functionality.
>
> My next step would be to explore SetupDi
APIs. But those are not part of
> NTDLL. Even If I use SetupDi
APIs, will they work in native mode?
>
> Thanks in advance,
> Chandra
>
> — 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
>
>
> — 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
>

Virtual keyboards. Never assume that number N is a particular type of keyboard. Are you stopping to open handles on the first error? There could easily be holes in the namespace as well so that would not be the right thing to do…

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 1:56 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

Ok Thanks for clarifying that. I mentioned this device name in my question in the beginning.

I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that in some test runs I’m not able to get handle to \Device\Kbdclass3. Even though my USB keyboard is attached right from the beginning I start the machine. Like I said this does not happen all the time. In some cases I get 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many other cases I just get 2 handles (keyboardclass0, 1). In that case can’t read USB keyboard. I confirmed this in windbg by looking at the handle table of my native process.

Can you explain why this intermittent behavior. What can I do to fix this?
On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan > wrote:

\Device\Kbdclass%d in the OBJECT_ATTRIBUTES

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 12:41 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

“NtCreateFile you can open a device object that does not have a symlink to user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan > wrote:

There is no other way, the native apis does not expose a way to enumerate device interfaces, but hten again using the native NtCreateFile you can open a device object that does not have a symlink to user mode.

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t open handles to hard coded \device\keyboardclassN. A suggested may is to use IoGetDeviceInterfaces for the keyboard class guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any corresponding API in NTDLL that I can use in a native mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra

— 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

— 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

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

No I’m NOT stopping if I see an error. I enumerate from N from 0 to 255 and
store handles for successful creates.
If I see an error for any N, I just ignore it.
Any clues how can I avoid this situation and get all the needed keyboard
handles?

On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan
wrote:

> Virtual keyboards. Never assume that number N is a particular type of
> keyboard. Are you stopping to open handles on the first error? There could
> easily be holes in the namespace as well so that would not be the right
> thing to do?
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 1:56 PM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> Ok Thanks for clarifying that. I mentioned this device name in my question
> in the beginning.
>
> I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that
> in some test runs I’m not able to get handle to \Device\Kbdclass3. Even
> though my USB keyboard is attached right from the beginning I start the
> machine. Like I said this does not happen all the time. In some cases I get
> 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many
> other cases I just get 2 handles (keyboardclass0, 1). In that case can’t
> read USB keyboard. I confirmed this in windbg by looking at the handle table
> of my native process.
>
> Can you explain why this intermittent behavior. What can I do to fix this?
>
> On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan
> wrote:
>
> \Device\Kbdclass%d in the OBJECT_ATTRIBUTES
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 12:41 PM
>
>
> To: Windows System Software Devs Interest List
>
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> “NtCreateFile you can open a device object that does not have a symlink to
> user mode”
> What is the name of the device object you are referring to?
>
> On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
> wrote:
>
> There is no other way, the native apis does not expose a way to
> enumerate device interfaces, but hten again using the native NtCreateFile
> you can open a device object that does not have a symlink to user mode.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of chandra97 97
> Sent: Thursday, June 05, 2008 11:45 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> In order to enumerate all keyboard device names in a native mode, we can’t
> open handles to hard coded \device\keyboardclassN. A suggested may is to use
> IoGetDeviceInterfaces for the keyboard class guid. But,
> IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
> corresponding API in NTDLL that I can use in a native mode application (like
> autochk).
>
> Can anyone suggest the API to use from NTDLL that would provide
> IoGetDeviceInterfaces functionality.
>
> My next step would be to explore SetupDi
APIs. But those are not part of
> NTDLL. Even If I use SetupDi
APIs, will they work in native mode?
>
> Thanks in advance,
> Chandra
>
> — 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
>
>
> — 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
>
>
> — 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
>

Perhaps the usb keyboard has not yet been enumerated and started. What does “!devnode 0 1 kbdhid” say at the exact moment in time that you cannot open the usb keyboard?

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 3:26 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

No I’m NOT stopping if I see an error. I enumerate from N from 0 to 255 and store handles for successful creates.
If I see an error for any N, I just ignore it.
Any clues how can I avoid this situation and get all the needed keyboard handles?

On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan > wrote:

Virtual keyboards. Never assume that number N is a particular type of keyboard. Are you stopping to open handles on the first error? There could easily be holes in the namespace as well so that would not be the right thing to do…

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 1:56 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

Ok Thanks for clarifying that. I mentioned this device name in my question in the beginning.

I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that in some test runs I’m not able to get handle to \Device\Kbdclass3. Even though my USB keyboard is attached right from the beginning I start the machine. Like I said this does not happen all the time. In some cases I get 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many other cases I just get 2 handles (keyboardclass0, 1). In that case can’t read USB keyboard. I confirmed this in windbg by looking at the handle table of my native process.

Can you explain why this intermittent behavior. What can I do to fix this?

On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan > wrote:

\Device\Kbdclass%d in the OBJECT_ATTRIBUTES

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 12:41 PM

To: Windows System Software Devs Interest List

Subject: Re: [ntdev] enumerating all keyboards from a native mode application

“NtCreateFile you can open a device object that does not have a symlink to user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan > wrote:

There is no other way, the native apis does not expose a way to enumerate device interfaces, but hten again using the native NtCreateFile you can open a device object that does not have a symlink to user mode.

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t open handles to hard coded \device\keyboardclassN. A suggested may is to use IoGetDeviceInterfaces for the keyboard class guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any corresponding API in NTDLL that I can use in a native mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra

— 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

— 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

— 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

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

Like I mentioned this is intermittent. When I step through my native program
during handle opening in windbg, it always finds ALL keyboards. Also in many
situations without debugger it works fine. But, in some situations it does
NOT and that moment I break into attached windbg. I list all the handles
(file object pointers) of my native mode process using !handle 0 3
<my_eprocess>. Then I use !devobj on FIleObject->DeviceObject pointer for
each file object pointer. I did see device names for KeyboardClass0 and
KeyBoardClass1 in the handle listing. Then I check all objects under \device
directory. In \device directory listing I do find ALL 3 keyboard class
objects (\device\KeyboardClass0, 1 and 2). This indicates to me there could
be a race condition between PnP enumeration and my native mode program
trying to create handle to ALL possible keyboard device objects. But, I
don’t think that to be the case because my USB keyboard is attached right
at machine power up. Also, I can choose multi-OS boot option from my USB
keyboard which happen much earlier than the start of my native program.

I havn;t tried !devnode command that you are suggesting. I will try it when
I can repro it again. In the meantime, any other suggestions for a fix to
this issue?

On Thu, Jun 5, 2008 at 7:01 PM, Doron Holan
wrote:

> Perhaps the usb keyboard has not yet been enumerated and started. What
> does “!devnode 0 1 kbdhid” say at the exact moment in time that you cannot
> open the usb keyboard?
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 3:26 PM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> No I’m NOT stopping if I see an error. I enumerate from N from 0 to 255 and
> store handles for successful creates.
> If I see an error for any N, I just ignore it.
> Any clues how can I avoid this situation and get all the needed keyboard
> handles?
>
> On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan
> wrote:
>
> Virtual keyboards. Never assume that number N is a particular type of
> keyboard. Are you stopping to open handles on the first error? There could
> easily be holes in the namespace as well so that would not be the right
> thing to do?
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 1:56 PM
>
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> Ok Thanks for clarifying that. I mentioned this device name in my question
> in the beginning.
>
> I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that
> in some test runs I’m not able to get handle to \Device\Kbdclass3. Even
> though my USB keyboard is attached right from the beginning I start the
> machine. Like I said this does not happen all the time. In some cases I get
> 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many
> other cases I just get 2 handles (keyboardclass0, 1). In that case can’t
> read USB keyboard. I confirmed this in windbg by looking at the handle table
> of my native process.
>
> Can you explain why this intermittent behavior. What can I do to fix this?
>
> On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan
> wrote:
>
> \Device\Kbdclass%d in the OBJECT_ATTRIBUTES
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 12:41 PM
>
>
> To: Windows System Software Devs Interest List
>
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> “NtCreateFile you can open a device object that does not have a symlink to
> user mode”
> What is the name of the device object you are referring to?
>
> On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
> wrote:
>
> There is no other way, the native apis does not expose a way to
> enumerate device interfaces, but hten again using the native NtCreateFile
> you can open a device object that does not have a symlink to user mode.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of chandra97 97
> Sent: Thursday, June 05, 2008 11:45 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> In order to enumerate all keyboard device names in a native mode, we can’t
> open handles to hard coded \device\keyboardclassN. A suggested may is to use
> IoGetDeviceInterfaces for the keyboard class guid. But,
> IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
> corresponding API in NTDLL that I can use in a native mode application (like
> autochk).
>
> Can anyone suggest the API to use from NTDLL that would provide
> IoGetDeviceInterfaces functionality.
>
> My next step would be to explore SetupDi
APIs. But those are not part of
> NTDLL. Even If I use SetupDi
APIs, will they work in native mode?
>
> Thanks in advance,
> Chandra
>
> — 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
>
>
> — 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
>
>
> — 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
>
>
> — 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
></my_eprocess>

Think about what you just said (“the keyboard works at startup, why does not it enumerate quickly when the OS is booting”). Many devices work at the boot screen (video, storage, usb HID, etc). does that mean that they will work in the target OS? No, absolutely not. You need drivers for each of these devices. At boot the bios is running the show, when your app runs, the OS is running the show. Of course there is a race between your native app starting and pnp, pnp does not wait for processes to start, it runs async based on the changes in the tree. So yes, you could very well be in the state where the keyboard HID stack has been built but not yet started when your native app runs. You have to deal with it.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 8:29 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

Like I mentioned this is intermittent. When I step through my native program during handle opening in windbg, it always finds ALL keyboards. Also in many situations without debugger it works fine. But, in some situations it does NOT and that moment I break into attached windbg. I list all the handles (file object pointers) of my native mode process using !handle 0 3 <my_eprocess>. Then I use !devobj on FIleObject->DeviceObject pointer for each file object pointer. I did see device names for KeyboardClass0 and KeyBoardClass1 in the handle listing. Then I check all objects under \device directory. In \device directory listing I do find ALL 3 keyboard class objects (\device\KeyboardClass0, 1 and 2). This indicates to me there could be a race condition between PnP enumeration and my native mode program trying to create handle to ALL possible keyboard device objects. But, I don’t think that to be the case because my USB keyboard is attached right at machine power up. Also, I can choose multi-OS boot option from my USB keyboard which happen much earlier than the start of my native program.

I havn;t tried !devnode command that you are suggesting. I will try it when I can repro it again. In the meantime, any other suggestions for a fix to this issue?
On Thu, Jun 5, 2008 at 7:01 PM, Doron Holan > wrote:

Perhaps the usb keyboard has not yet been enumerated and started. What does “!devnode 0 1 kbdhid” say at the exact moment in time that you cannot open the usb keyboard?

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 3:26 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

No I’m NOT stopping if I see an error. I enumerate from N from 0 to 255 and store handles for successful creates.
If I see an error for any N, I just ignore it.
Any clues how can I avoid this situation and get all the needed keyboard handles?

On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan > wrote:

Virtual keyboards. Never assume that number N is a particular type of keyboard. Are you stopping to open handles on the first error? There could easily be holes in the namespace as well so that would not be the right thing to do…

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 1:56 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode application

Ok Thanks for clarifying that. I mentioned this device name in my question in the beginning.

I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that in some test runs I’m not able to get handle to \Device\Kbdclass3. Even though my USB keyboard is attached right from the beginning I start the machine. Like I said this does not happen all the time. In some cases I get 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many other cases I just get 2 handles (keyboardclass0, 1). In that case can’t read USB keyboard. I confirmed this in windbg by looking at the handle table of my native process.

Can you explain why this intermittent behavior. What can I do to fix this?

On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan > wrote:

\Device\Kbdclass%d in the OBJECT_ATTRIBUTES

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 12:41 PM

To: Windows System Software Devs Interest List

Subject: Re: [ntdev] enumerating all keyboards from a native mode application

“NtCreateFile you can open a device object that does not have a symlink to user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan > wrote:

There is no other way, the native apis does not expose a way to enumerate device interfaces, but hten again using the native NtCreateFile you can open a device object that does not have a symlink to user mode.

d

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.commailto:xxxxx] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native mode application

In order to enumerate all keyboard device names in a native mode, we can’t open handles to hard coded \device\keyboardclassN. A suggested may is to use IoGetDeviceInterfaces for the keyboard class guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any corresponding API in NTDLL that I can use in a native mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But those are not part of NTDLL. Even If I use SetupDi* APIs, will they work in native mode?

Thanks in advance,
Chandra

— 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

— 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

— 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

— 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

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

Can I wait for PnP enumeration to complete on a specific (in this case
keyboard) device (may be in a timeout)? Or, can I check if PnP enumeration
is going on and I wait for it until it gets done?

Thanks

On Fri, Jun 6, 2008 at 1:21 AM, Doron Holan
wrote:

> Think about what you just said (“the keyboard works at startup, why does
> not it enumerate quickly when the OS is booting”). Many devices work at the
> boot screen (video, storage, usb HID, etc). does that mean that they will
> work in the target OS? No, absolutely not. You need drivers for each of
> these devices. At boot the bios is running the show, when your app runs,
> the OS is running the show. Of course there is a race between your native
> app starting and pnp, pnp does not wait for processes to start, it runs
> async based on the changes in the tree. So yes, you could very well be in
> the state where the keyboard HID stack has been built *but not yet started
> * when your native app runs. You have to deal with it.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 8:29 PM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> Like I mentioned this is intermittent. When I step through my native
> program during handle opening in windbg, it always finds ALL keyboards. Also
> in many situations without debugger it works fine. But, in some situations
> it does NOT and that moment I break into attached windbg. I list all the
> handles (file object pointers) of my native mode process using !handle 0 3
> <my_eprocess>. Then I use !devobj on FIleObject->DeviceObject pointer for
> each file object pointer. I did see device names for KeyboardClass0 and
> KeyBoardClass1 in the handle listing. Then I check all objects under \device
> directory. In \device directory listing I do find ALL 3 keyboard class
> objects (\device\KeyboardClass0, 1 and 2). This indicates to me there could
> be a race condition between PnP enumeration and my native mode program
> trying to create handle to ALL possible keyboard device objects. But, I
> don’t think that to be the case because my USB keyboard is attached right
> at machine power up. Also, I can choose multi-OS boot option from my USB
> keyboard which happen much earlier than the start of my native program.
>
> I havn;t tried !devnode command that you are suggesting. I will try it
> when I can repro it again. In the meantime, any other suggestions for a fix
> to this issue?
>
> On Thu, Jun 5, 2008 at 7:01 PM, Doron Holan
> wrote:
>
> Perhaps the usb keyboard has not yet been enumerated and started. What
> does “!devnode 0 1 kbdhid” say at the exact moment in time that you cannot
> open the usb keyboard?
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 3:26 PM
>
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> No I’m NOT stopping if I see an error. I enumerate from N from 0 to 255 and
> store handles for successful creates.
> If I see an error for any N, I just ignore it.
> Any clues how can I avoid this situation and get all the needed keyboard
> handles?
>
> On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan
> wrote:
>
> Virtual keyboards. Never assume that number N is a particular type of
> keyboard. Are you stopping to open handles on the first error? There could
> easily be holes in the namespace as well so that would not be the right
> thing to do?
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 1:56 PM
>
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> Ok Thanks for clarifying that. I mentioned this device name in my question
> in the beginning.
>
> I try to get handles to ALL \Device\Kbdclass%d devices. I am noticing that
> in some test runs I’m not able to get handle to \Device\Kbdclass3. Even
> though my USB keyboard is attached right from the beginning I start the
> machine. Like I said this does not happen all the time. In some cases I get
> 3 handles (keyboardclass0, 1, 2). Then I can read the USB keyboard. In many
> other cases I just get 2 handles (keyboardclass0, 1). In that case can’t
> read USB keyboard. I confirmed this in windbg by looking at the handle table
> of my native process.
>
> Can you explain why this intermittent behavior. What can I do to fix this?
>
> On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan
> wrote:
>
> \Device\Kbdclass%d in the OBJECT_ATTRIBUTES
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *chandra97 97
> Sent: Thursday, June 05, 2008 12:41 PM
>
>
> To: Windows System Software Devs Interest List
>
> Subject: Re: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> “NtCreateFile you can open a device object that does not have a symlink to
> user mode”
> What is the name of the device object you are referring to?
>
> On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
> wrote:
>
> There is no other way, the native apis does not expose a way to
> enumerate device interfaces, but hten again using the native NtCreateFile
> you can open a device object that does not have a symlink to user mode.
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of chandra97 97
> Sent: Thursday, June 05, 2008 11:45 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] enumerating all keyboards from a native mode
> application
>
>
>
> In order to enumerate all keyboard device names in a native mode, we can’t
> open handles to hard coded \device\keyboardclassN. A suggested may is to use
> IoGetDeviceInterfaces for the keyboard class guid. But,
> IoGetDeviceInterfaces is exported from ntoskrnl and I couldn’t find any
> corresponding API in NTDLL that I can use in a native mode application (like
> autochk).
>
> Can anyone suggest the API to use from NTDLL that would provide
> IoGetDeviceInterfaces functionality.
>
> My next step would be to explore SetupDi
APIs. But those are not part of
> NTDLL. Even If I use SetupDi
APIs, will they work in native mode?
>
> Thanks in advance,
> Chandra
>
> — 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
>
>
> — 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
>
>
> — 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
>
>
> — 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
>
>
> — 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
></my_eprocess>

USB keyboards won’t always be found by a native app, a delay between the
start of a native app and enumerating keyboards would be the only way it
works well.

and What if a (USB) keyboard is plugged in later on?

and does your code handle multiple keybards?

What I did when faced with this situation a while back was have an event
driven input loop that looked for events from each keyboard with a
timeout, and if it times out occurs poll for new keyboards.

BR,

Rob Linegar
Software Engineer
Data Encryption Systems Limited
www.des.co.uk | www.deslock.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: 06 June 2008 14:24
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native mode
application

Can I wait for PnP enumeration to complete on a specific (in this case
keyboard) device (may be in a timeout)? Or, can I check if PnP
enumeration is going on and I wait for it until it gets done?

Thanks

On Fri, Jun 6, 2008 at 1:21 AM, Doron Holan
wrote:

Think about what you just said (“the keyboard works at startup,
why does not it enumerate quickly when the OS is booting”). Many
devices work at the boot screen (video, storage, usb HID, etc). does
that mean that they will work in the target OS? No, absolutely not.
You need drivers for each of these devices. At boot the bios is running
the show, when your app runs, the OS is running the show. Of course
there is a race between your native app starting and pnp, pnp does not
wait for processes to start, it runs async based on the changes in the
tree. So yes, you could very well be in the state where the keyboard HID
stack has been built but not yet started when your native app runs. You
have to deal with it.

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 8:29 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native
mode application

Like I mentioned this is intermittent. When I step through my
native program during handle opening in windbg, it always finds ALL
keyboards. Also in many situations without debugger it works fine. But,
in some situations it does NOT and that moment I break into attached
windbg. I list all the handles (file object pointers) of my native mode
process using !handle 0 3 <my_eprocess>. Then I use !devobj on
FIleObject->DeviceObject pointer for each file object pointer. I did see
device names for KeyboardClass0 and KeyBoardClass1 in the handle
listing. Then I check all objects under \device directory. In \device
directory listing I do find ALL 3 keyboard class objects
(\device\KeyboardClass0, 1 and 2). This indicates to me there could be a
race condition between PnP enumeration and my native mode program trying
to create handle to ALL possible keyboard device objects. But, I don’t
think that to be the case because my USB keyboard is attached right at
machine power up. Also, I can choose multi-OS boot option from my USB
keyboard which happen much earlier than the start of my native program.

I havn;t tried !devnode command that you are suggesting. I will
try it when I can repro it again. In the meantime, any other
suggestions for a fix to this issue?

On Thu, Jun 5, 2008 at 7:01 PM, Doron Holan
wrote:

Perhaps the usb keyboard has not yet been enumerated and
started. What does “!devnode 0 1 kbdhid” say at the exact moment in
time that you cannot open the usb keyboard?

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 3:26 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native
mode application

No I’m NOT stopping if I see an error. I enumerate from N from 0
to 255 and store handles for successful creates.
If I see an error for any N, I just ignore it.
Any clues how can I avoid this situation and get all the needed
keyboard handles?

On Thu, Jun 5, 2008 at 5:01 PM, Doron Holan
wrote:

Virtual keyboards. Never assume that number N is a particular
type of keyboard. Are you stopping to open handles on the first error?
There could easily be holes in the namespace as well so that would not
be the right thing to do…

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 1:56 PM

To: Windows System Software Devs Interest List
Subject: Re: [ntdev] enumerating all keyboards from a native
mode application

Ok Thanks for clarifying that. I mentioned this device name in
my question in the beginning.

I try to get handles to ALL \Device\Kbdclass%d devices. I am
noticing that in some test runs I’m not able to get handle to
\Device\Kbdclass3. Even though my USB keyboard is attached right from
the beginning I start the machine. Like I said this does not happen all
the time. In some cases I get 3 handles (keyboardclass0, 1, 2). Then I
can read the USB keyboard. In many other cases I just get 2 handles
(keyboardclass0, 1). In that case can’t read USB keyboard. I confirmed
this in windbg by looking at the handle table of my native process.

Can you explain why this intermittent behavior. What can I do to
fix this?

On Thu, Jun 5, 2008 at 4:10 PM, Doron Holan
wrote:

\Device\Kbdclass%d in the OBJECT_ATTRIBUTES

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 12:41 PM

To: Windows System Software Devs Interest List

Subject: Re: [ntdev] enumerating all keyboards from a native
mode application

“NtCreateFile you can open a device object that does not have a
symlink to user mode”
What is the name of the device object you are referring to?

On Thu, Jun 5, 2008 at 2:58 PM, Doron Holan
wrote:

There is no other way, the native apis does not expose
a way to enumerate device interfaces, but hten again using the native
NtCreateFile you can open a device object that does not have a symlink
to user mode.

d

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of chandra97 97
Sent: Thursday, June 05, 2008 11:45 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] enumerating all keyboards from a native
mode application

In order to enumerate all keyboard device names in a
native mode, we can’t open handles to hard coded \device\keyboardclassN.
A suggested may is to use IoGetDeviceInterfaces for the keyboard class
guid. But, IoGetDeviceInterfaces is exported from ntoskrnl and I
couldn’t find any corresponding API in NTDLL that I can use in a native
mode application (like autochk).

Can anyone suggest the API to use from NTDLL that would
provide IoGetDeviceInterfaces functionality.

My next step would be to explore SetupDi* APIs. But
those are not part of NTDLL. Even If I use SetupDi* APIs, will they work
in native mode?

Thanks in advance,
Chandra

— 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

— 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

— 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

— 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

— 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

— 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</my_eprocess>

> NtCreateFile can open devices by their kernel name, whereas CreateFile can only

open devices that have symlinks to user mode.

There is no such thing as “kernel name” or “symlink to user mode” - all objects can get accessed by either their real names or symbolic links from both kernel and user modes. The only reason why you cannot open devices by their real names with CreateFile is because Win32 wrapper pre-pends ‘??’ to the strings that it passes to ZwCreateFile(), so that the system looks for the target name only in ‘DosDevices’. In other words, this is not the question of kernel mode vs user one, but solely of Win32 wrapper vs native API…

Anton Bassov

Doron, Rob.

Thanks for your input. Having a few seconds sleep fixed the issue.

Anton,
I understand the concept of Global (??) DosDevices object directory for user
mode.

Thanks.

On Sun, Jun 8, 2008 at 2:38 AM, wrote:

> > NtCreateFile can open devices by their kernel name, whereas CreateFile
> can only
> > open devices that have symlinks to user mode.
>
> There is no such thing as “kernel name” or “symlink to user mode” - all
> objects can get accessed by either their real names or symbolic links from
> both kernel and user modes. The only reason why you cannot open devices by
> their real names with CreateFile is because Win32 wrapper pre-pends ‘??’ to
> the strings that it passes to ZwCreateFile(), so that the system looks for
> the target name only in ‘DosDevices’. In other words, this is not the
> question of kernel mode vs user one, but solely of Win32 wrapper vs native
> API…
>
>
> Anton Bassov
>
> —
> 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
>