.NET Framework Bookmark and Share   
 index > .NET Base Class Library > reading process memry .. ?? wats is wrong in the follwing code
 

reading process memry .. ?? wats is wrong in the follwing code

can anyone tell me wats wrong with following code its giving me error like :

Error1The best overloaded method match for 'p.Program.ReadProcessMemory(System.IntPtr, System.IntPtr, byte[], uint, out System.IntPtr)' has some invalid argumentsE:\ani\p\p\Program.cs4727p

Error2Argument '3' should not be passed with the 'out' keywordE:\ani\p\p\Program.cs4775p




using

System;

using

System.Collections.Generic;

using

System.Text;

using

System.Diagnostics; // For the Process class

using

System.Runtime.InteropServices;

namespace

p

{

class Program

{

[

DllImport("Kernel32.dll")]

public static extern IntPtr OpenProcess(int dwDesiredAccess, bool

bInheritHandle,

Int32 dwProcessId);

[

DllImport("Kernel32.dll")]

public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] lpBuffer, UInt32 nSize, out IntPtr lpNumberOfBytesRead);

[

DllImport("Kernel32.dll")]

public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr

lpBaseAddress, [

In, Out] byte[] lpBuffer, UInt32 nSize, out IntPtr lpNumberOfBytesWritten);

[

DllImport("Kernel32.dll")]

public static extern int GetLastError();

public static readonly int PROCESS_VM_READ = 0x0010;

public static readonly int PROCESS_VM_WRITE = 0x0020;

static void Main(string[] args)

{

Process[] p = Process.GetProcessesByName("notepad");

ProcessModule pm = p[0].MainModule;

Console.WriteLine(pm.BaseAddress + ":" + p[0].Id);

IntPtr hProcess = OpenProcess(PROCESS_VM_READ, false, p[0].Id);

Console.WriteLine(hProcess);

byte[] cptr = new byte[4];

IntPtr xptr;

bool result = ReadProcessMemory(hProcess, pm.BaseAddress, out cptr, 200, out xptr);

Console.WriteLine(result + ":" + xptr);

}

}

}

aniruddha84
thx buddy ... its working fine ..
  • Marked As Answer byaniruddha84 Wednesday, July 22, 2009 5:50 AM
  •  
aniruddha84
You can't pass an in,out parameter as out parameter like you do.

See pinvoke.net how to invoke the windows API function.

Defining a parameter as in,out is the default (passing an object by reference). According to pinvoke, the 3rd should be defined as out only.

Geert van Horrik - CatenaLogic
Visit my blog: http://blog.catenalogic.com
Geert van Horrik
That's right,
All you need to do just write the following

bool

result = ReadProcessMemory(hProcess, pm.BaseAddress, cptr, 200, out xptr);

it works with me
Thanks


We are volunteers, if the reply help you mark it as your answer. thanks!!
http://mohamed-radwan.spaces.live.com/default.aspx
M.Radwan
thx buddy ... its working fine ..
  • Marked As Answer byaniruddha84 Wednesday, July 22, 2009 5:50 AM
  •  
aniruddha84

You can use google to search for other answers

Custom Search

More Threads

• Populating (DataGridView) Combobox with databinding in relational tables?
• Is there a way to draw a specific glyph from a font to a bitmap?
• Storing a generic class in a dictionary
• How to make TraceSource print DateTimes in local time instead of GMT?
• Issue with Process.Start
• Datarecieved event not firing
• CodeDom region and comment directives scope.
• How Can I Detect if I am running in a windows or web Enviroment?
• Using Action
• Problem using DirectorySearcher class : target of an invocation.System.Runtime.InteropServices.COMException...