Page 1 of 2
Send string between apps
Posted: Sun Nov 10, 2019 8:26 pm
by Wolf
Hi everyone
I want send big string variable from app1 to app2, what is the best or fastest way?
Re: Send string between apps
Posted: Sun Nov 10, 2019 8:44 pm
by mk-soft
Re: Send string between apps
Posted: Sun Nov 10, 2019 9:08 pm
by infratec
If your data fits in one packet (1500 bytes)
Use UDP.
It is much faster and a loss on the same PC is nearly impossible.
It is also possible with larger datas, but then you need to handle the incomimg data stream.
Re: Send string between apps
Posted: Sun Nov 10, 2019 10:39 pm
by Wolf
Thanks but I mean on local system, something like share string variable between two program
My string variable is over 600 KB and updated every second in app1,after each string update i want send it (share) with app2 to process it.
Write and read from file is one basic way but i want faster way if possible.
Re: Send string between apps
Posted: Sun Nov 10, 2019 11:10 pm
by infratec
We told you already the easiest way on a local PC
Use localhost (127.0.0.1) as address and choose a free port.
As alternative you have to implement shared memory, which is far more complicated.
Re: Send string between apps
Posted: Sun Nov 10, 2019 11:42 pm
by mk-soft
Already considered to work with 1 app and to outsource the tasks to the threads...
Re: Send string between apps
Posted: Sun Nov 10, 2019 11:47 pm
by JHPJHP
Hi Wolf,
See
Windows Services & Other Stuff
-
\Windows_Services_Other_Stuff_SRC\Other_Stuff\CopyShare\...
NB*: Includes SendMessage text example and Shared Memory text and image examples.
Re: Send string between apps
Posted: Mon Nov 11, 2019 12:13 am
by skywalk
If you don't like tcp, just write it to Myfile4u.txt.
Then the reader opens and reads and clears it.
Myfile4u.0.
Re: Send string between apps
Posted: Mon Nov 11, 2019 12:28 am
by oreopa
On windows API you can use
Code: Select all
SendMessage_(hwnd, #WM_COPYDATA, #Null, *CopyData)
You need the window handle, which you can get from
And you can handle the recieve by a windows callback and checking for #WM_COPYDATA.
Re: Send string between apps
Posted: Mon Nov 11, 2019 12:51 am
by IdeasVacuum
See netmaestro's example here:
viewtopic.php?t=29781
Re: Send string between apps
Posted: Tue Nov 12, 2019 2:24 pm
by Wolf
Thank you all for your solutions.
After test all, i think best one for me and my program is using SendMessage with #WM_COPYDATA.
So thanks again @JHPJHP & @oreopa & @IdeasVacuum for SendMessage codes and examples, especially @JHPJHP for great CopyData example code in "Windows Services & Other Stuff" topic, thanks man

Re: Send string between apps
Posted: Tue Nov 12, 2019 10:37 pm
by Joris
Using the clipboard... send and detect.
Re: Send string between apps
Posted: Tue Nov 12, 2019 10:56 pm
by wombats
Joris wrote:Using the clipboard... send and detect.
That’s not a good way. The user wouldn’t appreciate it if something they have on the clipboard disappears.
Re: Send string between apps
Posted: Wed Nov 13, 2019 8:45 am
by Joris
wombats wrote:Joris wrote:Using the clipboard... send and detect.
That’s not a good way. The user wouldn’t appreciate it if something they have on the clipboard disappears.
It's just a possibility. Besides let Wolf decide what is useable and good.
What copy/paste does, is mostly well known, so...
Re: Send string between apps
Posted: Wed Nov 13, 2019 10:48 am
by ZX80
wombats, good question. Therefore I will ask here: how can I save/copy temporarily the global buffer (if not empty) with userdata in other place? Not destroy/clear, but make backup userdata (pictures, links, text etc.) somewhere in available memory block. If I need use the global buffer for my things for a short time. Then to be able to recover userdata. And user will not see changes.
There is some code for analys the global buffer content (to determine type of text):
Code: Select all
OpenClipboard_(0)
lR = EnumClipboardFormats_(lR)
Select lR
Case #CF_TEXT
Debug "Text"
hStrPtr = GetClipboardData_(lR)
MessageRequester("ClipBoard Text", PeekS(hStrPtr,-1,#PB_Ascii), 0)
Case #CF_BITMAP
Debug "Bitmap Picture"
Case #CF_METAFILEPICT
Debug "Meta-File Picture"
Case #CF_SYLK
Debug "Microsoft Symbolic Link (SYLK) data."
Case #CF_DIF
Debug "Software Arts' Data Interchange information."
Case #CF_TIFF
Debug "Tagged Image File Format (TIFF) Picture"
Case #CF_OEMTEXT
Debug "Text (OEM)"
hStrPtr = GetClipboardData_(lR)
String.s = PeekS(hStrPtr,-1,#PB_Ascii)
OemToChar_(@String, @String)
MessageRequester("ClipBoard Text", String, 0)
Case #CF_DIB
Debug "DIB Bitmap Picture"
Case #CF_PALETTE
Debug "Colour Palette"
Case #CF_PENDATA
Debug "Pen Data"
Case #CF_RIFF
Debug "RIFF Audio data"
Case #CF_WAVE
Debug "Wave File"
Case #CF_UNICODETEXT
Debug "Text (Unicode)"
hStrPtr = GetClipboardData_(lR)
MessageRequester("ClipBoard Text", PeekS(hStrPtr,-1,#PB_Unicode), 0)
Case #CF_ENHMETAFILE
Debug "Enhanced Meta-File Picture"
Case #CF_HDROP
Debug "File List"
Case #CF_LOCALE
Debug "Text Locale Identifier"
Default
Debug "Unknown encoding or data = " + lR
hStrPtr = GetClipboardData_(lR)
MessageRequester("ClipBoard Text", PeekS(hStrPtr,-1,#PB_Unicode), 0)
EndSelect
CloseClipboard_()