公告
财富商城
积分规则
提问
发文
2019-01-19 13:57发布
爷的心禁止访问
How do I force my application to run as 32 bit on a 64 bit machine?
The code is written in C#.
Visual Studio 11 and .NET framwork 4.5 or above have an option for Any CPU 32-bit preferred and this was the default since then
Any CPU 32-bit preferred
The resulting code will run on any platforms but on 64-bit platforms they are run as 32-bit processes
Command-line form:
corflags application.exe /32BIT+
Right click your project, and select properties.
In properties, select the build tab. Under platform target, select x86.
Hit Ctrl+Shift+S to save all files, right click the solution and select "Clean" to get rid of old binaries. Any builds after that should be 32 bit
Assuming this is a Winforms, console app, or Windows service you have to build the exe for x86 instead of Any CPU. It's in the Configuration Manager.
Here's how I did it when we couldn't change the existing code from Any CPU to x86 due to a ClickOnce limitation:
Create a 32-bit (x86 must be checked under project properties) 'launcher' application (Windows Application but not form):
static void Main(string[] args) { // Load the assembly string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string assemblyName = Path.Combine(directory, "YourAnyCPUApplication.exe"); Assembly assembly = Assembly.LoadFile(assemblyName); assembly.EntryPoint.Invoke(null, null); }
Add the following code to the Main method in the Any CPU project:
if (IntPtr.Size == 4) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // etc... } else { // Launch application in 32-bit mode System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + @"\Your32BitApplicationLauncher.exe"); }
I hope this helps :-)
If you go to Configuration Manager in Visual Studio you can set the platform to x86 or x64.
最多设置5个标签!
Visual Studio 11 and .NET framwork 4.5 or above have an option for
Any CPU 32-bit preferred
and this was the default since thenThe resulting code will run on any platforms but on 64-bit platforms they are run as 32-bit processes
Command-line form:
Right click your project, and select properties.
In properties, select the build tab. Under platform target, select x86.
Hit Ctrl+Shift+S to save all files, right click the solution and select "Clean" to get rid of old binaries. Any builds after that should be 32 bit
Assuming this is a Winforms, console app, or Windows service you have to build the exe for x86 instead of Any CPU. It's in the Configuration Manager.
Here's how I did it when we couldn't change the existing code from Any CPU to x86 due to a ClickOnce limitation:
Create a 32-bit (x86 must be checked under project properties) 'launcher' application (Windows Application but not form):
Add the following code to the Main method in the Any CPU project:
I hope this helps :-)
If you go to Configuration Manager in Visual Studio you can set the platform to x86 or x64.