x64应用程序可以使用x86程序集吗?反之亦然 [英] Can an x64 application use x86 assemblies - and vice versa?

查看:297
本文介绍了x64应用程序可以使用x86程序集吗?反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是作为x64应用程序构建的。搬到VS2010后,我获得了一些问题这似乎与引用的dll中的一些x64 / x86不匹配有关。现在我正在移动目标.NET4,并且我获得更多的类似的问题

My application is built as a x64 application. After moving to VS2010 I got some problems which seems to be related to some x64/x86 mismatch in referenced dlls. Now I'm moving to target .NET4, and I get even more similar problems.

我的问题是:在混合x64和x86时需要采取什么预防措施。可以完成吗?我认为x64应用程序应该能够使用x86 dll没有问题。没有?另一方面呢?一个x86应用程序可以引用x64 dll - 只要它在x64平台上运行?我需要注意什么陷阱?

My question is: What precautions do I need to take regarding mixing x64 and x86. Can it be done at all? I thought x64 applications should be able to use x86 dlls without problems. No? What about the other way? Can a x86 application reference an x64 dll - as long as it is being run on an x64 platform? What are the pitfalls I need to be aware of?

推荐答案

不,64位进程只能加载64位DLL,32位进程只能加载32-位DLL。您可能会想到的是,64位操作系统可以运行32位进程

No, a 64-bit process can only load 64-bit DLLs and a 32-bit process can only load 32-bit DLLs. What you're probably thinking of is that a 64-bit operating system can run 32-bit processes.

.NET的主要问题是 - 在VS2010之前 - 可执行项目默认为AnyCPU,这意味着它将以正在运行的操作系统的本机格式加载(因此32位32位版本的Windows 64位版本的Windows 64位)。问题在于,如果您在32位Windows上测试了应用程序(比如说),那么如果您加载了32位DLL并尝试在64位Windows上运行,那么可能会损坏。

The main issue with .NET is that - prior to VS2010 - executable projects defaulted to "AnyCPU" which means it would load in the "native" format of the OS it's running on (so 32-bit for 32-bit versions of Windows and 64-bit for 64-bit versions of Windows). The problem with that is that if you tested your application on 32-bit Windows (say) then it could break if you load 32-bit DLLs and tried to run on 64-bit Windows.

在VS2010中,默认情况下,所有可执行项目默认为x86(即32位),这大部分可以减轻问题。

In VS2010, they defaulted all executable projects to be "x86" (that is, 32-bit) by default which (for the most part) mitigates the problem.

这篇关于x64应用程序可以使用x86程序集吗?反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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