C# AnyCPU and Read/WriteProcessMemory
My C# program is compiled with AnyCPU option and i am using P/Invoke to call native apis this way:
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out UIntPtr lpNumberOfBytesWritten);
My guestion is, can my c# program read开发者_JAVA技巧 from and write to both 32bit and 64bit processes since its compiled with anycpu? or would be there problems? i am asking this because i have only 32bit OS so i can't test it. Thx
On a 32 bit OS, all processes are 32 bit and so no issues arise. On a 64 bit OS your AnyCPU process runs 64 bit and the only possible mismatch is then with 32 bit processes. But it's no problem to store a 32 bit address in a 64 bit pointer. If you were trying to read/write memory in a 64 bit process from a 32 bit process you would be stuck. But since you are doing the opposite there's no trouble.
精彩评论