Why I cann't get the message device type:DBT_DEVTYP_DEVICEINTERFACE?
I can get the message device tpye DBT_DEVTYP_VOLUME,but my WndProc cann't get the DBT_DEVTYP_DEVICEINTERFACE message device type.My code is:
const int WM_DEVICECHANGE = 0x0219;
public enum DEVICETYPE:int
{
DBT_DEVTYP_OEM =0x00000000,// oem-defined device type
DBT_DEVTYP_DEVNODE = 0x00000001, // devnode number
DBT_DEVTYP_VOLUME = 0x00000002, // logical volume
DBT_DEVTYP_PORT = 0x00000003, // serial, parallel
DBT_DEVTYP_NET =0x00000004, // network resource
DBT_DEVTYP_DEVICEINTERFACE =0x00000005 //device interface class
}
public struct _DEV_BROADCAST_HDR
{
public int dbch_size;
public DEVICETYPE dbch_devicetype;
private int dbch_reserved;
}
public struct _DEV_BROADCAST_VOLUME
{
public int dbcv_size;
public DEVICETYPE dbcv_devicetype;//Set to DBT_DEVTYP_VOLUME
private int dbcv_reserved;
public uint dbcv_unitmask;
public int dbcv_flags;
}
public struct _DEV_BROADCAST_DEVICEINTERFACE
{
public int dbcc_size;
public DEVICETYPE dbcc_devicetype; //Set to DBT_DEVTYP_DEVICEINTERFACE
public int dbcc_reserved;
public System.Guid dbcc_classguid;
//char dbcc_name[1];
}
protected override void WndProc(ref Message devicemsg)
{
_DEV_BROADCAST_DEVICEINTERFACE
DevBroadcastInterface;
DEVICEEVENT Eventtype;
_DEV_BROADCAST_HDR Whicheventtype;
_DEV_BROADCAST_VOLUME DevBroadcastVolume;
base.WndProc(ref devicemsg);
if(devicemsg.Msg == WM_DEVICECHANGE)
{
Eventtype = (DEVICEEVENT)devicemsg.WParam.ToInt32();
switch(Eventtype)
{
case DEVICEEVENT.DBT_DEVICEARRIVAL:
{
Whicheventtype = (_DEV_BROADCAST_HDR)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_HDR));
switch(Whicheventtype.dbch_devicetype)
{
case DEVICETYPE.DBT_DEVTYP_DEVICEINTERFACE:
{//this case can not be retrieved,why?
DevBroadcastInterface = (_DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_DEVICEINTERFACE));
//do something here.
break;
}
case DEVICETYPE.DBT_DEVTYP_VOLUME:
{// but this case can be retrieved.
DevBroadcastVolume = (_DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(devicemsg.LParam,typeof(_DEV_BROADCAST_VOLUME));
//do something here.
break;
}//end case DBT_DEVTYP_VOLUME
}//end switch(pDevBroadcastHdr.dbch_devicetype)
}//end case DBT_DEVICEARRIVAL
break;
}//end switch(Eventtype)
}//end if
}//end WndProc()
Why does the WndProc can not retrive the DBT_DEVTYP_DEVICEINTERFACE message device type?
Thanks!