IoReportTargetDeviceChangeAsynchronous from HID Minidriver

Hi,

I have a hid mini driver based on the vhidmini sample. I am trying to use IoReportTargetDeviceChangeAsynchronous following the example given at:
http://www.microsoft.com/whdc/Driver/tips/PnPUmNotif.mspx to send a custom event to an app in user mode. Try as I might I can’t get the user mode code to see the event. There are no errors and I’m not sure what I’m doing wrong. If I disable the device I do get the detach PNP messages so I’m thinking it has to do with the driver code.

Here’s the relevant bits of code:
Driver:
RtlZeroMemory(buffer, sizeof(sizeof(TARGET_DEVICE_CUSTOM_NOTIFICATION) + sizeof(EVENT_INFO)));

pNotify = (PTARGET_DEVICE_CUSTOM_NOTIFICATION) buffer;

RtlCopyMemory(&pNotify->Event, &GUID_CUSTOM_EVENT, sizeof(GUID));

pNotify->NameBufferOffset = -1;
pNotify->Version = 1;
pNotify->Size = sizeof(*pNotify) - sizeof(pNotify->CustomDataBuffer) + sizeof(*pInfo);

pInfo = (EVENT_INFO UNALIGNED *) &pNotify->CustomDataBuffer[0];

pInfo->lInputMode = pDevExt->InputMode;
pInfo->lDeviceIndex = 0;

ntStatus = IoReportTargetDeviceChangeAsynchronous( pDevExt->Pdo, pNotify, NULL, NULL );

Register code in the App:
memset( &broadcastHandle, 0, sizeof( DEV_BROADCAST_HANDLE ) );
broadcastHandle.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
broadcastHandle.dbch_devicetype = DBT_DEVTYP_HANDLE;
broadcastHandle.dbch_nameoffset = -1;
broadcastHandle.dbch_handle = hidIF.GetDeviceHandle();
hDevNotify = RegisterDeviceNotification( hWnd,
&broadcastHandle,
DEVICE_NOTIFY_WINDOW_HANDLE);

Any hints are greatly appreciated.

-Dan

It has been several OS releases since the last time I looked at custom pnp
events, but the last time I looked at custom pnp events I painfully came to
the conclusion that they did not actually work and that while your drive
could deliver the event, your app would never receive the notification. As I
said, this was a long time ago, so this defect may actually have been fixed.

On Jan 25, 2008 10:17 PM, wrote:

> Hi,
>
> I have a hid mini driver based on the vhidmini sample. I am trying to use
> IoReportTargetDeviceChangeAsynchronous following the example given at:
> http://www.microsoft.com/whdc/Driver/tips/PnPUmNotif.mspx to send a custom
> event to an app in user mode. Try as I might I can’t get the user mode code
> to see the event. There are no errors and I’m not sure what I’m doing
> wrong. If I disable the device I do get the detach PNP messages so I’m
> thinking it has to do with the driver code.
>
>
> Here’s the relevant bits of code:
> Driver:
> RtlZeroMemory(buffer,
> sizeof(sizeof(TARGET_DEVICE_CUSTOM_NOTIFICATION) + sizeof(EVENT_INFO)));
>
> pNotify =
> (PTARGET_DEVICE_CUSTOM_NOTIFICATION) buffer;
>
>
> RtlCopyMemory(&pNotify->Event, &GUID_CUSTOM_EVENT, sizeof(GUID));
>
> pNotify->NameBufferOffset =
> -1;
> pNotify->Version = 1;
> pNotify->Size =
> sizeof(*pNotify) - sizeof(pNotify->CustomDataBuffer) + sizeof(*pInfo);
>
> pInfo = (EVENT_INFO
> UNALIGNED *) &pNotify->CustomDataBuffer[0];
>
> pInfo->lInputMode =
> pDevExt->InputMode;
> pInfo->lDeviceIndex = 0;
>
> ntStatus =
> IoReportTargetDeviceChangeAsynchronous( pDevExt->Pdo, pNotify, NULL, NULL );
>
>
> Register code in the App:
> memset( &broadcastHandle, 0, sizeof( DEV_BROADCAST_HANDLE ) );
> broadcastHandle.dbch_size =
> sizeof(DEV_BROADCAST_HANDLE);
> broadcastHandle.dbch_devicetype = DBT_DEVTYP_HANDLE;
> broadcastHandle.dbch_nameoffset = -1;
> broadcastHandle.dbch_handle = hidIF.GetDeviceHandle();
> hDevNotify = RegisterDeviceNotification( hWnd,
>
> &broadcastHandle,
>
> DEVICE_NOTIFY_WINDOW_HANDLE);
>
> Any hints are greatly appreciated.
>
> -Dan
>
>
> —
> 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
>


