zoukankan      html  css  js  c++  java
  • c++实现"扫描检测硬件改动"

    这里需要用到cfgmgr32.h,参考了网上好几篇博文。

    #include <windows.h>
    #include <stdio.h>
    #include <cfgmgr32.h>
    #pragma comment(lib,"setupapi.lib") 
    
    int main()
    {
       DEVINST     devInst;
       CONFIGRET   status;
    
       status = CM_Locate_DevNode(&devInst, NULL, CM_LOCATE_DEVNODE_NORMAL);
    
       if (status != CR_SUCCESS) {
           printf("CM_Locate_DevNode failed: %x
    ", status);
           return FALSE;
       }
    
       status = CM_Reenumerate_DevNode(devInst, 0);
    
       if (status != CR_SUCCESS) {
           printf("CM_Reenumerate_DevNode failed: %x
    ", status);
       }
    
       return 0;
    }
    
    

    网上的文章基本上没提到要引入lib,我用VS2010测试会报错,提示“...error LNK2019: 无法解析的外部符号 __imp__CM_Reenumerate_DevNode@8...”、“...error LNK2019: 无法解析的外部符号 __imp__CM_Locate_DevNodeA@12...”

    然后继续查资料,提到要引入lib,按照操作了,vs2010又提示错误“无法打开文件 cfgmgr32.lib” 随后在stackoverflow找到答案了,参考 https://stackoverflow.com/questions/27178969/why-cant-i-find-cfgmgr32-lib-in-the-windows-sdk
    以上是最终版,经测试在设备管理器里卸载某设备,执行该程序可以实现等同扫描硬件改动的效果。

    参考链接:
    https://stackoverflow.com/questions/33420994/windows-usb-device-refresh-in-c-c
    https://docs.microsoft.com/en-us/windows/desktop/devinst/cfgmgr32-h
    https://bbs.csdn.net/topics/30248104

  • 相关阅读:
    pthread_key_t和pthread_key_create()详解
    oracle的时间
    spring加载bean报错:expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    MyBatis调用存储过程
    java的时间
    java的日期
    java中的多态
    笔记本设置wifi热点并抓包
    WiresShark使用说明
    HTTP协议概述
  • 原文地址:https://www.cnblogs.com/sherlock-merlin/p/10793522.html
Copyright © 2011-2022 走看看