• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1194
  • Last Modified:

Reading from memory location pointer vb6, how??

How do i read from a pointer location in memory in vb6?  No matter what I do copymemory crashes once compiled and run as an exe.    How do I read from a known memory location (it's a long) without crashing???

I'm using this code to receive ipc messages from my dll.

Public Function IPCCallbackFunction(ByVal IPCname As String, ByVal messageBuf As Long, ByVal messageLen As Long, answerBuf As Long, ByVal answerLen As Long) As Long

ReDim ByteArrayBuf(1 To 255) As Byte
Dim Msg As String

Call CopyMemory(ByteArrayBuf(1), ByVal messageBuf, ByVal messageLen)

Msg = Left$(StrConv(ByteArrayBuf, vbUnicode), messageLen)
Form1.Text1.SelText = Msg & vbCrLf

'If answerLen <> 0 Then
'   Msg = "Reply back from VB" & Chr(0)
'   messageLen = Len(Msg)
'   Call CopyMemory(answerBuf, ByVal Msg, ByVal messageLen)
'End If

'ByteArrayBuf = Empty

IPCCallbackFunction = True

End Function
1 Solution
Have you read this:
And does this help.
There are 3 possible reasons why your copymemory crashes
1. messageLen > 255. To prevent this, use
ReDim ByteArrayBuf(1 To messageLen) As Byte
2. messageBuf=0 - check this prior to CopyMemory call:
If messageBuf<>0 Then
   CopyMemory .....
End If
3. Your dll return memory from another process. In this case you have to know processID or hProcess
and use ReadProcessMemory API instead of CopyMemory
Also, try to check memory permissions using VirtualQuery (VirtualQueryEx for remote proc) for VM_READ and probably change permission with VirtualAlloc(Ex)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now