Announcement

Collapse
No announcement yet.

Sharing Data between processes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sharing Data between processes

    I am looking at using context menus in windows to either send file names or folders to my program. However if the program is already open, rather than sending this information to a new instance I would like to have the running instance receive the data. This data will obviously be passed via the command line, but I am wondering how to you get STRING DATA to another instance? I have looked at MUTEXs but they don't really seem to have a way to do this, so maybe a custom windows message?? ie. Store data in a buffer in the new instance and then send a custom message to the original instance passing the address of this buffer to it, so that it can access the data?

    Is there a better or safer way of doing this (without using a disk file for data passing)?

    Anyone have any thoughts on this, or have done something similar?
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

  • #2
    There's lots of ways to share data across processes, and demos of all here.

    >This data will obviously be passed via the command line.

    That's not quite that obvious. When you use this method, you WILL launch a new instance of the target program; however, the target program will have to be smart enough to know another instance is already running, in which case it will send that info to that running instance and then just end.

    To share string data across processes, a global atom is probably the easiest form of the "data storage" to implement. That's limited to 255 bytes (which is LESS THAN %MAX_PATH, so may not work to send filenames) . If you need more storage, you can use a memory-mapped file object as demo'd here: Win32: Memory Mapped Files/Control User Count April 26, 2001

    The trickier part of your challenge will be 'contacting' the running instance of the program and telling it it has new data to process.

    If it's a GUI program, you can send it a WM_COPYDATA message and have your program process that message. (assuming you can obtain handle to the window). (This has the benefit of not requiring storage, Windows will handle all that for you in the WM_COPYDATA message)

    If a window handle is not available, you can have your server program wait on a named event... or wait on a TCP or UDP message.... or wait on pipe or mailslot activity.. or wait on a file ...

    MCM
    PS: The linked demo will show you how to detect if an instance is already running if you want to go the command-line route...
    Last edited by Michael Mattias; 21 Aug 2009, 09:12 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thanks Michael. I can already detect whether the other instance is running, and can get it's handle from the new instance. I was more concerned about getting string data from the new to the existing instance. I will check out the WM_COPYDATA message. It seems like it might do what I need.
      Scott Slater
      Summit Computer Networks, Inc.
      www.summitcn.com

      Comment

      Working...
      X