Hi all,
I am developing a USB application, in which i am registering the Device_Arrival notification.I am using CM_Request_Device_Eject to reject the USB Mass Storage Device. For this i am using setupapi.h and cfgmgr32.h header files from setupapi.dll.
this is the code snippet:
TO REGISTER THE EVENTS:
HDEVNOTIFY hDevNotify;
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
NotificationFilter.dbcc_size=sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype =DBT_DEVTYP_DEVICEINTERFACE;
HDEVINFO hDevInfo;
NotificationFilter.dbcc_classguid =GUID_CLASS_USB_DEVICE;//GUID_DEVINTERFACE_USB_DEVICE; //GUID_DEVINTERFACE_LIST[0];//GUID_CLASS_USB_DEVICE; //GUID_DEVINTERFACE_LIST[0];
hDevNotify=RegisterDeviceNotification(this ->GetSafeHwnd(),&NotificationFilter,DEVICE_NOTIFY_WIN DOW_HANDLE);
if(!hDevNotify)
{
return FALSE;
}
IN dEVICE DISCONNETED METHOD():
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData,*did;
CONFIGRET cr1,cr2,cr3,cr4;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[300]={0};
WCHAR buf[1024];//buf[BUFFER_SIZE];
DEVINST devInstParent;
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,0,/*Enumerator*/0,DIGCF_PRESENT | DIGCF_ALLCLASSES);
if(hDevInfo== INVALID_HANDLE_VALUE) return 0;
DeviceInfoData.cbSize=sizeof(DeviceInfoData);
BOOL B=SetupDiEnumDeviceInfo(hDevInfo,0,(PSP_DEVINFO_DATA)&De viceInfoData);
cr1= CM_Get_Parent(&devInstParent,DeviceInfoData.DevInst, 0);
cr4= CM_Query_And_Remove_SubTreeW( devInstParent,&pnpvietotype,(LPWSTR)vetoname, 300, 0);
****in this case i am getting pnpvietotype=PNP_VetoDevice... this means that, device is capable to perform operation on it, but it is rejecting the operation. And here the vetoname="ACPI_HAL\PNP08C08\0" but actually the deviceInstance is "USB\VIE_058F&PID_6387\PUL5N9MH"
And the cr=23 in this case.
but when i use:CM_Request_Device_Eject( devInstParent,&pnpvietotype,(LPWSTR)vetoname, 300, 0); I am getting the PNP_VetoIllegalDeviceRequest.That means this device does not support this operation.And here the vetoname="storage\RemovableMedia\7&97DBC19&0&RM" but actually the deviceInstance is "USB\VIE_058F&PID_6387\PUL5N9MH"
can anybody help me in locating this problem. I have included the setupapi.dll in the include libraries. I am doing this in VC++.Net2005.
Thanks bye
Anupama.