Send string between apps

Just starting out? Need help? Post your questions and find answers here.
Wolf
Enthusiast
Enthusiast
Posts: 229
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Send string between apps

Post by Wolf »

Hi everyone

I want send big string variable from app1 to app2, what is the best or fastest way?
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Send string between apps

Post by mk-soft »

Over Network...

Link: viewtopic.php?f=12&t=73882
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Send string between apps

Post 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.
Wolf
Enthusiast
Enthusiast
Posts: 229
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Re: Send string between apps

Post 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.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Send string between apps

Post by infratec »

We told you already the easiest way on a local PC :wink:

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.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Send string between apps

Post by mk-soft »

Already considered to work with 1 app and to outsource the tasks to the threads...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Send string between apps

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Send string between apps

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: Send string between apps

Post 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

Code: Select all

EnumWIndows_(...
And you can handle the recieve by a windows callback and checking for #WM_COPYDATA.
Proud supporter of PB! * Musician * C64/6502 Freak
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Send string between apps

Post by IdeasVacuum »

See netmaestro's example here: viewtopic.php?t=29781
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Wolf
Enthusiast
Enthusiast
Posts: 229
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Re: Send string between apps

Post 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 :D
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Send string between apps

Post by Joris »

Using the clipboard... send and detect.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Send string between apps

Post 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.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Send string between apps

Post 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...
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
ZX80
Enthusiast
Enthusiast
Posts: 331
Joined: Mon Dec 12, 2016 1:37 pm

Re: Send string between apps

Post 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_()
Post Reply