Can I configure a WinForms application to work as "x86" without recompiling?

Is it possible to configure the WinForms application for "Any CPU" to work as "x86" on a 64-bit server without recompiling the application? In particular, I am looking for an app.config parameter or a control panel applet to achieve this. All client clients are x86, but the server is x64, and we like to install the WinForms application on the server for administrators to configure and monitor the system. We would rather not recompile only for the server.

+4
source share
3 answers

From http://www.request-response.com/blog/PermaLink,guid,34966ef8-3142-46b2-84e0-372b5c36ddcc.aspx

However, you can control and override this default behavior even after compiling the code. There is a convenient tool called corflags.exe in the SDK, which allows you to forcibly compile "anycpu" code to use a 32-bit process in a 64-bit world.

Using this utility can be found here http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx

+11
source

Configuration is not needed if you have written managed code correctly. As long as the corresponding frameworks are installed on the 64-bit machine, the JIT process will take care of any differences between the 32 and 64-bit requirements.

The only thing you need to worry about in your own code is what you did P / Invoke. In this case, when you call an API function that uses the HANDLE or void * type, you need to make sure that you always use System.IntPtr, not System.Int32. In the .NET world, the int data type is ALWAYS 32 bits, even on a 64-bit machine. Likewise, the longest is always 64 bits, regardless of architecture.

And IntPtr, however, always has a void * size and therefore the correct JIT is for different sizes depending on the architecture of the machine you are running on.

+1
source
+1
source

Source: https://habr.com/ru/post/1277612/


All Articles