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

查看:42
本文介绍了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 位(适用于 64 位版本的 Windows).问题在于,如果您在 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天全站免登陆