阅读:1305回复:4
70分求救.关于设备的拔插?
我在发送了一个类命令后,希望设备和主机断开,再连接,然后就可以发送其它的命令了.
手动断开设备再连接可以实现我要的效果. 但是有什么命令,请求可以达到同样的效果呢? 是在客户驱动程序中实现,还是在应用层实现呢? |
|
沙发#
发布于:2005-05-26 00:00
Try SetupDiChangeState() or other SetupDiXXXX functions...
They can be found in DDK, and run in user-mode. Good luck! |
|
板凳#
发布于:2005-05-26 10:50
看了半天越看越迷惑,望高手解释清楚一点,或举个例子说明究竟是怎么完成软件实现拔插的
|
|
地板#
发布于:2005-05-26 10:53
谁有现成可用的代码就是实现软件实现拔插的呀?
|
|
地下室#
发布于:2005-05-26 11:49
BOOLEAN
RestartDevice( IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData ) { SP_PROPCHANGE_PARAMS params; SP_DEVINSTALL_PARAMS installParams; // for future compatibility; this will zero out the entire struct, rather // than just the fields which exist now memset(¶ms, 0, sizeof(SP_PROPCHANGE_PARAMS)); // initialize the SP_CLASSINSTALL_HEADER struct at the beginning of the // SP_PROPCHANGE_PARAMS struct, so that SetupDiSetClassInstallParams will // work params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; // initialize SP_PROPCHANGE_PARAMS such that the device will be stopped. params.StateChange = DICS_STOP; params.Scope = DICS_FLAG_CONFIGSPECIFIC; params.HwProfile = 0; // current profile // prepare for the call to SetupDiCallClassInstaller (to stop the device) if( !SetupDiSetClassInstallParams( DeviceInfoSet, DeviceInfoData, (PSP_CLASSINSTALL_HEADER) ¶ms, sizeof(SP_PROPCHANGE_PARAMS) ) ) { printf(\"in RestartDevice(): couldn\'t set the install parameters!\"); printf(\" error: %u\\n\", GetLastError()); return (FALSE); } // stop the device if( !SetupDiCallClassInstaller( DIF_PROPERTYCHANGE, DeviceInfoSet, DeviceInfoData ) ) { printf(\"in RestartDevice(): call to class installer (STOP) failed!\"); printf(\" error: %u\\n\", GetLastError() ); return (FALSE); } // restarting the device params.StateChange = DICS_START; // prepare for the call to SetupDiCallClassInstaller (to stop the device) if( !SetupDiSetClassInstallParams( DeviceInfoSet, DeviceInfoData, (PSP_CLASSINSTALL_HEADER) ¶ms, sizeof(SP_PROPCHANGE_PARAMS) ) ) { printf(\"in RestartDevice(): couldn\'t set the install parameters!\"); printf(\" error: %u\\n\", GetLastError()); return (FALSE); } // restart the device if( !SetupDiCallClassInstaller( DIF_PROPERTYCHANGE, DeviceInfoSet, DeviceInfoData ) ) { printf(\"in RestartDevice(): call to class installer (START) failed!\"); printf(\" error: %u\\n\", GetLastError()); return (FALSE); } installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); // same as above, the call will succeed, but we still need to check status if( !SetupDiGetDeviceInstallParams( DeviceInfoSet, DeviceInfoData, &installParams ) ) { printf(\"in RestartDevice(): couldn\'t get the device install params!\"); printf(\" error: %u\\n\", GetLastError() ); return (FALSE); } // to see if the machine needs to be rebooted if( installParams.Flags & DI_NEEDREBOOT ) { return (FALSE); } // if we get this far, then the device has been stopped and restarted return (TRUE); } |
|