Reading from memory location pointer vb6, how??

Posted on 2007-08-11
Last Modified: 2008-01-09
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
Question by:bluedragon99
    LVL 8

    Expert Comment

    Have you read this:
    And does this help.
    LVL 27

    Accepted Solution

    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

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now