试图加载格式不正确的程序
An attempt was made to load a program with an incorrect format
我正在使用c#加载c++ dll,并得到这个错误:
"类型为'System '的未处理异常。BadImageFormatException' occurred in MyApp.exe"附加信息:试图加载格式不正确的程序。(Exception from HRESULT: 0x8057000B)
我不明白为什么。c++ dll是使用vs2012向导生成的,win32应用程序,带前置的dll。它是用x64选项构建的。下面是代码:
// MyNativeDLL.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
//char* pMemoryBuffer = NULL;
using namespace std;
__declspec(dllexport) long Test()
{
long a;
a = 1;
a++;
return a;
}
调用它的c#代码是:
[DllImport("C:\MyNativeDLL\x64\Debug\MyNativeDLL.dll", EntryPoint = "Test")]
private extern static int Test();
void doJob()
{
long a = Test(); // exception thrown here
}
c#代码是用任意CPU选项构建的,它正在加载x64本地dll。我想知道我哪里做错了?我已经试了很久了,但是真的卡住了。谢谢!当我使用win32选项编译本机dll时,并设置正确的dll路径,它加载成功。但是当我用x64选项编译本机dll时,用正确的路径加载,加载失败。
正如你所说: c++ dll是使用vs2012向导生成的,win32应用程序,带前置的dll。它是用x64选项
构建的DLL和exe必须都是32位,或者都是64位。
相关文章:
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 连接的组件程序产生不正确的输出
- 我的程序中的值计算不正确,即使支持数学是正确的
- 我的控制台处理程序不处理 CTRL+C,即使设置正确
- 简单的程序比较阵列运行但给出不正确的结果
- C++:我的简单计算器程序无法打印出来。我也认为我的变量命名不正确
- 收到错误 87,安装程序的参数不正确DiGetDeviceInterfaceDetail
- 我创建了一个将雷亚尔转换为美元的程序,但浮点变量不正确
- C 程序运行不正确的其他语句
- C 程序不会返回正确的阶乘值
- 程序不输出正确的标准偏差.另外,验证问题
- 无法加载dll libglorycolx2010.dll.该应用程序未能启动,因为其并排配置不正确.Hresult:0x
- 查找符号时,程序不会从正确的库中搜索
- C++曼德布洛特程序不会产生正确的输出
- 使用C++(基于C#程序)保存wav文件时,音频数据不正确
- 为什么他的语法正确的程序不能在带有llvm编译器的Xcode IDE上编译?
- 中缀到后缀转换器 + 评估程序正确打印到控制台,但不正确地打印到文本文件
- 如果通过循环求和,下面的程序会找到正确的答案,但如果通过GP的公式求和,则会找到不正确的答案.为什么
- OpenGL程序/w着色器,相机移动不正确