From: Axter on
How can I use GUID_IO_VOLUME_MOUNT to detect when a mount point is created?

Is there any example code?
I've tried the following code, but I get error 1066 when calling
RegisterDeviceNotification.

BOOL RegisterDevBroadcastHandle(const std::string& VolumeName) //VolumeName
in following format \\.\C:
{
SERVICE_STATUS_HANDLE &theServiceStatusHandle = serviceStatusHandle;
HANDLE dbch_handle = CreateFileA(VolumeName.c_str(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (dbch_handle == INVALID_HANDLE_VALUE)
{
LogEvent("CreateFileA(%s) failed (hndl): %lu.", VolumeName.c_str(),
GetLastError());
return FALSE;
}
DEV_BROADCAST_HANDLE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbch_size = sizeof(NotificationFilter);
NotificationFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
NotificationFilter.dbch_eventguid = GUID_IO_VOLUME_MOUNT;
NotificationFilter.dbch_handle = dbch_handle;

//The following line produces error 1066
HDEVNOTIFY hDevNotify = RegisterDeviceNotification( theServiceStatusHandle,
&NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE |
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);

if(!hDevNotify)
{
CloseHandle(dbch_handle);
LogEvent("RegisterDeviceNotification failed (hndl): %lu; (%s), %i",
GetLastError(), VolumeName.c_str(), (glbl_currentServiceRunningState ==
SERVICE_RUNNING));
return FALSE;
}

OpenVolumes[VolumeName] = dbch_handle;
ArrayOfHdevnotify.push_back(hDevNotify);
return TRUE;
}

Does anyone know how to get this to work?
--
-----------------------------------------------
Top Ten Expert in Experts-Exchange C++ and MFC topic area.
http://www.experts-exchange.com/Cplusplus
------------------------------------------------