PInvoke c++ dll from c# - 尝试加载格式不正确的程序.(来自 HRESULT 的异常:0x8007000B) [英] PInvoke c++ dll from c# - An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

查看:28
本文介绍了PInvoke c++ dll from c# - 尝试加载格式不正确的程序.(来自 HRESULT 的异常:0x8007000B)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 Dll 导入从 c# 访问旧的 c++ dll.在网上搜索了大约 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.

我正在尝试使用来自 asp.net mvc 3 网站 .net 4 的 c++ dll.

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

我已将平台目标更改为 x86.我已在 iis 中的应用程序池中将启用 32 位应用程序"设置为 true.

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

使用带有 iis 7.5 的 Windows Server 2008 R2

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尝试加载格式不正确的程序"指出:

要使用 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

提前致谢!最好的问候

在 c# 中对 c++ 方法调用的错误声明会导致此错误吗?阅读该错误,人们可能会猜测调用具有 3 个参数且应接收 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 的进程实际上是一个 32 位进程,方法是通过某种方式获取进程 ID(例如通过捕获和记录异常),然后检查在任务管理器中.如果该进程实际上是一个 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.

这篇关于PInvoke c++ dll from c# - 尝试加载格式不正确的程序.(来自 HRESULT 的异常:0x8007000B)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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