From: adorable.rajesh on
I am trying to get SERVICE_CONTROL_DEVICEEVENT notification in a NT
Service for CD/DVD ROM. The procedure I am following to code the
service is mentioned below :-

1) I have written a NT Service in C++ using Win32 APIs.
2) I am providing the SERVICE_STATUS.dwControlsAccepted as
SERVICE_ACCEPT_HARDWAREPROFILECHANGE. The code snippet is presented
below :-

ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|
SERVICE_ACCEPT_HARDWAREPROFILECHANGE|
SERVICE_ACCEPT_PARAMCHANGE|SERVICE_ACCEPT_POWEREVENT;

3) Then I invoke SetServiceStatus API which completes successfully. I
have verified this.

4) Then I invoke RegisterDeviceNotification API with proper arguments.
I provide the DEV_BROADCAST_DEVICEINTERFACE.dbcc_classguid =
GUID_DEVINTERFACE_CDROM. The complete code snippet is provided
below :-

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
wchar_t szMsg[80];

ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size =
sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
//NotificationFilter.dbcc_classguid =
GUID_DEVINTERFACE_USBSTOR;
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_CDROM;
//NotificationFilter.dbcc_classguid =
GUID_DEVINTERFACE_MEDIUMCHANGER;

HDEVNOTIFY hDevNotify =
RegisterDeviceNotification( sshStatusHandle,
&NotificationFilter,
DEVICE_NOTIFY_SERVICE_HANDLE);

if(!hDevNotify)
{
wsprintf(szMsg, L"RegisterDeviceNotification failed: %d\n",
GetLastError());
MessageBox(NULL, szMsg, L"Registration", MB_OK);
return FALSE;
}
else
{
MessageBox(NULL,L"RegisterDeviceNotification
Successful",L"Information",MB_OK);
}


5) RegisterDeviceNotification API always completes successfully. But I
dont receive SERVICE_CONTROL_DEVICEEVENT notification in my HandlerEx
function. I have tested this for Windows XP Professional SP2 and
Windows 2000 Professional SP4, but I did not receive
SERVICE_CONTROL_DEVICEEVENT notification.

I have also tried to use GUID_DEVINTERFACE_VOLUME,
GUID_DEVINTERFACE_PARTITION, but all in vain. I still dont receive any
SERVICE_CONTROL_DEVICEEVENT notification.

6) If I change the NotificationFilter.dbcc_classguid =
GUID_DEVINTERFACE_USBSTOR, then I start receiving
SERVICE_CONTROL_DEVICEEVENT notifications whenever I insert a USB Mass
Storage Device into the machine. I have defined the
GUID_DEVINTERFACE_USBSTOR my self using DEFINE_GUID macro, but it
works absolutely fine.

7) Kindly help me realise why I am not able to receive this
SERVICE_CONTROL_DEVICEEVENT notification. Do I have to use any other
GUID for CD/DVD ROM's?? Kindly let me know the GUIDs if possible.

NOTE :- I also built one Window Application to capture WM_DEVICECHANGE
notification. It works absolutely fine for CD ROM and I receive
notifications for CD Insert/Eject correctly.

But the problem is that I have to use NT Service to detect the same.
Kindly let me know what I am doing wrong.

Thanks
CoolAvenger

From: adorable.rajesh on
On Nov 7, 10:22 am, adorable.raj...(a)gmail.com wrote:
> I am trying to get SERVICE_CONTROL_DEVICEEVENT notification in a NT
> Service for CD/DVD ROM. The procedure I am following to code the
> service is mentioned below :-
>
> 1) I have written a NT Service in C++ using Win32 APIs.
> 2) I am providing the SERVICE_STATUS.dwControlsAccepted as
> SERVICE_ACCEPT_HARDWAREPROFILECHANGE. The code snippet is presented
> below :-
>
> ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|
> SERVICE_ACCEPT_HARDWAREPROFILECHANGE|
> SERVICE_ACCEPT_PARAMCHANGE|SERVICE_ACCEPT_POWEREVENT;
>
> 3) Then I invoke SetServiceStatus API which completes successfully. I
> have verified this.
>
> 4) Then I invoke RegisterDeviceNotification API with proper arguments.
> I provide the DEV_BROADCAST_DEVICEINTERFACE.dbcc_classguid =
> GUID_DEVINTERFACE_CDROM. The complete code snippet is provided
> below :-
>
> DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
> wchar_t szMsg[80];
>
> ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
> NotificationFilter.dbcc_size =
> sizeof(DEV_BROADCAST_DEVICEINTERFACE);
> NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
> //NotificationFilter.dbcc_classguid =
> GUID_DEVINTERFACE_USBSTOR;
> NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_CDROM;
> //NotificationFilter.dbcc_classguid =
> GUID_DEVINTERFACE_MEDIUMCHANGER;
>
> HDEVNOTIFY hDevNotify =
> RegisterDeviceNotification( sshStatusHandle,
> &NotificationFilter,
> DEVICE_NOTIFY_SERVICE_HANDLE);
>
> if(!hDevNotify)
> {
> wsprintf(szMsg, L"RegisterDeviceNotification failed: %d\n",
> GetLastError());
> MessageBox(NULL, szMsg, L"Registration", MB_OK);
> return FALSE;
> }
> else
> {
> MessageBox(NULL,L"RegisterDeviceNotification
> Successful",L"Information",MB_OK);
> }
>
> 5) RegisterDeviceNotification API always completes successfully. But I
> dont receive SERVICE_CONTROL_DEVICEEVENT notification in my HandlerEx
> function. I have tested this for Windows XP Professional SP2 and
> Windows 2000 Professional SP4, but I did not receive
> SERVICE_CONTROL_DEVICEEVENT notification.
>
> I have also tried to use GUID_DEVINTERFACE_VOLUME,
> GUID_DEVINTERFACE_PARTITION, but all in vain. I still dont receive any
> SERVICE_CONTROL_DEVICEEVENT notification.
>
> 6) If I change the NotificationFilter.dbcc_classguid =
> GUID_DEVINTERFACE_USBSTOR, then I start receiving
> SERVICE_CONTROL_DEVICEEVENT notifications whenever I insert a USB Mass
> Storage Device into the machine. I have defined the
> GUID_DEVINTERFACE_USBSTOR my self using DEFINE_GUID macro, but it
> works absolutely fine.
>
> 7) Kindly help me realise why I am not able to receive this
> SERVICE_CONTROL_DEVICEEVENT notification. Do I have to use any other
> GUID for CD/DVD ROM's?? Kindly let me know the GUIDs if possible.
>
> NOTE :- I also built one Window Application to capture WM_DEVICECHANGE
> notification. It works absolutely fine for CD ROM and I receive
> notifications for CD Insert/Eject correctly.
>
> But the problem is that I have to use NT Service to detect the same.
> Kindly let me know what I am doing wrong.
>
> Thanks
> CoolAvenger

Hi Once Again,

Kindly reply urgently if possible.

Thanks Once Again
CoolAvenger