Results 1 to 6 of 6

Thread: How do I transfer in-memory data from one program to another easilly?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,238

    How do I transfer in-memory data from one program to another easilly?

    I've created these two test programs. Basic operation is this.

    One defines a Long type variable "a" and assigns it a value.
    Then the second one is run and it establishes a TCP connection to the first (they both are using Winsock for the initial connection).
    Then the first one uses VarPtr to get the address of the variable "a" and sends this memory address over the TCP connection to the second program.
    Then the second program attempts to directly access the value stored in the variable "a" from the first program, using the CopyMemory API command.
    But then that second program crashes (as in it completely crashes the VB6 IDE that the program was running from, just as if I'd given CopyMemory an invalid memory address, but it's VERY valid, as it was taken directly from the first program).

    Here is the code for the first program.
    Code:
    Dim a As Long
    Private Sub Form_Load()
    a = 12345
    Server.Listen
    End Sub
    
    Private Sub Server_ConnectionRequest(ByVal requestID As Long)
    Server.Close
    Server.Accept requestID
    End Sub
    
    Private Sub Server_DataArrival(ByVal bytesTotal As Long)
    Dim Text As String
    Server.GetData Text
    If Text = "Ready" Then Server.SendData VarPtr(a)
    End Sub
    Here's the code for the second program.
    Code:
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Private Sub Client_Connect()
    Client.SendData "Ready"
    End Sub
    
    Private Sub Client_DataArrival(ByVal bytesTotal As Long)
    Dim Address As Long
    Dim Value As Long
    Client.GetData Value
    CopyMemory Value, ByVal Address, 4
    MsgBox Value
    End Sub
    
    Private Sub Form_Load()
    Client.Connect "127.0.0.1", 12000
    End Sub
    Using memory like this so that the programs could share memory addresses would be faster for copying large quantities of data like raw pixel data from pictures, than it would be to send the all the data over TCP. TCP should just be used to share the numbers that are the memory addresses. This way I could have a collection of image processing tools, each its own program (exe file) but they could ALL have access to the same image data in memory. For example I could have imageprocessor.exe and separately imageloaderplugin.exe, and the first program would run the second, the second program would load the image, and store it in memory, and then the first program would get the image by reading the raw pixel data that was stored in memory by the first program.

    I don't understand why it isn't working. I don't know why VB6 keeps crashing. Also, if there's an easier way to accomplish sharing of data between programs (without the saving of a temporary file), then please let me know.
    Last edited by Ben321; Jan 10th, 2013 at 03:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width