找回密码
 加入
搜索
查看: 6613|回复: 18

[系统综合] [已解决]求教各位大大,这个函数DiShowUpdateDevice 如何DLLCALL?

 火.. [复制链接]
发表于 2016-10-8 14:47:43 | 显示全部楼层 |阅读模式
本帖最后由 zghwelcome 于 2016-10-17 16:51 编辑

函数原型:https://msdn.microsoft.com/en-us ... 44727(v=vs.85).aspx
The DiShowUpdateDevice function displays the Hardware Update wizard for a specified device.
Syntax
C++


BOOL DiShowUpdateDevice(
  _In_opt_  HWND             hwndParent,
  _In_      HDEVINFO         DeviceInfoSet,
  _In_      PSP_DEVINFO_DATA DeviceInfoData,
  _In_      DWORD            Flags,
  _Out_opt_ PBOOL            NeedReboot
);

Parameters

hwndParent [in, optional]

    A handle to the top-level window that DiShowUpdateDevice uses to display any user interface components that are associated with updating the specified device. This parameter is optional and can be set to NULL.
DeviceInfoSet [in]

    A handle to the device information set that contains a device information element that represents the device for which to show the Hardware Update wizard.
DeviceInfoData [in]

    A pointer to an SP_DEVINFO_DATA structure that represents the device for which to show the Hardware Update wizard.
Flags [in]

    This parameter must be set to zero.
NeedReboot [out, optional]

    A pointer to a value of type BOOL that DiShowUpdateDevice sets to indicate whether a system restart is required to complete the driver update. This parameter is optional and can be NULL. If the parameter is supplied and a system restart is required to complete the driver update, DiShowUpdateDevice sets the value to TRUE. In this case, the caller must prompt the user to restart the system. If this parameter is supplied and a system restart is not required to complete the installation, DiShowUpdateDevice sets the value to FALSE. If the parameter is NULL and a system restart is required to complete the driver update, DiShowUpdateDevice displays a system restart dialog box. For more information about this parameter, see the following Remarks section.

参考了P版得 SetupAPI.au3,可惜基础差,加上比较愚钝,一直琢磨不透,该如何调用呢?

测试无数次失败后,我投降了
 楼主| 发表于 2016-10-8 15:01:30 | 显示全部楼层
情况是,在win10下,有未签名的打印机驱动需要安装,尝试了以下安装方案均告失败
1.rundll32 printui.dll,PrintUIEntry ...
2.devcon install ...
3.devcon update ..../updateni ....
4. P版写的函数_CM_Install_Device_Driver、_CM_Install_DevInst_Ex 等在win10下均无法运行

这个驱动只能在设备管理器的“其他设备”中,选择新硬件右键更新驱动才可以安装,所以我想通过模拟驱动更新向导的方式来安装驱动,可是不知道如何调出这个更新向导的界面。
 楼主| 发表于 2016-10-10 21:06:39 | 显示全部楼层
求助各位版主、各位长老级高手啊
 楼主| 发表于 2016-10-17 16:50:24 | 显示全部楼层
各种尝试,调用失败。此贴终结,没解决的解决,实属无奈
参看 http://www.autoitx.com/thread-53315-1-1.html
发表于 2016-10-17 21:59:05 | 显示全部楼层

#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseUpx=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include "SetupAPI.au3"

Local $tDevInfo

; 硬件设备 ID
$sDevID = 'PCI\VEN_10DE&DEV_0DEF&SUBSYS_21F417AA&REV_A1'
$hDev = _SetupDiGetClassDevs($DIGCF_ALLCLASSES, Null, $sDevID)
If @error Then
        MsgBox(0, '', @error)
        Exit
EndIf

$bRet = _SetupDiEnumDeviceInfo($hDev, 0, $tDevInfo)
If $bRet <>  True Then
        MsgBox(0, '', @error)
        Exit
EndIf

$iResult = DllCall('Newdev.dll', 'BOOL', 'DiShowUpdateDevice', _
        'ptr', Null, _
        'ptr', $hDev, _
        'ptr', DllStructGetPtr($tDevInfo), _
        'DWORD', 0, _
        'BOOL', False)


Win10 14393 x64 测试通过

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +31 收起 理由
zghwelcome + 31 感激不尽!

查看全部评分

发表于 2016-10-17 22:04:14 | 显示全部楼层
本帖最后由 nmgwddj 于 2016-10-17 22:10 编辑

另外需要注意的是,由于 32-bit 系统和 64-bit 系统,sizeof(SP_DEVINFO_DATA) 大小不一样,所以 64-bit 编译要将 P 版写的 SetupAPI.au3 中 _SetupDiEnumDeviceInfo 函数修改一下。

将给结构体 Size 赋值时大小改为 32(64-bit 系统下 sizeof(SP_DEVINFO_DATA) 的大小),否则 @error 会得到 1784,用户空间给出的 buffer 大小不够。



默认是 28,也就是 32-bit 下 sizeof(SP_DEVINFO_DATA) 的大小:



至于为什么要这样设置,请看一下 MSDN 中的介绍,调用者必须设置这个成员为 sizeof(SP_DEVINFO_DATA) 的大小:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +31 收起 理由
zghwelcome + 31 太帅了,感谢大师!

查看全部评分

 楼主| 发表于 2016-10-17 22:12:30 | 显示全部楼层
回复 6# nmgwddj


    谢谢大师,涨知识了,我明天测试下。
发表于 2016-10-18 11:20:44 | 显示全部楼层
回复 6# nmgwddj


请教一下, au3 没有sizeof如何提前知道那个结构的大小?
发表于 2016-10-18 12:31:06 | 显示全部楼层
回复 8# haijie1223


    我不太清楚 au3 具体有没有这类的实现方法,可能我不知道。因为我的环境里面装了 VS,所以在 VS 下打印一下 sizeof() 的大小就可以了。

    如果没有安装 VS,有个 linux 虚拟机,装个 gcc 编译个小测试程序成本也不高。
   
    如果以上两点均不具备,可以自己学习计算结构体内存大小,前提是要对 C 的一些基础数据类型有所了解,另外还要涉及到结构体在内存中的对齐方式。可以参考这里:http://www.mycode.net.cn/language/cpp/1489.html
发表于 2016-10-19 10:42:32 | 显示全部楼层
都是大神,膜拜一下。。。
 楼主| 发表于 2016-10-19 14:50:54 | 显示全部楼层
回复 5# nmgwddj


    谢谢大师,测试很正常!受教了
发表于 2016-10-21 15:41:35 | 显示全部楼层
这个很牛X的样子学习了
发表于 2016-12-31 22:32:07 | 显示全部楼层
收藏了,膜拜大神
发表于 2017-1-14 23:19:27 | 显示全部楼层
受教了,都是牛人啊,
发表于 2017-1-15 23:21:07 | 显示全部楼层
直接调用 devcon安装驱动即可,如果需要可以发出批处理代码
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-19 14:54 , Processed in 0.083630 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表