|
-
January 4th, 2010, 08:28 PM
#1
Problem detecting DBT_DEVTYP_VOLUME
Hello,
I've made a service that *should* detect when a usb flash drive is plugged in. The service does detect something, but I can't retrieve information from the volume. I'm not sure what's wrong, probably the cast.
Here's what I have:
Code:
//on ServiceMain
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_VOLUME;
m_hDevNotify = RegisterDeviceNotification(m_hServiceStatus, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE);
Code:
inline void Handler(DWORD dwOpcode,DWORD evtype, PVOID evdata, PVOID Context)
{
switch (dwOpcode)
{
...
case SERVICE_CONTROL_DEVICEEVENT:
OutputDebugString(L"SERVICE_CONTROL_DEVICEEVENT");
DeviceEventNotify(evtype, evdata);
break;
....
Code:
BOOLEAN DeviceEventNotify(DWORD evtype, PVOID evdata)
{
if (DBT_DEVICEARRIVAL == evtype || DBT_DEVICEREMOVECOMPLETE == evtype)
{
DEV_BROADCAST_VOLUME *volume = (DEV_BROADCAST_VOLUME *)evdata;
if (volume->dbcv_devicetype != DBT_DEVTYP_VOLUME)
{
OutputDebugString(L"Not a volume");
return FALSE;
}
My function always returns FALSE. I have this code, with some minor modifications working in a simple GUI application. But I need this functionality in a service. :\
-
January 4th, 2010, 10:19 PM
#2
Re: Problem detecting DBT_DEVTYP_VOLUME
Try changing this...
Code:
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_VOLUME;
to this...
;
-
January 5th, 2010, 02:16 PM
#3
Re: Problem detecting DBT_DEVTYP_VOLUME
Same result. 
I add this:
Code:
if (pHdr->dbch_devicetype != DBT_DEVTYP_VOLUME)
{
std::wstring my_string = format("TYPE: %x", pHdr->dbch_devicetype);
OutputDebugString(my_string.c_str());
return FALSE;
}
Output:
It's not the flash drive problem since my GUI app detects it just fine. :\
-
January 5th, 2010, 10:36 PM
#4
Re: Problem detecting DBT_DEVTYP_VOLUME
A quote from this thread
Using DBT_DEVTYP_VOLUME in a service is trick since it is a basic
broadcast notification which are sent to top level windows only.
If a service creates a Windows to receive this, it works only if
the service is running in the same session as the logged on user.
So, it will never work under Vista and under XP only for the first
logged on user.
-
January 6th, 2010, 05:15 AM
#5
Re: Problem detecting DBT_DEVTYP_VOLUME
Thanks Bob. Unfortunately you're the bearer of bad news (no, you'll not be shot ). I'll have to rewrite my service and make an extra program to be my usb monitor and communicate with the service.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|