Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use RegisterDeviceNotification() in windows service program?

291 views
Skip to first unread message

Lee, Myoung Ho

unread,
Oct 8, 2003, 6:18:26 AM10/8/03
to
Hi,

I'm using windows 2000 and VS .NET 2003.

I want to watch attaching/dettaching event of all USB memorys or CD-ROM
medias in my service program.

So I'm trying to use RegisterDeviceNotification() function but It do not
work.

my codes are;
---------------------------from----------------
myServiceMain()
{
HDEVNOTIFY hDevNotify = NULL;
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;

...
m_hss = RegisterServiceCtrlHandlerEx(szServiceName, myHandlerEx,
pvContext);
if ( m_hss != NULL)
{
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
hDevNotify = RegisterDeviceNotification( m_hss, &NotificationFilter,
DEVICE_NOTIFY_SERVICE_HANDLE);
//DEVICE_NOTIFY_ALL_INTERFACE_CLASSES for xp
if ( hDevNotify != NULL)
Debug("RegisterDeviceNotification success");
else
Debug("RegisterDeviceNotification return NULL");
}

...
} //end of myServiceMain

DWORD WINAPI myHandlerEx(DWORD dwControl, DWORD dwEventType, ... )
{
switch (dwControl) {
case SERVICE_CONTROL_STOP:
...
case SERVICE_CONTROL_SHUTDOWN:
...
case SERVICE_CONTROL_DEVICEEVENT: // I want this event!!!!
....
case SERVICE_CONTROL_POWEREVENT:
....
}
} // end of myHandlerEx

------------------till here-----------------------

MSDN says, service program can get device event by this. but
SERVICE_CONTROL_DEVICEEVENT

event not reached in my service control handler(myHandlerEx).

I can get SERVICE_CONTROL_SHUTDOWN or SERVICE_CONTROL_POWEREVENT event

and return value of RegisterDeviceNotification() is not NULL.

How can I get SERVICE_CONTROL_DEVICEEVENT event????


I hope you can understand my poor english.. :)

Lee.

Kobi Ben Tzvi

unread,
Oct 8, 2003, 4:54:47 PM10/8/03
to
Lee,

> I want to watch attaching/dettaching event of all USB memorys or CD-ROM
> medias in my service program.

> I can get SERVICE_CONTROL_SHUTDOWN or SERVICE_CONTROL_POWEREVENT event
> and return value of RegisterDeviceNotification() is not NULL.
> How can I get SERVICE_CONTROL_DEVICEEVENT event????

I think your problem is related to fact that you don't specify GUID to
indicate which class of device you wish to be notified about.

See,I think it is talking about same problem:
http://tinyurl.com/q875

--
Regards,
Kobi Ben Tzvi


"Lee, Myoung Ho" <mh...@digicaps.com> wrote in message
news:OiOg$VYjDH...@TK2MSFTNGP12.phx.gbl...

Lee, Myoung Ho

unread,
Oct 9, 2003, 1:19:12 AM10/9/03
to
Thanks for your response.

I specified GUID to GUID_DEVINTERFACE_CDROM but It still not work.

NotificationFilter.dbcc_classguid = CdRomClassGuid;

What should I do more??

Thanks in advance,

Lee.

"Kobi Ben Tzvi" <tsum...@hotmail.comREMOVETHIS> wrote in message
news:e6H3q5dj...@TK2MSFTNGP09.phx.gbl...

Kobi Ben Tzvi

unread,
Oct 9, 2003, 8:27:19 AM10/9/03
to
Lee,

> I specified GUID to GUID_DEVINTERFACE_CDROM but It still not work.
> NotificationFilter.dbcc_classguid = CdRomClassGuid;
> What should I do more??

I suggest you do some research on http://groups.google.com , try looking for
"SERVICE_CONTROL_DEVICEEVENT" and see if you get clues. Unfortunately I
don't have USB cd-rom or disk on key device to check your code.

--
Regards,
Kobi Ben Tzvi


"Lee, Myoung Ho" <mh...@digicaps.com> wrote in message

news:e8xvfTij...@tk2msftngp13.phx.gbl...

0 new messages