当目标的x64在Visual Studio [英] When to target x64 in Visual Studio

查看:149
本文介绍了当目标的x64在Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始了新的工作,第一件事情之一,我发现每个人都在谈论被更新的所有的我们的.NET应用程序到x64。我最初以为这很奇怪,因为我们都知道.NET编译为平台无关的IL和具体CLR运行code。

I recently started a new job, and one of the first things I noticed everybody talking about was "updating" All our .NET apps to x64. I initially thought this odd since we all know .NET compiles to platform agnostic IL and the specific CLR runs the code.

看远一点,我发现这是很有帮助的文章和的这个SO帖子这有助于解释的事情。

Looking a bit further, I found this helpful article and this SO post which helped explain things.

所以,现在我明白,IL没有改变,只是元数据基本上是说在WOW64在x64系统上运行或不能(简单地说)。

So now I understand that the IL isn't changed, only meta data basically saying to run in WOW64 or not on a x64 system (in a nutshell).

所以,如果我在x64系统,我可以指定任何CPU到本地运行,但不支持32位的DLL;我可以指定86,这将支持32位的DLL(因为他们都将在WOW64下运行); 但是当我会指定64?如此看来,64位的DLL将在在x64系统中的任何CPU的设想得到支持。这是,如果我想prevent有人在32位系统上运行我的应用程序或确保失败尝试加载32位的DLL时?

So if I'm on a x64 system, I can specify "Any CPU" to run natively, but won't support 32bit dlls; I can specify "x86" which will support 32bit dlls (since they both would be running under WOW64); but when would I specify "x64"? It seems that 64bit dlls would be supported in the "Any CPU" scenario on a x64 system. Is this if I want to prevent someone from running my app on a 32bit system or ensuring failure when trying to load 32bit dlls?

这也将在我看来,你会需要将其设置为除任何CPU等,如果你有一些第三方的dll到项目后顾之忧。是不是最好离开它,因为任何CPU的所有其他项目不涉及别人的dll?

It would also seem to me that you would only need to set it to something other than "Any CPU" if you have some 3rd party dll to worry about in your project. Is it best to leave it as "Any CPU" for every other project not dealing with others dlls?

如果我碰巧设置我的目标为86,因为我有一个32位的第三方的dll,是我的应用程序实际上被认为是运行在64位,如果在64位系统刚下WOW64?

If I do happen to set my target to "x86" because I have a 32bit 3rd party dll, is my application actually considered to be running in 64bit if on a 64bit system just under WOW64?

推荐答案

是的,你可以指定该项目应编译到x64,如果你调用一个DLL,它本身是64位(可能是因为它是本地的,或者是托管DLL这本身调用64位本机DLL,等)。

Yes, you would specify that the project should compile to x64 if you're calling a DLL that is itself 64 bit (either because it is native, or is a managed DLL that's itself calling a 64 bit native DLL, etc).

同样,对于指定它应该是86,如果你正在处理的32位第三方的DLL;它不会被考虑,如果在64位版本的Windows上运行64位应用程序。

Likewise for specifying that it should be x86 if you're dealing with 32-bit 3rd party DLLs; it will not be considered a 64-bit application if running on a 64-bit version of Windows.

如果你只是处理纯管理code,那么我会离开的事情为任何。我也一般假的DLL作为任何还有,即使executeable会被指定为x86或x64。

If you're just dealing with pure managed code, then I'd leave things as "any". I also generally leave DLLs as "any" as well, even if the executeable will be specified to be either x86 or x64.

即使你正在处理的本机DLL,你可能仍然能够逃脱离开它为所有,如果你使用的PInvoke;你可以有两个版本的包围着它,一个是86,一个是64位的一类,并选择在运行时通过检查IntPtr.Size财产使用哪一个。

And even if you're dealing with native dlls, you might still be able to get away with leaving it as "any" if you're using PInvoke; you can have two versions of a class that wraps around it, one for x86, one for x64, and choose which one to use at runtime by checking the IntPtr.Size property.

当然,如果你的应用需要超过4 GB的RAM,并要强制它必须在64位操作系统上运行,那么你还需要针对64位。

And of course, if you're application needs more than 4 GBs of RAM and you want to enforce that it has to run on a 64-bit OS, then you'll also need to target x64.

这篇关于当目标的x64在Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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