greeceting
驱动牛犊
驱动牛犊
  • 注册日期2005-01-27
  • 最后登录2005-10-19
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1305回复:4

70分求救.关于设备的拔插?

楼主#
更多 发布于:2005-05-25 16:38
我在发送了一个类命令后,希望设备和主机断开,再连接,然后就可以发送其它的命令了.
     手动断开设备再连接可以实现我要的效果.
      但是有什么命令,请求可以达到同样的效果呢?
     是在客户驱动程序中实现,还是在应用层实现呢?
Shentu
驱动小牛
驱动小牛
  • 注册日期2004-04-05
  • 最后登录2011-01-24
  • 粉丝0
  • 关注0
  • 积分234分
  • 威望24点
  • 贡献值0点
  • 好评度20点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-05-26 00:00
Try SetupDiChangeState() or other SetupDiXXXX functions...
They can be found in DDK, and run in user-mode. Good luck!
greeceting
驱动牛犊
驱动牛犊
  • 注册日期2005-01-27
  • 最后登录2005-10-19
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-05-26 10:50
看了半天越看越迷惑,望高手解释清楚一点,或举个例子说明究竟是怎么完成软件实现拔插的
greeceting
驱动牛犊
驱动牛犊
  • 注册日期2005-01-27
  • 最后登录2005-10-19
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2005-05-26 10:53
谁有现成可用的代码就是实现软件实现拔插的呀?
wonder_2001
驱动小牛
驱动小牛
  • 注册日期2002-07-02
  • 最后登录2010-12-03
  • 粉丝0
  • 关注0
  • 积分452分
  • 威望96点
  • 贡献值0点
  • 好评度36点
  • 原创分0分
  • 专家分0分
地下室#
发布于: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(&params, 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) &params,
                                       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) &params,
                                       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);
}
游客

返回顶部