Can get only USB device insertion/removal and not IDE CD/DVD in WinXP Service
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Can get only USB device insertion/removal and not IDE CD/DVD in WinXP Service

Threaded View

  1. #1
    Join Date
    May 2008
    Posts
    1

    Question Can get only USB device insertion/removal and not IDE CD/DVD in WinXP Service

    Hello,
    I'm writing a service for the WinXP OS. My need is to get notification about insertion and removal of USB disks and notification on media change in CD/DVD. I've used the RegisterDeviceNotification as stated within the MSDN with DEVICE_NOTIFY_ALL_INTERFACE_CLASSES but I still receive only nitification about USB and not for CD/DVD.
    Here is the relevant part of the ServiceMain:

    Code:
    VOID ServiceMain(DWORD argc, char* argv[]) {
    
        serviceStatusHandle = RegisterServiceCtrlHandlerEx((LPWSTR)SERVICE_NAME, (LPHANDLER_FUNCTION_EX) ServiceCtrlHandler, 0);
        OutputDebugString(TEXT("Registering Service Ctrl Handler"));
       
    
        if (!serviceStatusHandle) {
            terminateService(GetLastError());
            return;
        }
    
        BOOL success = UpdateSCMStatus(SERVICE_START_PENDING,
                    NO_ERROR, 0, 1, 5000);
        if (!success) {
            terminateService(GetLastError());
            return;
        }
    
    
        ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
        NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
        NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    
        hDevNotify = RegisterDeviceNotification(
                serviceStatusHandle,
                &NotificationFilter,
                DEVICE_NOTIFY_SERVICE_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
               
        if (hDevNotify == NULL) OutputDebugString(TEXT("Registering device notification: error")    );
        else OutputDebugString(TEXT("Registering device notification: success"));
    
    ...
    
    }
    And here is the relevant part of the ServiceCtrlHandler:

    Code:
    VOID ServiceCtrlHandler(DWORD controlCode, DWORD evtype, PVOID evdata, PVOID Context) {
        BOOL success;
        DWORD threadId;
       
        switch(controlCode) {
            case SERVICE_CONTROL_DEVICEEVENT:
                OutputDebugString(TEXT("SERVICE_CONTROL_DEVICEEVENT"));
                DeviceEventNotify(evtype, evdata);
                break;
    ...
    }
    Using DebugView I see that there are no errors when registering device notification, but I have DEVICEEVENT only when I insert or remove an usb device, instead if I eject or load a CD/DVD nothing happens.

    I'll keep on trying, but every help will be very appreciate, because I don't know what to do more.

    Regards,
    ale
    Last edited by PeejAvery; May 28th, 2008 at 10:18 AM. Reason: Fixed code tags.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center