I've been posting questions relate to this for a few days now. Yesterday I
was criticized for not providing enough information. I always have mixed
feelings about posting too much information, because I believe many will
tire of reading, and move on.
But, I'll give this a try.
I've created a Window in a Dll to respond to PnP events from my USB device.
I've double-checked the driver, and it seems to be registering and enabling
the interface correctly. I suspect that it's my user mode code that's at
fault.
Below is my code for creating the window, where the
UCan2NotificationWindowProc (not a class member by the way) is of the form:
LRESULT CALLBACK UCan2NotificationWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {}

Can someone spot a problem that might prohibit it from receiving
notifications?
Thanks in advance,
Dennis

// Module-level variables
HWND hNotificationWindow = NULL;
LPCTSTR NotificationClassName = "CUCan2NotificationWnd";
LPCTSTR NotificationWindowName = "UCan2 Notification Window";
ATOM NotificationClassAtom = 0;
HDEVNOTIFY hDeviceNotification = NULL;

extern HINSTANCE hUCan2ApiInstance;
// (Note: hUCan2ApiInstance is determined in a call to
AfxGetInstanceHandle() in the InitInstance member function of the
// class that the Visual Studio New Project Wizard created.)

DWORD CreateNotificationWindow( GUID InterfaceClassGuid ){
WNDCLASSEX WC;
WC.cbSize = sizeof(WNDCLASSEX);
WC.style = 0;
WC.lpfnWndProc = UCan2NotificationWindowProc;
WC.cbClsExtra = 0;
WC.cbWndExtra = 0;
WC.hInstance = hUCan2ApiInstance;
WC.hIcon = NULL;
WC.hCursor = NULL;
WC.hbrBackground = NULL;
WC.lpszMenuName = NULL;
WC.lpszClassName = NotificationClassName;
WC.hIconSm = NULL;

NotificationClassAtom = RegisterClassEx( &WC );
if( !NotificationClassAtom )
return GetLastError();

hNotificationWindow = CreateWindowEx(
0, // dwExStyle
NotificationClassName,
NotificationWindowName,
0, // dwStyle
0, // X
0, // Y
0, // Width
0, // Height
NULL, // hWndParent
NULL, // hMenu
NULL,
NULL // lpParam
);

DEV_BROADCAST_DEVICEINTERFACE filter;
ZeroMemory( &filter, sizeof(filter) );
filter.dbcc_size = sizeof(filter);
filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
filter.dbcc_classguid = InterfaceClassGuid;

hDeviceNotification = RegisterDeviceNotification(
hNotificationWindow,
&filter,
DEVICE_NOTIFY_WINDOW_HANDLE
);

DWORD dwError = ERROR_SUCCESS;

if(!hDeviceNotification)
{
dwError = GetLastError();
DestroyWindow( hNotificationWindow );
UnregisterClass( NotificationClassName, NULL );
}

return dwError;
}

Re: Notification Window In a Dll by cristalink

cristalink
Thu Dec 02 11:40:06 CST 2004


"db_from_mn" <dburns@rtessentials.com> wrote in message
news:X9-dnTAfq7FwvzLcRVn-2Q@comcast.com...
> I've been posting questions relate to this for a few days now. Yesterday I
> was criticized for not providing enough information. I always have mixed
> feelings about posting too much information, because I believe many will
> tire of reading, and move on.

True. Though you should provide enough info to have it answered, too.

> Below is my code for creating the window, where the
> UCan2NotificationWindowProc (not a class member by the way) is of the
form:
> LRESULT CALLBACK UCan2NotificationWindowProc(
> HWND hwnd,
> UINT uMsg,
> WPARAM wParam,
> LPARAM lParam) {}

It must be something like this:

switch( uMsg )
{
case WM_DEVICECHANGE:
onWmDeviceChange( wParam, *PDEV_BROADCAST_HDR( lParam ) );
return TRUE;
}

return DefWindowProc(...)

void onWmDeviceChange( WPARAM EventType, DEV_BROADCAST_HDR& Hdr )
{
if( EventType == DBT_DEVICEARRIVAL
|| EventType == DBT_DEVICEREMOVECOMPLETE )
{
if( &Hdr != NULL
&& Hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
{
DEV_BROADCAST_DEVICEINTERFACE& di =
*PDEV_BROADCAST_DEVICEINTERFACE( &Hdr );
if( di.dbcc_classguid == GUID_MY_INTERFACE )
{
bool isArrived = ( EventType == DBT_DEVICEARRIVAL );
Trace( ( isArrived ? _T("Arrived") : _T("Removed") ) <<
_T(" target device, name=[") << di.dbcc_name << _T("]") )
onDeviceChanged();
}
}
}
}

Make sure

- You have a message loop
- You use the same InterfaceClassGuid both in your app and driver
- You receive other WM_ messages in your UCan2NotificationWindowProc
- Your driver enables or disables the interface AFTER you registered for
notifications. If your driver already enabled the interface by the time you
registered, you won't receive DBT_DEVICEARRIVAL
- Check return values in your driver code
- Make sure you use PDO to register the interface

st = IoRegisterDeviceInterface( PhysicalDeviceObject,
&GUID_MY_INTERFACE , NULL, &m_ustrInterfaceName );
if( !NT_SUCCESS( st ) )
{
Trc( T1, "@%p *IoRegisterDeviceInterface() failed, st=%!STATUS!",
this, st );
return st;
}

Trc( T1, "@%p Registered device interface [%!USTR!]",
this, PUNICODE_STRING( m_ustrInterfaceName ) );

st = IoSetDeviceInterfaceState( m_ustrInterfaceName, TRUE );
if( !NT_SUCCESS( st ) )
{
Trc( T1, "@%p *IoSetDeviceInterfaceState() failed, st=%!STATUS!",
this, st );
return st;
}

--
http://www.firestreamer.com - NTBACKUP to DVD and DV



>
> Can someone spot a problem that might prohibit it from receiving
> notifications?
> Thanks in advance,
> Dennis
>
> // Module-level variables
> HWND hNotificationWindow = NULL;
> LPCTSTR NotificationClassName = "CUCan2NotificationWnd";
> LPCTSTR NotificationWindowName = "UCan2 Notification Window";
> ATOM NotificationClassAtom = 0;
> HDEVNOTIFY hDeviceNotification = NULL;
>
> extern HINSTANCE hUCan2ApiInstance;
> // (Note: hUCan2ApiInstance is determined in a call to
> AfxGetInstanceHandle() in the InitInstance member function of the
> // class that the Visual Studio New Project Wizard created.)
>
> DWORD CreateNotificationWindow( GUID InterfaceClassGuid ){
> WNDCLASSEX WC;
> WC.cbSize = sizeof(WNDCLASSEX);
> WC.style = 0;
> WC.lpfnWndProc = UCan2NotificationWindowProc;
> WC.cbClsExtra = 0;
> WC.cbWndExtra = 0;
> WC.hInstance = hUCan2ApiInstance;
> WC.hIcon = NULL;
> WC.hCursor = NULL;
> WC.hbrBackground = NULL;
> WC.lpszMenuName = NULL;
> WC.lpszClassName = NotificationClassName;
> WC.hIconSm = NULL;
>
> NotificationClassAtom = RegisterClassEx( &WC );
> if( !NotificationClassAtom )
> return GetLastError();
>
> hNotificationWindow = CreateWindowEx(
> 0, // dwExStyle
> NotificationClassName,
> NotificationWindowName,
> 0, // dwStyle
> 0, // X
> 0, // Y
> 0, // Width
> 0, // Height
> NULL, // hWndParent
> NULL, // hMenu
> NULL,
> NULL // lpParam
> );
>
> DEV_BROADCAST_DEVICEINTERFACE filter;
> ZeroMemory( &filter, sizeof(filter) );
> filter.dbcc_size = sizeof(filter);
> filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
> filter.dbcc_classguid = InterfaceClassGuid;
>
> hDeviceNotification = RegisterDeviceNotification(
> hNotificationWindow,
> &filter,
> DEVICE_NOTIFY_WINDOW_HANDLE
> );
>
> DWORD dwError = ERROR_SUCCESS;
>
> if(!hDeviceNotification)
> {
> dwError = GetLastError();
> DestroyWindow( hNotificationWindow );
> UnregisterClass( NotificationClassName, NULL );
> }
>
> return dwError;
> }
>
>



Re: Notification Window In a Dll by db_from_mn

db_from_mn
Thu Dec 02 14:10:18 CST 2004

Hello chrisalink:
I've reviewed you comments, and feel (pretty) confident that I've done
everything correctly, except for the message loop question. I did not
explicitly implement a message loop, but the UCan2NotificationWindowProc is
responding to basic Windows messages.
In a dll, where would the message loop be implemented? Note that I started
this project using Visual Studio's New Project Wizard, and I don't see
DllMain.
This may likely be the problem.

Thanks for the help,
Dennis



"cristalink" <cristalink@nospam.nospam> wrote in message
news:eQ6E5XJ2EHA.1300@TK2MSFTNGP14.phx.gbl...
>
> "db_from_mn" <dburns@rtessentials.com> wrote in message
> news:X9-dnTAfq7FwvzLcRVn-2Q@comcast.com...
>> I've been posting questions relate to this for a few days now. Yesterday
>> I
>> was criticized for not providing enough information. I always have mixed
>> feelings about posting too much information, because I believe many will
>> tire of reading, and move on.
>
> True. Though you should provide enough info to have it answered, too.
>
>> Below is my code for creating the window, where the
>> UCan2NotificationWindowProc (not a class member by the way) is of the
> form:
>> LRESULT CALLBACK UCan2NotificationWindowProc(
>> HWND hwnd,
>> UINT uMsg,
>> WPARAM wParam,
>> LPARAM lParam) {}
>
> It must be something like this:
>
> switch( uMsg )
> {
> case WM_DEVICECHANGE:
> onWmDeviceChange( wParam, *PDEV_BROADCAST_HDR( lParam ) );
> return TRUE;
> }
>
> return DefWindowProc(...)
>
> void onWmDeviceChange( WPARAM EventType, DEV_BROADCAST_HDR& Hdr )
> {
> if( EventType == DBT_DEVICEARRIVAL
> || EventType == DBT_DEVICEREMOVECOMPLETE )
> {
> if( &Hdr != NULL
> && Hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
> {
> DEV_BROADCAST_DEVICEINTERFACE& di =
> *PDEV_BROADCAST_DEVICEINTERFACE( &Hdr );
> if( di.dbcc_classguid == GUID_MY_INTERFACE )
> {
> bool isArrived = ( EventType == DBT_DEVICEARRIVAL );
> Trace( ( isArrived ? _T("Arrived") : _T("Removed") ) <<
> _T(" target device, name=[") << di.dbcc_name << _T("]") )
> onDeviceChanged();
> }
> }
> }
> }
>
> Make sure
>
> - You have a message loop
> - You use the same InterfaceClassGuid both in your app and driver
> - You receive other WM_ messages in your UCan2NotificationWindowProc
> - Your driver enables or disables the interface AFTER you registered for
> notifications. If your driver already enabled the interface by the time
> you
> registered, you won't receive DBT_DEVICEARRIVAL
> - Check return values in your driver code
> - Make sure you use PDO to register the interface
>
> st = IoRegisterDeviceInterface( PhysicalDeviceObject,
> &GUID_MY_INTERFACE , NULL, &m_ustrInterfaceName );
> if( !NT_SUCCESS( st ) )
> {
> Trc( T1, "@%p *IoRegisterDeviceInterface() failed, st=%!STATUS!",
> this, st );
> return st;
> }
>
> Trc( T1, "@%p Registered device interface [%!USTR!]",
> this, PUNICODE_STRING( m_ustrInterfaceName ) );
>
> st = IoSetDeviceInterfaceState( m_ustrInterfaceName, TRUE );
> if( !NT_SUCCESS( st ) )
> {
> Trc( T1, "@%p *IoSetDeviceInterfaceState() failed, st=%!STATUS!",
> this, st );
> return st;
> }
>
> --
> http://www.firestreamer.com - NTBACKUP to DVD and DV
>
>
>
>>
>> Can someone spot a problem that might prohibit it from receiving
>> notifications?
>> Thanks in advance,
>> Dennis
>>
>> // Module-level variables
>> HWND hNotificationWindow = NULL;
>> LPCTSTR NotificationClassName = "CUCan2NotificationWnd";
>> LPCTSTR NotificationWindowName = "UCan2 Notification Window";
>> ATOM NotificationClassAtom = 0;
>> HDEVNOTIFY hDeviceNotification = NULL;
>>
>> extern HINSTANCE hUCan2ApiInstance;
>> // (Note: hUCan2ApiInstance is determined in a call to
>> AfxGetInstanceHandle() in the InitInstance member function of the
>> // class that the Visual Studio New Project Wizard created.)
>>
>> DWORD CreateNotificationWindow( GUID InterfaceClassGuid ){
>> WNDCLASSEX WC;
>> WC.cbSize = sizeof(WNDCLASSEX);
>> WC.style = 0;
>> WC.lpfnWndProc = UCan2NotificationWindowProc;
>> WC.cbClsExtra = 0;
>> WC.cbWndExtra = 0;
>> WC.hInstance = hUCan2ApiInstance;
>> WC.hIcon = NULL;
>> WC.hCursor = NULL;
>> WC.hbrBackground = NULL;
>> WC.lpszMenuName = NULL;
>> WC.lpszClassName = NotificationClassName;
>> WC.hIconSm = NULL;
>>
>> NotificationClassAtom = RegisterClassEx( &WC );
>> if( !NotificationClassAtom )
>> return GetLastError();
>>
>> hNotificationWindow = CreateWindowEx(
>> 0, // dwExStyle
>> NotificationClassName,
>> NotificationWindowName,
>> 0, // dwStyle
>> 0, // X
>> 0, // Y
>> 0, // Width
>> 0, // Height
>> NULL, // hWndParent
>> NULL, // hMenu
>> NULL,
>> NULL // lpParam
>> );
>>
>> DEV_BROADCAST_DEVICEINTERFACE filter;
>> ZeroMemory( &filter, sizeof(filter) );
>> filter.dbcc_size = sizeof(filter);
>> filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
>> filter.dbcc_classguid = InterfaceClassGuid;
>>
>> hDeviceNotification = RegisterDeviceNotification(
>> hNotificationWindow,
>> &filter,
>> DEVICE_NOTIFY_WINDOW_HANDLE
>> );
>>
>> DWORD dwError = ERROR_SUCCESS;
>>
>> if(!hDeviceNotification)
>> {
>> dwError = GetLastError();
>> DestroyWindow( hNotificationWindow );
>> UnregisterClass( NotificationClassName, NULL );
>> }
>>
>> return dwError;
>> }
>>
>>
>
>



Re: Notification Window In a Dll by cristalink

cristalink
Thu Dec 02 14:40:17 CST 2004

Write a small normal app to verify your code works with the message loop.

You need to create a new thread somewhere in your dll, like DllMain or
wherever you register for WM_DEVICECHANGE. Create the window and register
inside that thread. Once done, run the message loop in the thread.

--
http://www.firestreamer.com - NTBACKUP to DVD and DV


"db_from_mn" <dburns@rtessentials.com> wrote in message
news:zPSdnT4OWf836zLcRVn-tw@comcast.com...
> Hello chrisalink:
> I've reviewed you comments, and feel (pretty) confident that I've done
> everything correctly, except for the message loop question. I did not
> explicitly implement a message loop, but the UCan2NotificationWindowProc
> is responding to basic Windows messages.
> In a dll, where would the message loop be implemented? Note that I started
> this project using Visual Studio's New Project Wizard, and I don't see
> DllMain.
> This may likely be the problem.
>
> Thanks for the help,
> Dennis
>
>
>
> "cristalink" <cristalink@nospam.nospam> wrote in message
> news:eQ6E5XJ2EHA.1300@TK2MSFTNGP14.phx.gbl...
>>
>> "db_from_mn" <dburns@rtessentials.com> wrote in message
>> news:X9-dnTAfq7FwvzLcRVn-2Q@comcast.com...
>>> I've been posting questions relate to this for a few days now. Yesterday
>>> I
>>> was criticized for not providing enough information. I always have mixed
>>> feelings about posting too much information, because I believe many will
>>> tire of reading, and move on.
>>
>> True. Though you should provide enough info to have it answered, too.
>>
>>> Below is my code for creating the window, where the
>>> UCan2NotificationWindowProc (not a class member by the way) is of the
>> form:
>>> LRESULT CALLBACK UCan2NotificationWindowProc(
>>> HWND hwnd,
>>> UINT uMsg,
>>> WPARAM wParam,
>>> LPARAM lParam) {}
>>
>> It must be something like this:
>>
>> switch( uMsg )
>> {
>> case WM_DEVICECHANGE:
>> onWmDeviceChange( wParam, *PDEV_BROADCAST_HDR( lParam ) );
>> return TRUE;
>> }
>>
>> return DefWindowProc(...)
>>
>> void onWmDeviceChange( WPARAM EventType, DEV_BROADCAST_HDR& Hdr )
>> {
>> if( EventType == DBT_DEVICEARRIVAL
>> || EventType == DBT_DEVICEREMOVECOMPLETE )
>> {
>> if( &Hdr != NULL
>> && Hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
>> {
>> DEV_BROADCAST_DEVICEINTERFACE& di =
>> *PDEV_BROADCAST_DEVICEINTERFACE( &Hdr );
>> if( di.dbcc_classguid == GUID_MY_INTERFACE )
>> {
>> bool isArrived = ( EventType == DBT_DEVICEARRIVAL );
>> Trace( ( isArrived ? _T("Arrived") : _T("Removed") ) <<
>> _T(" target device, name=[") << di.dbcc_name << _T("]") )
>> onDeviceChanged();
>> }
>> }
>> }
>> }
>>
>> Make sure
>>
>> - You have a message loop
>> - You use the same InterfaceClassGuid both in your app and driver
>> - You receive other WM_ messages in your UCan2NotificationWindowProc
>> - Your driver enables or disables the interface AFTER you registered for
>> notifications. If your driver already enabled the interface by the time
>> you
>> registered, you won't receive DBT_DEVICEARRIVAL
>> - Check return values in your driver code
>> - Make sure you use PDO to register the interface
>>
>> st = IoRegisterDeviceInterface( PhysicalDeviceObject,
>> &GUID_MY_INTERFACE , NULL, &m_ustrInterfaceName );
>> if( !NT_SUCCESS( st ) )
>> {
>> Trc( T1, "@%p *IoRegisterDeviceInterface() failed, st=%!STATUS!",
>> this, st );
>> return st;
>> }
>>
>> Trc( T1, "@%p Registered device interface [%!USTR!]",
>> this, PUNICODE_STRING( m_ustrInterfaceName ) );
>>
>> st = IoSetDeviceInterfaceState( m_ustrInterfaceName, TRUE );
>> if( !NT_SUCCESS( st ) )
>> {
>> Trc( T1, "@%p *IoSetDeviceInterfaceState() failed, st=%!STATUS!",
>> this, st );
>> return st;
>> }
>>
>> --
>> http://www.firestreamer.com - NTBACKUP to DVD and DV
>>
>>
>>
>>>
>>> Can someone spot a problem that might prohibit it from receiving
>>> notifications?
>>> Thanks in advance,
>>> Dennis
>>>
>>> // Module-level variables
>>> HWND hNotificationWindow = NULL;
>>> LPCTSTR NotificationClassName = "CUCan2NotificationWnd";
>>> LPCTSTR NotificationWindowName = "UCan2 Notification Window";
>>> ATOM NotificationClassAtom = 0;
>>> HDEVNOTIFY hDeviceNotification = NULL;
>>>
>>> extern HINSTANCE hUCan2ApiInstance;
>>> // (Note: hUCan2ApiInstance is determined in a call to
>>> AfxGetInstanceHandle() in the InitInstance member function of the
>>> // class that the Visual Studio New Project Wizard created.)
>>>
>>> DWORD CreateNotificationWindow( GUID InterfaceClassGuid ){
>>> WNDCLASSEX WC;
>>> WC.cbSize = sizeof(WNDCLASSEX);
>>> WC.style = 0;
>>> WC.lpfnWndProc = UCan2NotificationWindowProc;
>>> WC.cbClsExtra = 0;
>>> WC.cbWndExtra = 0;
>>> WC.hInstance = hUCan2ApiInstance;
>>> WC.hIcon = NULL;
>>> WC.hCursor = NULL;
>>> WC.hbrBackground = NULL;
>>> WC.lpszMenuName = NULL;
>>> WC.lpszClassName = NotificationClassName;
>>> WC.hIconSm = NULL;
>>>
>>> NotificationClassAtom = RegisterClassEx( &WC );
>>> if( !NotificationClassAtom )
>>> return GetLastError();
>>>
>>> hNotificationWindow = CreateWindowEx(
>>> 0, // dwExStyle
>>> NotificationClassName,
>>> NotificationWindowName,
>>> 0, // dwStyle
>>> 0, // X
>>> 0, // Y
>>> 0, // Width
>>> 0, // Height
>>> NULL, // hWndParent
>>> NULL, // hMenu
>>> NULL,
>>> NULL // lpParam
>>> );
>>>
>>> DEV_BROADCAST_DEVICEINTERFACE filter;
>>> ZeroMemory( &filter, sizeof(filter) );
>>> filter.dbcc_size = sizeof(filter);
>>> filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
>>> filter.dbcc_classguid = InterfaceClassGuid;
>>>
>>> hDeviceNotification = RegisterDeviceNotification(
>>> hNotificationWindow,
>>> &filter,
>>> DEVICE_NOTIFY_WINDOW_HANDLE
>>> );
>>>
>>> DWORD dwError = ERROR_SUCCESS;
>>>
>>> if(!hDeviceNotification)
>>> {
>>> dwError = GetLastError();
>>> DestroyWindow( hNotificationWindow );
>>> UnregisterClass( NotificationClassName, NULL );
>>> }
>>>
>>> return dwError;
>>> }
>>>
>>>
>>
>>
>
>



Re: Notification Window In a Dll by Pavel

Pavel
Thu Dec 02 19:43:33 CST 2004

The OP can start with any Visual C or SDK sample app that creates a normal
visible window. Just add your message handler, and run.
If it will work, the problem out of scope of this NG :)
--PA

"cristalink" <cristalink@nospam.nospam> wrote in message news:uzynj8K2EHA.4072@TK2MSFTNGP10.phx.gbl...
> Write a small normal app to verify your code works with the message loop.
>
> You need to create a new thread somewhere in your dll, like DllMain or
> wherever you register for WM_DEVICECHANGE. Create the window and register
> inside that thread. Once done, run the message loop in the thread.
>
> --
> http://www.firestreamer.com - NTBACKUP to DVD and DV
>
>
> "db_from_mn" <dburns@rtessentials.com> wrote in message
> news:zPSdnT4OWf836zLcRVn-tw@comcast.com...
> > Hello chrisalink:
> > I've reviewed you comments, and feel (pretty) confident that I've done
> > everything correctly, except for the message loop question. I did not
> > explicitly implement a message loop, but the UCan2NotificationWindowProc
> > is responding to basic Windows messages.
> > In a dll, where would the message loop be implemented? Note that I started
> > this project using Visual Studio's New Project Wizard, and I don't see
> > DllMain.
> > This may likely be the problem.
> >
> > Thanks for the help,
> > Dennis
> >
> >
> >
> > "cristalink" <cristalink@nospam.nospam> wrote in message
> > news:eQ6E5XJ2EHA.1300@TK2MSFTNGP14.phx.gbl...
> >>
> >> "db_from_mn" <dburns@rtessentials.com> wrote in message
> >> news:X9-dnTAfq7FwvzLcRVn-2Q@comcast.com...
> >>> I've been posting questions relate to this for a few days now. Yesterday
> >>> I
> >>> was criticized for not providing enough information. I always have mixed
> >>> feelings about posting too much information, because I believe many will
> >>> tire of reading, and move on.
> >>
> >> True. Though you should provide enough info to have it answered, too.
> >>
> >>> Below is my code for creating the window, where the
> >>> UCan2NotificationWindowProc (not a class member by the way) is of the
> >> form:
> >>> LRESULT CALLBACK UCan2NotificationWindowProc(
> >>> HWND hwnd,
> >>> UINT uMsg,
> >>> WPARAM wParam,
> >>> LPARAM lParam) {}
> >>
> >> It must be something like this:
> >>
> >> switch( uMsg )
> >> {
> >> case WM_DEVICECHANGE:
> >> onWmDeviceChange( wParam, *PDEV_BROADCAST_HDR( lParam ) );
> >> return TRUE;
> >> }
> >>
> >> return DefWindowProc(...)
> >>
> >> void onWmDeviceChange( WPARAM EventType, DEV_BROADCAST_HDR& Hdr )
> >> {
> >> if( EventType == DBT_DEVICEARRIVAL
> >> || EventType == DBT_DEVICEREMOVECOMPLETE )
> >> {
> >> if( &Hdr != NULL
> >> && Hdr.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
> >> {
> >> DEV_BROADCAST_DEVICEINTERFACE& di =
> >> *PDEV_BROADCAST_DEVICEINTERFACE( &Hdr );
> >> if( di.dbcc_classguid == GUID_MY_INTERFACE )
> >> {
> >> bool isArrived = ( EventType == DBT_DEVICEARRIVAL );
> >> Trace( ( isArrived ? _T("Arrived") : _T("Removed") ) <<
> >> _T(" target device, name=[") << di.dbcc_name << _T("]") )
> >> onDeviceChanged();
> >> }
> >> }
> >> }
> >> }
> >>
> >> Make sure
> >>
> >> - You have a message loop
> >> - You use the same InterfaceClassGuid both in your app and driver
> >> - You receive other WM_ messages in your UCan2NotificationWindowProc
> >> - Your driver enables or disables the interface AFTER you registered for
> >> notifications. If your driver already enabled the interface by the time
> >> you
> >> registered, you won't receive DBT_DEVICEARRIVAL
> >> - Check return values in your driver code
> >> - Make sure you use PDO to register the interface
> >>
> >> st = IoRegisterDeviceInterface( PhysicalDeviceObject,
> >> &GUID_MY_INTERFACE , NULL, &m_ustrInterfaceName );
> >> if( !NT_SUCCESS( st ) )
> >> {
> >> Trc( T1, "@%p *IoRegisterDeviceInterface() failed, st=%!STATUS!",
> >> this, st );
> >> return st;
> >> }
> >>
> >> Trc( T1, "@%p Registered device interface [%!USTR!]",
> >> this, PUNICODE_STRING( m_ustrInterfaceName ) );
> >>
> >> st = IoSetDeviceInterfaceState( m_ustrInterfaceName, TRUE );
> >> if( !NT_SUCCESS( st ) )
> >> {
> >> Trc( T1, "@%p *IoSetDeviceInterfaceState() failed, st=%!STATUS!",
> >> this, st );
> >> return st;
> >> }
> >>
> >> --
> >> http://www.firestreamer.com - NTBACKUP to DVD and DV
> >>
> >>
> >>
> >>>
> >>> Can someone spot a problem that might prohibit it from receiving
> >>> notifications?
> >>> Thanks in advance,
> >>> Dennis
> >>>
> >>> // Module-level variables
> >>> HWND hNotificationWindow = NULL;
> >>> LPCTSTR NotificationClassName = "CUCan2NotificationWnd";
> >>> LPCTSTR NotificationWindowName = "UCan2 Notification Window";
> >>> ATOM NotificationClassAtom = 0;
> >>> HDEVNOTIFY hDeviceNotification = NULL;
> >>>
> >>> extern HINSTANCE hUCan2ApiInstance;
> >>> // (Note: hUCan2ApiInstance is determined in a call to
> >>> AfxGetInstanceHandle() in the InitInstance member function of the
> >>> // class that the Visual Studio New Project Wizard created.)
> >>>
> >>> DWORD CreateNotificationWindow( GUID InterfaceClassGuid ){
> >>> WNDCLASSEX WC;
> >>> WC.cbSize = sizeof(WNDCLASSEX);
> >>> WC.style = 0;
> >>> WC.lpfnWndProc = UCan2NotificationWindowProc;
> >>> WC.cbClsExtra = 0;
> >>> WC.cbWndExtra = 0;
> >>> WC.hInstance = hUCan2ApiInstance;
> >>> WC.hIcon = NULL;
> >>> WC.hCursor = NULL;
> >>> WC.hbrBackground = NULL;
> >>> WC.lpszMenuName = NULL;
> >>> WC.lpszClassName = NotificationClassName;
> >>> WC.hIconSm = NULL;
> >>>
> >>> NotificationClassAtom = RegisterClassEx( &WC );
> >>> if( !NotificationClassAtom )
> >>> return GetLastError();
> >>>
> >>> hNotificationWindow = CreateWindowEx(
> >>> 0, // dwExStyle
> >>> NotificationClassName,
> >>> NotificationWindowName,
> >>> 0, // dwStyle
> >>> 0, // X
> >>> 0, // Y
> >>> 0, // Width
> >>> 0, // Height
> >>> NULL, // hWndParent
> >>> NULL, // hMenu
> >>> NULL,
> >>> NULL // lpParam
> >>> );
> >>>
> >>> DEV_BROADCAST_DEVICEINTERFACE filter;
> >>> ZeroMemory( &filter, sizeof(filter) );
> >>> filter.dbcc_size = sizeof(filter);
> >>> filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
> >>> filter.dbcc_classguid = InterfaceClassGuid;
> >>>
> >>> hDeviceNotification = RegisterDeviceNotification(
> >>> hNotificationWindow,
> >>> &filter,
> >>> DEVICE_NOTIFY_WINDOW_HANDLE
> >>> );
> >>>
> >>> DWORD dwError = ERROR_SUCCESS;
> >>>
> >>> if(!hDeviceNotification)
> >>> {
> >>> dwError = GetLastError();
> >>> DestroyWindow( hNotificationWindow );
> >>> UnregisterClass( NotificationClassName, NULL );
> >>> }
> >>>
> >>> return dwError;
> >>> }
> >>>
> >>>
> >>
> >>
> >
> >
>
>