Jim Cavalaris [MS]
2003-07-14 18:23:14 UTC
you cannot register for notification of DBT_DEVTYP_VOLUME events.
RegisterDeviceNotification will always fail for this type of
notification filter. DBT_DEVTYP_VOLUME type messages are
automatically broadcast to top-level windows only, for compatibility
with Windows 9x systems. they are not sent to NT services.
for a service to receive any device events at all via its control
handler, the service must register a HandlerEx control handler
using RegisterServiceCtrlHandlerEx:
HandlerEx:
http://msdn.microsoft.com/library/en-us/dllproc/base/handlerex.asp
RegisterServiceCtrlHandlerEx:
http://msdn.microsoft.com/library/en-us/dllproc/base/registerservicectrlhandlerex.asp
to receive volume arrival and removal events, register for
device interface notification using the volume device interface
class GUID.
use a DEV_BROADCAST_DEVICEINTERFACE structure for the
NotificationFilter (dbcc_devicetype must be set to
DBT_DEVTYP_DEVICEINTERFACE), and set the dbcc_classguid field to
GUID_DEVINTERFACE_VOLUME.
on volume arrivals and removals, you service's HandlerEx routine
will receive SERVICE_CONTROL_DEVICEEVENT controls with an EventType
of DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. check the type
of the accompanying data structure to verify it is the expected
DBT_DEVTYP_DEVICEINTERFACE. the dbcc_name field of the
DEV_BROADCAST_DEVICEINTERFACE strcuture will specify a path that
can be used to access the volume (note that this path is always
supplied as a Unicode string, even for services compiled as ANSI.)
hope this helps,
jim.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
RegisterDeviceNotification will always fail for this type of
notification filter. DBT_DEVTYP_VOLUME type messages are
automatically broadcast to top-level windows only, for compatibility
with Windows 9x systems. they are not sent to NT services.
for a service to receive any device events at all via its control
handler, the service must register a HandlerEx control handler
using RegisterServiceCtrlHandlerEx:
HandlerEx:
http://msdn.microsoft.com/library/en-us/dllproc/base/handlerex.asp
RegisterServiceCtrlHandlerEx:
http://msdn.microsoft.com/library/en-us/dllproc/base/registerservicectrlhandlerex.asp
to receive volume arrival and removal events, register for
device interface notification using the volume device interface
class GUID.
use a DEV_BROADCAST_DEVICEINTERFACE structure for the
NotificationFilter (dbcc_devicetype must be set to
DBT_DEVTYP_DEVICEINTERFACE), and set the dbcc_classguid field to
GUID_DEVINTERFACE_VOLUME.
on volume arrivals and removals, you service's HandlerEx routine
will receive SERVICE_CONTROL_DEVICEEVENT controls with an EventType
of DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. check the type
of the accompanying data structure to verify it is the expected
DBT_DEVTYP_DEVICEINTERFACE. the dbcc_name field of the
DEV_BROADCAST_DEVICEINTERFACE strcuture will specify a path that
can be used to access the volume (note that this path is always
supplied as a Unicode string, even for services compiled as ANSI.)
hope this helps,
jim.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
I have been trying and failing to use RegisterDeviceNotification() from
within a service on Win2K. I am calling it as prescribed to connect to
//dbdi is a DEV_BROADCAST_VOLUME
memset(&dbdi, 0, sizeof(dbdi));
dbdi.dbcv_size = sizeof(dbdi);
dbdi.dbcv_devicetype = DBT_DEVTYP_VOLUME;
dbdi.dbcv_unitmask = (1 << 3) | (1 << 5); //get drives D and F for
testingwithin a service on Win2K. I am calling it as prescribed to connect to
//dbdi is a DEV_BROADCAST_VOLUME
memset(&dbdi, 0, sizeof(dbdi));
dbdi.dbcv_size = sizeof(dbdi);
dbdi.dbcv_devicetype = DBT_DEVTYP_VOLUME;
dbdi.dbcv_unitmask = (1 << 3) | (1 << 5); //get drives D and F for
.. these are removable (cdrom and zip) drives on my system
//twiddling this value has not helped ...
dbdi.dbcv_flags = DBTF_MEDIA;
m_hDevNotify = RegisterDeviceNotification(m_hServiceStatus, &dbdi,
DEVICE_NOTIFY_SERVICE_HANDLE);
//always returns zero...
if(!m_hDevNotify)
DWORD dwErr = GetLastError();
dwErr is always 13, ERROR_INVALID_DATA.
Is there anyone on planet Earth who has successfully called this function
from inside a *service* EXE?
//twiddling this value has not helped ...
dbdi.dbcv_flags = DBTF_MEDIA;
m_hDevNotify = RegisterDeviceNotification(m_hServiceStatus, &dbdi,
DEVICE_NOTIFY_SERVICE_HANDLE);
//always returns zero...
if(!m_hDevNotify)
DWORD dwErr = GetLastError();
dwErr is always 13, ERROR_INVALID_DATA.
Is there anyone on planet Earth who has successfully called this function
from inside a *service* EXE?