CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968

    How to monitor mount points via GUID_IO_VOLUME_MOUNT

    Does anyone know how to get notification when a mount point is created?
    I've tried the following code, but I get error 1066 from the RegisterDeviceNotification API.


    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;
    }
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: How to monitor mount points via GUID_IO_VOLUME_MOUNT

    No sure, but maybe your service control handler is called (synchronously) by RegisterDeviceNotification, and that you fail to handle that notification correctly (ex. you return an 'invalid' return value)?

    - petter

  3. #3
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968

    Re: How to monitor mount points via GUID_IO_VOLUME_MOUNT

    This code is called before any threads are called.
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured