How can I make my compilation optimized for Windows 64 bit?
4 Answers
You might also want to do a check at runtime, just to be sure:
using System;
using System.Runtime.InteropServices;
class SystemChecker
{
static bool Is64Bit
{
get { return Marshal.SizeOf(typeof(IntPtr)) == 8; }
}
}

- 113,561
- 39
- 200
- 288

- 21,178
- 26
- 94
- 142
A managed project is automatically built according to the architecture selected => default C# project created on AMD64 will be AMD64, X86 on X86. The native one is always 32-bit by default.
To explicitly set a platform:
1 open the solution explorer, select solution, right click->Configuration Manager.
2 go to 'Active Solution Platform', click New.
3 in the 'New Solution Platform' dialog that comes up select the new platform say Itanium. Set 'Copy Settings From' to 'Any CPU' which was the default setting in the 'Active Solution Platform'.
4 click OK.
This is from WebLog

- 136,852
- 88
- 292
- 341
As Patrick Desjardins said, with a little addition.
Beware if you have third party DLL which uses Interop and is compiled with 32 bit. In that case, you will specifically have to set all your assemblies which uses it to use x86 or all manner of weird things will happen.

- 136,852
- 88
- 292
- 341

- 793
- 3
- 10
You can compile for 64bit through the /platform
-flag. Note that visual studio Express has no straightforward 64bit compile setting.
See here for more information, and here. Taken from the second source is the following information:
On a 64-bit Windows operating system:
- Assemblies compiled with
/platform:x86
will execute on the 32 bit CLR running under WOW64. - Executables compiled with the
/platform:anycpu
will execute on the 64 bit CLR. - DLLs compiled with the
/platform:anycpu
will execute on the same CLR as the process into which it is being loaded.
Runtime Check:
You can check the execution bit environment at runtime through one of the following options
bool is64BitProcess = IntPtr.Size == 8;
int bitProcess = IntPtr.Size*8;
//C# 4 provides System.Environment.Is64BitProcess
//TimothyP's solution:
bool is64BitProcess = Marshal.SizeOf(typeof(IntPtr)) == 8;

- 23,698
- 16
- 85
- 87