WM_DEVICECHANGE never received for CD (DBT_DEVICEREMOVECOMPLETE & DBT_DEVICEARRIVAL)

David L 161 Reputation points
2021-02-20T16:46:40.35+00:00

Hello
My program that detects the CD removal and insertion via WM_DEVICECHANGE | DBT_DEVICEREMOVECOMPLETE and WM_DEVICECHANGE | DBT_DEVICEARRIVAL works perfectly on my desktop computer (Windows 10), but the WM_DEVICECHANGE is never received with the same program by a mini PC (Windows 10) to which is connected a laptop SATA CD reader (there is an extension SATA connector in the mini). The CD reader is recognized as such by the PC, it plays audio CD, read CD-ROM, etc... but no WM_DEVICECHANGE is triggered when a CD is ejected or inserted.

Is it a known problem? Did I miss something?
Thanks David

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,675 questions
0 comments No comments
{count} votes

8 answers

Sort by: Most helpful
  1. Castorix31 86,061 Reputation points
    2021-02-20T17:58:48.153+00:00

    Maybe you can try RegisterDeviceNotification, although it is usually not needed (Detecting Media Insertion or Removal)

    0 comments No comments

  2. David L 161 Reputation points
    2021-02-20T17:59:57.333+00:00

    I'm going to try that, thanks again @Castorix31 , always there to help!

    0 comments No comments

  3. David L 161 Reputation points
    2021-02-20T18:34:57.68+00:00

    I tried

        DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
        ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
        NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
        NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
        NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_CDROM;
    
        HDEVNOTIFY hDeviceNotify = RegisterDeviceNotification(hWnd,&NotificationFilter,DEVICE_NOTIFY_WINDOW_HANDLE);
        if (NULL == hDeviceNotify)
        {
            err_AddErreur(L"RegisterDeviceNotification");
            return FALSE;
        }
    

    with "DEFINE_GUID(GUID_DEVINTERFACE_CDROM, 0x53f56308L, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);". I found it in ntddstor.h.

    But it doesn't change a thing, my breakpoint just after "WM_DEVICECHANGE:" is never reached when I eject or insert a CD.


  4. David L 161 Reputation points
    2021-02-20T19:36:04.35+00:00

    70209-screenshot-117.png

    The interface is in French, but I guess you see that it is the disc section of the computer manager.


  5. David L 161 Reputation points
    2021-02-20T19:51:44.143+00:00

    While testing, I just saw that if I eject the CD, the WM_DEVICECHANGE is not triggered, but after that, if I try to play the CD then the WM_DEVICECHANGE breakpoint is reached. If the CD is playing while the CD is ejected, the notification is triggered too.
    So the problem is when the CD is on idle. And so it never sends the notification if a CD is inserted.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.