Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WM_DEVICECHANGE Problem [SOLVED]

WM_DEVICECHANGE Problem [SOLVED]

Scheduled Pinned Locked Moved C / C++ / MFC
helpperformance
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goldenrose9
    wrote on last edited by
    #1

    LRESULT CALLBACK devDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {

    switch(msg)
    {
    	case WM\_DEVICECHANGE:
    		PDEV\_BROADCAST\_VOLUME pVol = (PDEV\_BROADCAST\_VOLUME)lParam;
    		switch(wParam)
    		{
    		case DBT\_DEVICEARRIVAL:
    			MessageBox(NULL,\_T("FOUND"), \_T(""),MB\_OK);
    			break;
    		case DBT\_DEVICEREMOVECOMPLETE:
    			MessageBox(NULL,\_T("REMOVED"), \_T(""),MB\_OK);
    			break;
    		}
    	break;
    }
    return FALSE;
    

    }

    While Inserting memory card reader DBT_DEVICEARRIVAL notifies about Four Removable Drives (O,P,Q,R Drives), But while removing memory card reader DBT_DEVICEREMOVECOMPLETE notifies about only ONE Removable Drive (O Drive). Why DBT_DEVICEREMOVECOMPLETE does not notifies about other Three removable drives ( P,Q,R Drives). Help :confused:

    Some Day I Will Prove MySelf :: GOLD

    modified on Monday, March 7, 2011 5:43 AM

    O 1 Reply Last reply
    0
    • G goldenrose9

      LRESULT CALLBACK devDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
      {

      switch(msg)
      {
      	case WM\_DEVICECHANGE:
      		PDEV\_BROADCAST\_VOLUME pVol = (PDEV\_BROADCAST\_VOLUME)lParam;
      		switch(wParam)
      		{
      		case DBT\_DEVICEARRIVAL:
      			MessageBox(NULL,\_T("FOUND"), \_T(""),MB\_OK);
      			break;
      		case DBT\_DEVICEREMOVECOMPLETE:
      			MessageBox(NULL,\_T("REMOVED"), \_T(""),MB\_OK);
      			break;
      		}
      	break;
      }
      return FALSE;
      

      }

      While Inserting memory card reader DBT_DEVICEARRIVAL notifies about Four Removable Drives (O,P,Q,R Drives), But while removing memory card reader DBT_DEVICEREMOVECOMPLETE notifies about only ONE Removable Drive (O Drive). Why DBT_DEVICEREMOVECOMPLETE does not notifies about other Three removable drives ( P,Q,R Drives). Help :confused:

      Some Day I Will Prove MySelf :: GOLD

      modified on Monday, March 7, 2011 5:43 AM

      O Offline
      O Offline
      Ozer Karaagac
      wrote on last edited by
      #2

      All bit mask fields of removed units in pVol->dbcv_unitmask may come in one turn. You had also better check (pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME) like below.

      ...
      case WM_DEVICECHANGE:
      {
      PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME)lParam;
      switch(wParam)
      {
      case DBT_DEVICEARRIVAL:
      {
      if(pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME)
      {
      pVol->dbcv_unitmask; // test this mask for one or more volume letters (bit flags)
      MessageBox(NULL,_T("FOUND"), _T(""),MB_OK);
      }
      }
      break;
      case DBT_DEVICEREMOVECOMPLETE:
      {
      if(pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME)
      {
      pVol->dbcv_unitmask; // test this mask for one or more volume letters
      // may be consisting of more than one bit flag (ORed together)

            MessageBox(NULL,\_T("REMOVED"), \_T(""),MB\_OK);
          }
        }
        break;
      

      }
      break;
      ...

      G 1 Reply Last reply
      0
      • O Ozer Karaagac

        All bit mask fields of removed units in pVol->dbcv_unitmask may come in one turn. You had also better check (pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME) like below.

        ...
        case WM_DEVICECHANGE:
        {
        PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME)lParam;
        switch(wParam)
        {
        case DBT_DEVICEARRIVAL:
        {
        if(pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME)
        {
        pVol->dbcv_unitmask; // test this mask for one or more volume letters (bit flags)
        MessageBox(NULL,_T("FOUND"), _T(""),MB_OK);
        }
        }
        break;
        case DBT_DEVICEREMOVECOMPLETE:
        {
        if(pVol->dbcv_devicetype == DBT_DEVTYP_VOLUME)
        {
        pVol->dbcv_unitmask; // test this mask for one or more volume letters
        // may be consisting of more than one bit flag (ORed together)

              MessageBox(NULL,\_T("REMOVED"), \_T(""),MB\_OK);
            }
          }
          break;
        

        }
        break;
        ...

        G Offline
        G Offline
        goldenrose9
        wrote on last edited by
        #3

        this code is not notifying neither DEVICE_ARRIVAL nor DEVICE REMOVAL.

        Some Day I Will Prove MySelf :: GOLD

        O 1 Reply Last reply
        0
        • G goldenrose9

          this code is not notifying neither DEVICE_ARRIVAL nor DEVICE REMOVAL.

          Some Day I Will Prove MySelf :: GOLD

          O Offline
          O Offline
          Ozer Karaagac
          wrote on last edited by
          #4

          Does your device generate something other than DBT_DEVTYP_VOLUME as dbcv_devicetype member of the structure? Because this is the only difference from your code snippet above. You can inspect it by setting a break point on that line if you would like to.

          G 1 Reply Last reply
          0
          • O Ozer Karaagac

            Does your device generate something other than DBT_DEVTYP_VOLUME as dbcv_devicetype member of the structure? Because this is the only difference from your code snippet above. You can inspect it by setting a break point on that line if you would like to.

            G Offline
            G Offline
            goldenrose9
            wrote on last edited by
            #5

            Ozer Karaagac wrote:

            Does your device generate something other than DBT_DEVTYP_VOLUME as dbcv_devicetype member of the structure

            dbcv_devicetype = 2 When i insert the memory card reader DBT_DEVICEARRIVAL detect four drives (O,P,Q,R) but when memory card is removed DBT_DEVICEREMOVECOMPLTE detect only one drive removed from system (O drive), why other three drives is not notified. (P,Q,R Drives)

            Some Day I Will Prove MySelf :: GOLD

            O 1 Reply Last reply
            0
            • G goldenrose9

              Ozer Karaagac wrote:

              Does your device generate something other than DBT_DEVTYP_VOLUME as dbcv_devicetype member of the structure

              dbcv_devicetype = 2 When i insert the memory card reader DBT_DEVICEARRIVAL detect four drives (O,P,Q,R) but when memory card is removed DBT_DEVICEREMOVECOMPLTE detect only one drive removed from system (O drive), why other three drives is not notified. (P,Q,R Drives)

              Some Day I Will Prove MySelf :: GOLD

              O Offline
              O Offline
              Ozer Karaagac
              wrote on last edited by
              #6

              DBT_DEVTYP_VOLUME as defined 2 already. Could you also inspect dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE, it should be occurred only once (according to you)?

              G 1 Reply Last reply
              0
              • O Ozer Karaagac

                DBT_DEVTYP_VOLUME as defined 2 already. Could you also inspect dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE, it should be occurred only once (according to you)?

                G Offline
                G Offline
                goldenrose9
                wrote on last edited by
                #7

                Ozer Karaagac wrote:

                dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE

                is 245760. and this is occurred only once.

                Some Day I Will Prove MySelf :: GOLD

                O 1 Reply Last reply
                0
                • G goldenrose9

                  Ozer Karaagac wrote:

                  dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE

                  is 245760. and this is occurred only once.

                  Some Day I Will Prove MySelf :: GOLD

                  O Offline
                  O Offline
                  Ozer Karaagac
                  wrote on last edited by
                  #8

                  Well, 245760 = 0x3c000 in hex = 111100000000000000 in binary. 111100000000000000 RQPONMLKJIHGFEDCBA Which means that you got notifications for all 4 volumes. You should test its bit flags.

                  DWORD dwTestMask = 1;
                  char archVols[32];
                  int nCount = 0;

                  for(int i = 0; i < 26; i++)
                  {
                  if(pVol->dbcv_unitmask & dwTestMask)
                  archVols[nCount++] = 'A' + i;

                  dwTestMask <<= 1;
                  

                  }

                  You will receive array of volume letters in archVols. This notifications may or may not be occurred one per volume.

                  G 1 Reply Last reply
                  0
                  • O Ozer Karaagac

                    Well, 245760 = 0x3c000 in hex = 111100000000000000 in binary. 111100000000000000 RQPONMLKJIHGFEDCBA Which means that you got notifications for all 4 volumes. You should test its bit flags.

                    DWORD dwTestMask = 1;
                    char archVols[32];
                    int nCount = 0;

                    for(int i = 0; i < 26; i++)
                    {
                    if(pVol->dbcv_unitmask & dwTestMask)
                    archVols[nCount++] = 'A' + i;

                    dwTestMask <<= 1;
                    

                    }

                    You will receive array of volume letters in archVols. This notifications may or may not be occurred one per volume.

                    G Offline
                    G Offline
                    goldenrose9
                    wrote on last edited by
                    #9

                    thanx, it worked:thumbsup:

                    Some Day I Will Prove MySelf :: GOLD

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups