VB - API - Memory - Project - Inter Process String Transfer
The attached project shows how two separate VB applications can share String Data with each other without using Winsock or an intermediary file on the disk, using API calls to read the memory of the other process.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
That is exactally what I am trying to do.
Thank you very much, oh, and Mirrion if he is reading this thread...
I am transfering byte arrays, so I will rewrite some of your code to take into account for this and also will add buffering to the server
For sharing strings my preference would be to use the global atom table. This is a global resource that stores strings and can be accessed from any program in user space without having to worry about cross process memory access.
VB Code:
Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Declare Function GlobalGetAtomName Lib "kernel32" Alias "GlobalGetAtomNameA" (ByVal nAtom As Integer, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Declare Function GlobalDeleteAtom Lib "kernel32" Alias "GlobalDeleteAtom" (ByVal nAtom As Integer) As Integer
Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
Can someone please tell me what UI am doing wrong? Apart from working with computers...
The pointer, to the string, and the length of the string, that get put into my udtDataStructure type get reproduced on the server. but from these pointer and length values I cannot get my string
Me = fool, bad Woka *SLAP* [just edited this line since it said mer = fool, it was supposed to say me and not a ref to mirron]
Cheers...
Right, I have modified the code so it now passes varible length strings between apps using byte arrays. The server can now repond with a msg back to the client after it's processed the data
Kleinma, you could pass your Command() params using this method I would...
Woka
Last edited by Wokawidget; Apr 7th, 2003 at 09:08 AM.
U could also push the least significant bit 2 bits to the right and pop the semi - significant bit 4 bits to left and the move the most significant bit right out of its memory space! That would speed things even faster
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
A super golden sample for me after scrathing my head for weeks with regard to my IPC programs which use custom window messages (instead of WM_COPYDATA) to send string data.
Excellent work, KayJay.
Anyway, can someboy tell me what are those parameters as shown below mean? (such as: ByVal (Pointer - 4), StringLengthInBytes, 4, ReadLength etc)
Pointer: The memory address from which the values are being read.
ByVal (Pointer - 4) : The length of a string variable is stored as a long just before actual memory address of that variable. We retrieve that to make sure the correct number of bytes and therefore the correct string is read.
StringLengthInBytes : The variable to hold the length of the string
4 : As the length is a Long, therefore, 4 bytes.
ReadLength : A return value to store the actual number of bytes that are read.
So we open the process "hProcess", seek memory address "Pointer - 4", read 4 bytes from that address - a Long - and get the length of the String that we want. We then, using
ensure the variable to hold the string is correctly initialized, as VB stores in Unicode, the actual number of characters in the string is twice when stored in memory. Then we read the process "hProcess" at the memory address "Pointer" exactly the number of bytes that the String contains, i.e. StringLengthInBytes, and move that string to the buffer ReceiveString.
We now have the required String value as stored in the "hProcess"'s memory into a variable "ReceiveString" which resides in the current process's memory.
HTH
Regards
Kaushik Janardhanan
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia