Why is my application, which I compiled with AnyCPU, running as a 32-bit process on my 64-bit machine, and therefore unable to interact with Notepad, which is running as a 64-bit process?
I have the following code which will not run on x64 Operating System since notepad.exe
is x64 and a x86 application cannot get the modules information of a x64 process:
prc.Modules[0].FileName
.Net Exception throws on my code:
System.ComponentModel.Win32Exception (0x80004005): A 32 bit processes cannot access modules of a 64 bit process.
According to many answers and articles on this forum, MSDN, ..., I know that I need to use AnyCPU instead because of the fact that using x64 has no specific benefit for me. Even when Compile on AnyCPU configuration, my error persists, furthermore, in Task Manager I see a (32-bit)
at the end of my process name.
(Actually I tested the code with checking performance and the x64 code ran ~40 ms faster. never mind I do not want my code run 40 ms faster :D )
I do not know that is wrong.
VS 2011 Beta (x64)
Windows 8 Consumer Preview (x64)
Sincerely yours, Peyman Mortazavi
The 64-bit versions of Windows don't provide support for 16-bit binaries or 32-bit drivers. Programs that depend on 16-bit binaries or 32-bit drivers can't run on the 64-bit versions of Windows unless the program manufacturer provides an update for the program.
Click Start, type system in the search box, and then click System in the Control Panel list. The operating system is displayed as follows: For a 64-bit version operating system: 64-bit Operating System appears for the System type under System.
The difference in performance between 32-bit and 64-bit versions of applications depends greatly upon their types, and the data types they are processing. But in general you may expect a 2-20% performance gain from mere recompilation of a program - this is explained by architectural changes in 64-bit processors [1].
Furthermore, if you run a 32-bit program on a 64-bit machine, it will run perfectly because the program will take the computer as if it was a 32-bit machine. This happens because the processor enters a special mode and hides all the 64-bit extensions and libraries.
Though the questioner has accepted the answer, I feel like the answer is incomplete since the questioner has mentioned that he is using Visual Studio 2011 and hence assuming the target .Net Framework would be 4.5 there are few caveats with respect to what "AnyCPU" means.
Please refer to both these links, to get a better understanding of how the meaning of "AnyCPU" has changed over time.
From these links, you can arrive at the answer to the question of why your application is running as 32 bit process
On a 64-bit Windows operating system:
Executables compiled with /platform:anycpu32bitpreferred execute on the 32-bit CLR.
Here is your culprit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With