问题描述
我在asp.net Web应用程序中使用第三方c ++ dll。
Iam using a 3rd party c++ dll in my asp.net web application.
dll - 64-bit
asp.net Platform - Any Cpu
asp.net Framework - 4.0 (vs 2010)
System Os - Win 7 Professional (64-bit)
我已将dll放在Applications文件夹中,并以完整路径将dll命名为:
I have placed the dll in the Applications folder and called the dll with its full path as:
[DllImport(@"D:\Application\Sampledll.dll",
EntryPoint = "SampleFunc",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
public static extern int SampleFunc(char[] ch1, char[] ch2);
但是我得到以下结果:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
当搜索错误代码:0x8007000B时-表示正在使用32 64位系统上的位dll'
When searched with the Error code: 0x8007000B - It meant 'Using 32-bit dll on 64-bit system'
但是该dll是64位dll...。
But the dll is 64-bit dll....
通过将VS的目标平台更改为 x86并以任何方式尝试解决此错误, 'x64'并将IIS的'Enable 32-Bit Application'属性设置为'True'
Any how I tried the solution of this error by changing the Target Platform of VS to 'x86' & 'x64' and setting 'Enable 32-Bit Application' property of IIS to 'True'
但是出现了相同的错误.........
But got the same error.........
任何人都可以解决这个问题...。
Can any one help to get around this problem....
推荐答案
错误代码 0x8007000B
是表示Win32错误 ERROR_BAD_FORMAT
的COM错误代码。通常,当32位进程尝试加载64位DLL时,反之亦然,错误代码为 ERROR_BAD_EXE_FORMAT
,其显示为 0x800700C1
包裹在COM错误代码中。
Error code 0x8007000B
is the COM error code that represents the Win32 error ERROR_BAD_FORMAT
. Normally when a 32 bit process tries to load a 64 bit DLL, or vice versa, the error code is ERROR_BAD_EXE_FORMAT
which would appear as 0x800700C1
when wrapped in a COM error code.
因此,我认为问题不是32/64位不匹配。最可能的解释是该DLL或其依赖项之一已损坏。
Therefore, I think that the problem is not a 32/64 bit mismatch. The most likely explanation is that the DLL, or one of its dependencies, is corrupt.
为了调试此问题,我将消除IIS的复杂性。您已经添加了p / invoke和IIS层来处理。首先,请确保您可以从另一个本机程序加载此DLL。在VS中创建一个执行以下操作的64位C ++控制台应用程序:
In order to debug this I would remove the complexity of IIS. You've got added layers of p/invoke and IIS to deal with. First of all make sure that you can load this DLL from another native program. Create a 64 bit C++ console app in VS that does this:
#include <windows.h>
#include <iostream>
int main()
{
if (!LoadLibraryA("D:\\Application\\Sampledll.dll"))
{
std::cout << GetLastError() << std::endl;
}
}
看看运行该命令会发生什么。如果收到错误代码,它是什么值?是 ERROR_BAD_FORMAT
吗?此时,我将在配置文件模式下使用Dependency Walker来尝试找出哪个DLL是麻烦的制造者。
See what happens when you run that. If you get an error code, what value is it? Is it ERROR_BAD_FORMAT
? At this point I'd use Dependency Walker in Profile mode to try to work out which DLL is the trouble maker.
这篇关于尝试加载dll时出错-尝试加载格式错误的程序。 (来自HRESULT的异常:0x8007000B)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!