Mark Roddy

They have always worked for me. This is what I think is going on is that the HID minidriver is posting events on the parent HID stack (e.g. the PDO enumerated by USB or Bluetooth) and the application is registering for notifications on a handle that it opened which is the HID enumerated PDO (the child stack create by HID, e.g. not the HID parent stack). The HID miniport does not have access to the HID enumerated children so this scheme is not going to work (and no your app cannot open the parent,hidclass fails creates on the parent).

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Saturday, January 26, 2008 7:52 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] IoReportTargetDeviceChangeAsynchronous from HID Minidriver

It has been several OS releases since the last time I looked at custom pnp events, but the last time I looked at custom pnp events I painfully came to the conclusion that they did not actually work and that while your drive could deliver the event, your app would never receive the notification. As I said, this was a long time ago, so this defect may actually have been fixed.

On Jan 25, 2008 10:17 PM, > wrote:
Hi,

I have a hid mini driver based on the vhidmini sample. I am trying to use IoReportTargetDeviceChangeAsynchronous following the example given at:
http://www.microsoft.com/whdc/Driver/tips/PnPUmNotif.mspx to send a custom event to an app in user mode. Try as I might I can’t get the user mode code to see the event. There are no errors and I’m not sure what I’m doing wrong. If I disable the device I do get the detach PNP messages so I’m thinking it has to do with the driver code.

Here’s the relevant bits of code:
Driver:
RtlZeroMemory(buffer, sizeof(sizeof(TARGET_DEVICE_CUSTOM_NOTIFICATION) + sizeof(EVENT_INFO)));

pNotify = (PTARGET_DEVICE_CUSTOM_NOTIFICATION) buffer;

RtlCopyMemory(&pNotify->Event, &GUID_CUSTOM_EVENT, sizeof(GUID));

pNotify->NameBufferOffset = -1;
pNotify->Version = 1;
pNotify->Size = sizeof(*pNotify) - sizeof(pNotify->CustomDataBuffer) + sizeof(*pInfo);

pInfo = (EVENT_INFO UNALIGNED *) &pNotify->CustomDataBuffer[0];

pInfo->lInputMode = pDevExt->InputMode;
pInfo->lDeviceIndex = 0;

ntStatus = IoReportTargetDeviceChangeAsynchronous( pDevExt->Pdo, pNotify, NULL, NULL );

Register code in the App:
memset( &broadcastHandle, 0, sizeof( DEV_BROADCAST_HANDLE ) );
broadcastHandle.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
broadcastHandle.dbch_devicetype = DBT_DEVTYP_HANDLE;
broadcastHandle.dbch_nameoffset = -1;
broadcastHandle.dbch_handle = hidIF.GetDeviceHandle();
hDevNotify = RegisterDeviceNotification( hWnd,
&broadcastHandle,
DEVICE_NOTIFY_WINDOW_HANDLE);

Any hints are greatly appreciated.

-Dan


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


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

Thank you Mark and Doron. Sometimes being told an approach isn’t going to work is very valuable information. I’ll just create custom collection for the app to listen to.
Seems kind of clunky but at least I know it will work.

-Dan

2 other ways to communicate with an application from a hid miniport

  1. WMI (Events, execute method)

  2. write a full blown KMDF lower filter driver + the hidshim miniport driver in the 6001 WDK. This allows you to enumerate your own PDOs alongside the HID PDOs. Your pdo does not need to be a HID PDO, it can be a custom interface with a custom guid and your own IOCTLs. The kmdf kbfiltr example does this, you would just need to yank the raw PDO enumeration stuff out of it and merge it with the top level logic in the hidusbfx2 mapper driver that shows you how to use the hidshim driver.

D

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, January 28, 2008 4:14 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IoReportTargetDeviceChangeAsynchronous from HID Minidriver

Thank you Mark and Doron. Sometimes being told an approach isn’t going to work is very valuable information. I’ll just create custom collection for the app to listen to.
Seems kind of clunky but at least I know it will work.

-Dan


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