Example for reading other processes memory

I've been getting a lot of questions about howto read apps process memories
and a lot of people have been wanting to get examples on doing this. I've
sent my examples to a few people but they're way too complex to understand
(unlease that is the feedback I'm getting) so I've written a nice simple
example that simply reads a string value from one processes memory in
another process. Nice and simple example that will open doors to being able
to do whole lot of other neat stuff with other peoples process.

To make this example work, open the Sendprj in one instance of VB and the
receiveprj in another instance. Run them both and in the Sendprj textbox
just enter the receive threadid that is on displayed on the window itself.

Yeah I've also seen some questions about Hooks so the example utilizes hooks
instead of subclassing so if you want to know how to hook, it's also useful.

I would love some feedback on this to tell me if my explanations are
clear...Nothing I hate more then answering somebodies request and not
knowing if you're answer was what they wanted.

Since I can't post zip files, anybody who wants a copy of the code just send
me an email and I'll send it to you

Here is snippets of the code:

'Register your own window message
lngl = RegisterWindowMessage("MyMessage")
'set a value to send
strA = "Hello World"
'post the message to a thread...could've done a broadcast here and
forgotten about the thread
'but for example purpose I thought I'd use a normal easy post
PostThreadMessage CLng(Text1.Text), lngl, ByVal StrPtr(strA), Me.hWnd

Dim lngl As Long, lngl2 As Long, lngl3 As Long
Dim strA As String * 50

'Get The Message
CopyMemory A, ByVal LP, Len(A)
If A.Message = RegisterWindowMessage("MyMessage") Then
'Gets the process ID
GetWindowThreadProcessId A.LP, lngl
'Opens the process for reading
lngl3 = OpenProcess(PROCESS_VM_READ, 0, lngl)
'reads the processes memory
lngl3 = ReadProcessMemory(lngl3, ByVal A.Wp, ByVal strA, Len(strA),
'convert the string from unicode
strA = StrConv(strA, vbFromUnicode)
'display the message
MsgBox strA
End If
'Free the memory
CopyMemory strA, 0&, 0
'Send the hook up to the next hook in the chain
CallNextHookEx ByVal HookId, 0, ByVal Wp, ByVal LP

Hope this Helps,

Lee Amar
CTO OSTNet OpenSource Technologies
Advanced Computing Demands
Advanced Gaming Breaks