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);
  • 相关阅读:
    hdu-美素数
    codeforces-Jeff and Periods
    codeforces-Domino
    UVA10878
    UVA537
    UVA10815
    c语言中的qsort函数(转)
    Loadrunner进行性能测试的步骤
    LoadRunner打开WebTours只显示头部解决办法
    性能测试的基本概念
  • 原文地址:https://www.cnblogs.com/tommy-huang/p/12901608.html
Copyright © 2011-2022 走看看