WM_DEVICECHANGE Problem [SOLVED]
-
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
-
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
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;
... -
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;
...this code is not notifying neither DEVICE_ARRIVAL nor DEVICE REMOVAL.
Some Day I Will Prove MySelf :: GOLD
-
this code is not notifying neither DEVICE_ARRIVAL nor DEVICE REMOVAL.
Some Day I Will Prove MySelf :: GOLD
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.
-
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.
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
-
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
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)?
-
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)?
Ozer Karaagac wrote:
dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE
is 245760. and this is occurred only once.
Some Day I Will Prove MySelf :: GOLD
-
Ozer Karaagac wrote:
dbcv_unitmask in case DBT_DEVICEREMOVECOMPLETE
is 245760. and this is occurred only once.
Some Day I Will Prove MySelf :: GOLD
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.
-
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.
thanx, it worked:thumbsup:
Some Day I Will Prove MySelf :: GOLD