无法加载 DLL(无法找到模块 HRESULT:0x8007007E) [英] Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

查看:36
本文介绍了无法加载 DLL(无法找到模块 HRESULT:0x8007007E)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含非托管 C++ API 代码的 dll 库,我需要在我的 .NET 4.0 应用程序中使用.但是我尝试加载 dll 的每种方法都会出现错误:

I have a dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method I try to load my dll I get an error:

无法加载 DLL 'MyOwn.dll':找不到指定的模块.(来自 HRESULT 的异常:0x8007007E)

Unable to load DLL 'MyOwn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

我已经阅读并尝试了在互联网上找到的几种解决方案.没有任何效果..

I have read and tried several solutions I have found on the internet. Nothing works..

我尝试过使用以下方法:

I have tried using following methods:

[DllImport("MyOwn.dll",  CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs((UnmanagedType.I4))]
public static extern Int32 MyProIni(string DBname, string DBuser_pass,
    string WorkDirectory, ref StringBuilder ErrorMessage);

当我尝试遵循 这篇文章 并且当我运行这个例子(从下载的代码)它运行没有问题(使用的 dll 在 bin/debug 文件夹中)

When I tried following this article and when I run this example (from the downloaded code) it runs without a problem (the dll used is in the bin/debug folder)

我已将我的 dll(连同它所依赖的所有文件一起复制到我的 bin 文件夹中).

I have copied my dll (along with all the files the it depends on into my bin folder).

我也尝试过这种方法,但得到了同样的错误:

I also tried this approach but got the same error:

[DllImportAttribute(MyOwnLibDllPath, EntryPoint="TMproIni")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern  int MyproIni(string DBname, string DBuser_pass, 
    string WorkDirectory, ref StringBuilder ErrorMessage);

有什么建议吗?

推荐答案

我记得在 Windows 上,dll 的搜索顺序是:

From what I remember on Windows the search order for a dll is:

  1. 当前目录
  2. 系统文件夹,C:windowssystem32 或 c:windowsSysWOW64(适用于 64 位机器上的 32 位进程).
  3. Path环境变量中读取
  1. Current Directory
  2. System folder, C:windowssystem32 or c:windowsSysWOW64 (for 32-bit process on 64-bit box).
  3. Reading from the Path environment variable

另外我会检查DLL的依赖关系,Visual Studio提供的dependency walker可以帮到你,也可以免费下载:http://www.dependencywalker.com

In addition I'd check the dependencies of the DLL, the dependency walker provided with Visual Studio can help you out here, it can also be downloaded for free: http://www.dependencywalker.com

这篇关于无法加载 DLL(无法找到模块 HRESULT:0x8007007E)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