PInvoke的C ++从C#DLL - 试图用不正确的格式加载程序。 (从HRESULT异常:0x8007000B)不正确、试图用、加载、异常

2023-09-04 02:51:56 作者:剧情在美,终究是戏

试图使用DLL导入C#访问一个古老的C ++ DLL。 一直在寻找周围的净aprox的4天现在都没有成功。

Trying to access an old c++ dll from c# using Dll Import. Been searching around the net for aprox 4 days now without success.

我想用C ++ DLL从一个asp.net MVC 3网站.NET 4

I'm trying to use the c++ dll from an asp.net mvc 3 website .net 4.

我已经改变了目标平台的x86。 我已经设置了启用32位应用程序,以真正在IIS应用程序池。

I've changed platform target to x86. I've set "Enable 32 bit application" to true on the application pool in iis.

使用Windows Server 2008 R2与IIS 7.5

Using Windows Server 2008 R2 with iis 7.5

有没有一些方法来调试这或获取有关什么可能是错误的详细信息?

Is there some way to debug this or get more info about what might be wrong?

链接ASP.NET的P / Invoke"试图用不正确的格式&QUOT加载程序; 指出:

使用32位的dll,你的web应用程序必须在32位模式,通过切换IIS在32位模式下运行,做到运行,并给出了有关如何更改此链接,然而,这似乎只关注IIS 6和asp.net 2

"To use the 32 bit dll, your web application has to run in 32 bit mode, which is done by switching IIS to run in 32 bit mode" and gives a link about how you can change this, however this seems only to concern IIS 6 and asp.net 2

在此先感谢! 顺祝商祺

Thanks in advance! Best Regards

编辑1: 像C ++方法的错误的声明,在C#中的结果调用这个错误?读取错误人能猜到,调用3 PARAMS一个功能,应该得到4会导致此错误。

Edit 1: Would an erroneous declaration of the c++ method calls in c# result in this error? Reading the error one could guess that calling a function with 3 params that should receive 4 would result in this error.

推荐答案

好回答你的最后一个问题:

Well to answer your last question:

将在C ++中的这个错误在C#中的结果的方法调用?的错误声明

Would an erroneous declaration of the C++ method calls in c# result in this error?

没有,我不相信它会 - 作为C错误声明++方法可能会导致一些事情发生,从正确地执行一个互操作异常的作用被抛出,但我不认为这个异常将被抛出。 - 这是特定于一个问题加载DLL

No, I don't believe that it would - erroneous declaration of the C++ method could result in a number of things happening ranging from the function executing correctly to an interop exception being thrown, however I don't believe that this exception would be thrown - this is specific to a problem loading the dll.

您应该检查,以确保该进程试图加载这个DLL文件的实际上的通过某种方式获得的进程ID(例如,通过捕捉和记录的除外),然后检查32位进程在任务管理器。如果这个过程实际上是一个64位的过程中,你可能已经配置不正确的东西。

You should check to make sure that the process attempting to load this dll is actually a 32-bit process by somehow obtaining the process ID (e.g. by catching and logging the exception), and then checking in task manager. If the process is actually a 64-bit process then you may have incorrectly configured something.

您也应该检查,以确保该DLL您正试图加载(和它所有的依赖),其实都是32位的 - 我相信,如果你尝试加载64位DLL到你会遇到类似的问题一个32位的过程。您应该能够使用的Dependency Walker(全方位非常有用的工具)进行检查。

You should also check to ensure that the dll you are attempting to load (and all its dependencies) are in fact 32-bit - I believe that you will experience a similar issue if you attempt to load a 64-bit dll into a 32-bit process. You should be able to use Dependency walker (an all-round very useful tool) to check this.