locked
Readprocessmemory in C#

    Question

  • Hello,

    I'd like to read memory process in C#. I made something similar in C++, but i don't see function in C#? Can someone give simple read process memory example? Do i need to add some usings or references?

    Monday, April 30, 2012 8:53 AM

Answers

  • .NET has a Process class but it doesn't offer any read/write process memory functionality. You will have to PInvoke the Win32 functions ReadProcessMemory / WriteProcessMemory.

    • Proposed as answer by Konrad Neitzel Monday, April 30, 2012 9:11 AM
    • Marked as answer by pioncze Monday, April 30, 2012 9:24 AM
    Monday, April 30, 2012 8:57 AM

All replies

  • .NET has a Process class but it doesn't offer any read/write process memory functionality. You will have to PInvoke the Win32 functions ReadProcessMemory / WriteProcessMemory.

    • Proposed as answer by Konrad Neitzel Monday, April 30, 2012 9:11 AM
    • Marked as answer by pioncze Monday, April 30, 2012 9:24 AM
    Monday, April 30, 2012 8:57 AM
  • You likely need to add the following using 

    using System.Runtime.InteropServices;

    because that's the namespace where DllImportAttribute is declared.

    In addition you should use IntPtr for dwSize and lpNumberOfBytesRead because in Win32 they are SIZE_T, this means 32 bit on x86 and 64 bit on x64.

    Monday, April 30, 2012 9:29 AM