zoukankan      html  css  js  c++  java
  • C# DllImport 方法,出现 The system cannot find the file specified 错误

    最近使用 C# 调用 dll 中的 UpdateDriverForPlugAndPlayDevices() 方法去安装驱动,遇到了 “The system cannot find the file specified” 问题,

    看着错误提示,是指系统没有找到指定文件,但是我检查硬盘,该文件确实存在,但是因为我测试时使用的是 Hebrew 希伯来语的系统,
    我就考虑会不会是因为路径中包含了特殊字符,导致该方法不能正常工作,我当前的方法声明如下:

    [DllImport("newdev.dll", SetLastError = true)]
    public static extern bool UpdateDriverForPlugAndPlayDevices(IntPtr hwndParent, string HardwareId, string FullInfPath, UpdateDriverInstallFlag install, out Boolean bRebootRequired);

    后面经查资料,添加了 CharSet = CharSet.Auto,问题解决, 修改后的方法声明:

    [DllImport("newdev.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool UpdateDriverForPlugAndPlayDevices(IntPtr hwndParent, string HardwareId, string FullInfPath, UpdateDriverInstallFlag install, out Boolean bRebootRequired);
  • 相关阅读:
    勿忘初心
    欧拉函数与数论的结合UVA11426
    法雷级数
    欧拉函数及其应用
    poyla计数问题
    组合计数问题中容斥原理的应用
    数学问题当中的一些基本计数问题
    HDU4642博弈好题
    KMP算法在字符串中的应用
    UVA11722概率问题之线性规划
  • 原文地址:https://www.cnblogs.com/tommy-huang/p/12901608.html
Copyright © 2011-2022 走看看