BadImageFormatException加载32位的DLL时,目标86 [英] BadImageFormatException when loading 32 bit DLL, target is x86

查看:148
本文介绍了BadImageFormatException加载32位的DLL时,目标86的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL(FreeType的),这肯定是32位的。(头:IMAGE_FILE_MACHINE_I386)

I have a DLL (FreeType) which is certainly 32-bit (header: IMAGE_FILE_MACHINE_I386).

我想用它从C#code,使用的DllImport。

I want to use it from C# code, using DllImport.

我的应用程序的目标是86,IntPtr.Size是4,过程是32位。

Target of my application is x86, IntPtr.Size is 4, process is 32-bit.

但我得到BadImageFormatException(从HRESULT异常:0x8007000B)。什么可能是错误的?

But I get BadImageFormatException (Exception from HRESULT: 0x8007000B). What can be wrong?

当然,我用64位的Windows 7。

Of course I use 64-bit Windows 7.

推荐答案

据我了解,专为x86和在64位操作系统上运行内置的程序集只能加载库专为x86或一个BadImageFormatException将被抛出。在64位的操作系统,所有CPU或x64建立了一个组装会试图加载一个x86库时抛出同样的异常。

From what I understand, an assembly specifically built for x86 and running in a 64-bit operating system can only load libraries built for x86 or a BadImageFormatException will be thrown. In a 64-bit OS, an assembly built for Any CPU or x64 will throw the same exception when trying to load an x86 library.

因此​​,假设没有什么令人难以置信的奇怪的是怎么回事,我将确保你设置你的应用程序通过打开项目属性,然后单击生成选项卡上的搭建86。确保目标平台设置为86,而不是任何CPU。

So, assuming nothing incredibly weird is going on, I would ensure that you've set your application to build as x86 by opening the project properties and clicking on the Build tab. Ensure 'Platform Target' is set as 'x86' and not Any CPU.

另外,你可以尝试寻找该DLL的64位版本进行测试。

Alternatively, you could try to find a 64-bit version of the DLL for testing purposes.

这篇关于BadImageFormatException加载32位的DLL时,目标86的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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