"指定的程序找不到"使用.NET 4的错误 [英] "The specified procedure could not be found" error with .NET 4

查看:301
本文介绍了"指定的程序找不到"使用.NET 4的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发在64位Windows 7中使用Visual Studio 2012(11.0.51106.01更新1)。

I am developing on a 64-bit Windows 7 box with Visual Studio 2012 (11.0.51106.01 Update 1).

我有一个支持项目,编译一些C code成(32位)的DLL。在我的头,我有:

I have a Support project that compiles some C code into a (32-bit) DLL. In my header I have:

#define RET_TYPE(type) _declspec(dllexport) type __stdcall

RET_TYPE(int) test_dll_call(int invar);

在我的C文件,我有:

RET_TYPE(int) test_dll_call(int invar)
{
   int retVal = 4 * invar;

   return retVal;
}

我也有一个(32位),WPF C#应用程序加载的类内的DLL,如下所示:

I also have a (32-bit) WPF C# application that loads the DLL inside of a class as follows:

[DllImport("MyDll.dll", CharSet = CharSet.Ansi, BestFitMapping = true, ThrowOnUnmappableChar = true)]
public static extern int test_dll_call(int invar);

这是包裹如下:

public void Wrap_TestDllCall()
{
   try
   {
      int outTest = 0;
      int invar = 3;

      outTest = test_dll_call(invar);
   }
   catch (Exception ex)
   {
      dllError = ex.ToString();
   }
}

当我在我的开发中运行这个在调试器,这工作正常。如果我所有相关的文件复制到一个单独的文件夹,并从那里运行它,它工作正常。

When I run this in the debugger on my development box, this works fine. If I copy all the relevant files to a separate folder and run it from there, it works fine.

如果我的所有必要的文件夹复制到运行32位的Windows XP SP3出现以下错误另一台计算机:

If I copy all the necessary folders to another computer running 32-bit Windows XP SP3 I get the following error:

System.DllNotFoundException: Unable to load DLL 'MyDll.dll': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
   at MyNamespace.MyClass.test_dll_call(Int32 invar)
   at MyNamespace.MyClass.Wrap_TestDllCall()

我已经使用的Dependency Walker对我的两个编译EXE和DLL;唯一缺少的DLL文件它发现均 wer.dll ieshims.dll ,它从我的研究并不需要在XP

I have used dependency walker on both my compiled exe and the dll; the only missing dlls it found were wer.dll and ieshims.dll, which from my research are not needed on XP.

我已经安装了VS2012 C ++可再发行,和.NET 4,和.NET 4.0.3更新。仍然没有运气。

I have installed the VS2012 C++ Redistributable, and .NET 4, and the .NET 4.0.3 update. Still no luck.

作为汉斯指出,这的出现修改 的是,该应用程序无法在DLL中找到的程序;我也曾尝试:

Edit As Hans points out, this appears to be that the app can't find the procedure in the DLL; I have also tried:

[DllImport("MyDll.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int test_dll_call(int invar);

__declspec(dllexport) int __cdecl test_dll_call(int invar);

这也工作正常,我开发框,但给出了WinXP的盒同样的错误。

Which also works fine on my dev box but gives the same error on the WinXP box.

帮助!

推荐答案

问题解决了。有些事情要注意,因为我通过故障排除步骤去,对于那些谁偶然发现了这个在未来。

Problem solved. Some things to note as I went through troubleshooting steps, for those who stumble upon this in the future.

  1. 在这个错误并不一定意味着它无法找到程序 X - 而这可能意味着它无法找到函数,从另外一个DLL,即称为 X
  2. 确保编译DLL中释放模式,作为C ++可再发行将不包括调试的DLL。
  3. 在开始一个shell函数,并且由一个补充件回来,之一。
  1. This error does not necessarily mean it can't find procedure X -- rather it may mean it can't find function Y, from another dll, that is called by X.
  2. Make sure to compile the DLL in 'Release' mode, as the C++ redistributable will not include the debug DLLs.
  3. Start with a shell function, and add pieces back in, one by one.

在我上面测试的例子,这个问题是我被编译为Debug版本。

In my above test example, the problem was I was compiling as a Debug version.

不过,在我的完整功能,这种变化并没有解决这个问题。原来我是缺少某些DLL的依赖学步车没赶上。

However, in my complete function, that change did not fix the issue. It turns out I was missing some DLLs that dependency walker did not catch.

这篇关于"指定的程序找不到"使用.NET 4的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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