Reputation: 24067
I'm using Windows 7 and x64 cpu. Does it mean that I should always compile with "x64" option in Visual Studio? What about "dll", can I use x86 dll from x64 application? Probably there are other concerns?
Upvotes: 5
Views: 4144
Reputation: 40150
Generally speaking, you should use AnyCpu
all the time.
If you have specific reasons to expect compatibility problems with that, then you'll need to choose x86 or x64 as appropriate.
As noted in the comments, dll's built against specific architectures can require you to build your assembly a certain way. This will be something you'll want to do when you need to, not otherwise.
Upvotes: 5
Reputation: 31641
AnyCPU
is what I generally recommend. You can see this issue discussed in depth at this SO post.
The only concern is that you cannot go backwards - you can't use an x64 assembly from a x86 application. AnyCPU
alleviates this potential pitfall.
Upvotes: 1
Reputation: 70369
No... the machine you write your code on/compile/build your software (EXE, DLL...) does not have anything to do with the question which target (x86 / x64 / Any).
IF you want the result of the build to run anywhere you use either x86 or AnyCPU. If you want the result to run on x64 only then you use x64.
There are some cases where you must use x86 or x64 - that is when you use some (3rd-party?) component/library/DLL/ActiveX etc. in your project which is 32 Bit only (then x86) or only 64 Bit only (then x64).
Upvotes: 2
Reputation: 61802
This article contains a brief overview of each option.
Here's a small quote:
The default setting, Any CPU, means that the assembly will run natively on the CPU is it currently running on. Meaning, it will run as 64-bit on a 64-bit machine and 32-bit on a 32-bit machine. If the assembly is called from a 64-bit application, it will perform as a 64-bit assembly and so on.
If the project is set to x86, this means the project is intended to run only as a 32-bit process. A 64-bit process will be unable to call into an assembly set as X86. Reasons to set your project as x86 include dependencies upon native DLLs that are only available in 32-bit or making native calls assuming 32-bit . Applications and assemblies marked for x86 can still run on 64-bit Windows. However they run under WOW64. Visual Studio itself runs under this emulation mode since it is a 32-bit application.
Setting the project to x64 will specify that the assembly must run under 64-bit Windows. Attempting to run the assembly on 32-bit Windows or call the assembly from a 32-bit process will result in a runtime error.
Upvotes: 7