最近学校上vb.net的课,vb以前学过一点点,只会看不会写,不过没有办法,学校开的,所以几个人就组了个小组,写一个vb.net下的杀毒软件,要用到readprocessmemory来读取其它进程的内存,可以怎么调用也不行,goole和baidu找了n个小时。提这个问题的人倒是一大堆,可以是没有人解决过,但是其中也给我一些其实,后来在好友freecat的帮助下,找到了问题的所在,主要就是readprocessmemory声明的问题,我们应该这样声明
public declare function readprocessmemory lib “kernel32” (byval hprocess as integer, byval lpbaseaddress as integer, byval lpbuffer() as byte, byval nsize as integer, byref lpnumberofbyteswritten as integer) as integer
主要是其中的,byval lpbaseaddress as integer, byval lpbuffer() as byte
要设为byval而不是byref
这样调用就可以得到返回值了。
[code]
private declare function openprocess lib “kernel32.dll” _
(byval dwdesiredaccess as integer, byval binherithandle as integer, byval dwprocessid as integer) as integer
public declare function readprocessmemory lib “kernel32” (byval hprocess as integer, byval lpbaseaddress as integer, byval lpbuffer() as byte, byval nsize as integer, byref lpnumberofbyteswritten as integer) as integer
private const process_vm_read as long = &h10
dim ph as integer
dim i as integer
dim h as integer
dim buffer(20) as byte
dim bytesread as integer
获得进程
ph = openprocess(process_all_access, false, 1832)
if ph then
messagebox.show(“true”)
h = readprocessmemory(ph, &h403000, buffer, buffer.length, bytesread)
for i = 0 to buffer.length – 1
tempmem += buffer(i).tostring
next
else
messagebox.show(“false”)
end if
[/code]