|
发表于 2006-6-29 13:16:00
|
显示全部楼层
<P>大家参考一下吧!</P><P>int EjectUSBDevice()
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;</P><P>
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0,
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
::AfxMessageBox("ERROR - SetupDiGetClassDevs()");
return 1;
}
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
CString cc;
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
cc = DeviceInfoData.ClassGuid.Data4;
if(cc.Find("VDEST") == -1)
continue;
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[MAX_PATH];
ULONG ulStatus;
ULONG ulProblemNumber;</P><P> cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr )
{
TRACE("OK - CM_Get_DevNode_Status()[%d]\n", cr);
TRACE("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
TRACE("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
} else
{
TRACE("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
TRACE("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
if ((DN_DISABLEABLE & ulStatus ) != 0 )
{
TRACE("- DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
} else
{
continue;
}
if ((DN_REMOVABLE & ulStatus ) != 0 )
{
TRACE("- DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
}
else
{
continue;
}</P><P> len = MAX_PATH;
// pnpvietotype = PNP_VetoDevice;
cr = CM_Request_Device_Eject(DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0);
if ( CR_SUCCESS == cr )
{
TRACE("OK - CM_Request_Device_Eject()[%d]\n", cr);
}
else
{
TRACE("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
TRACE("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
return 1;
}
}
if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
//Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);</P><P> return 0;
}</P>[br]<p align=right><font color=red>+3 RD币</font></p> |
|