想弹出u盘,但是把usb鼠标也卸载了?

job82824 job82824 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

//这个其实是网上直接抄来的代码,大家能帮忙看下问题所在吗?
#include <windows.h>
#include <Setupapi.h>
#include <cfgmgr32.h>
#include <initguid.h>

#pragma comment(lib,"setupapi.lib")

DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L,0x6530,0x11D2, 0x90,0x1F,0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE

//绿色的地方好像没什么用,我就给屏蔽了。
int PopupAllUSBDisk()
{
int Result = 0;
DWORD i;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
//--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0,// Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(hDevInfo == INVALID_HANDLE_VALUE)
{
// 查询信息失败
//printf("ERROR - SetupDiGetClassDevs()");
return 1;
}
//--------------------------------------------------------------------------
// 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for(i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
TCHAR vetoname[MAX_PATH];
ULONG ulStatus;
ULONG ulProblemNumber;

cr = CM_Get_DevNode_Status(&ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
/*if(CR_SUCCESS == cr)
{
printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
}
else
{
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}*/
if(CR_SUCCESS != cr)
Result++;
// DN_DISABLEABLE or DN_REMOVABLE
/*if((DN_DISABLEABLE & ulStatus) != 0)
{
Result++;
//printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
}
else
{
continue;
}
if((DN_REMOVABLE & ulStatus) != 0)
{
printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
}
else
{
continue;
}*/

len = MAX_PATH;
// pnpvietotype = PNP_VetoDevice;
cr = CM_Request_Device_EjectW(DeviceInfoData.DevInst,&pnpvietotype,vetoname,len,0);//没有气泡提示
//cr = CM_Request_Device_EjectW(DeviceInfoData.DevInst,&pnpvietotype,NULL,0,0);//有气泡提示
/*if(CR_SUCCESS == cr)
{
printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
}
else
{
printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
}*/
if(CR_SUCCESS != cr)
Result++;
}

if(GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS)
{
// Insert error handling here.
return 1;
}

// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);

return Result;

这个有办法改一下吗?就是不要把鼠标给卸载了?
...全文
评论 14
收藏 已收藏
分享
返回顶部
job82824
硬件/系统 2,644 成员 17,229 内容