What is the preferred way of passing data between two applications on the same system?

前端 未结 6 1351
情书的邮戳
情书的邮戳 2020-12-05 06:07

I have an application (A) that needs to launch another application (B). I need to pass data between the applications. I can think of two approaches. The first is to open

相关标签:
6条回答
  • 2020-12-05 06:12

    The simplest method (assuming Windows since you mention a DLL) is probably to use CreateProcess and open a pipe to the child process, as described in simplified form here: http://msdn.microsoft.com/en-us/library/ms682499.aspx

    Named Pipes can be an alternative, especially if you aren't in control of the lifetime of all of the processes. http://msdn.microsoft.com/en-us/library/aa365590.aspx

    For simple cases, mailslots may be a sufficient alternative.

    http://msdn.microsoft.com/en-us/library/aa365574.aspx#base.using_a_mailslot_for_ipc

    Here's a longer list of various Interprocess Communication techniques for Windows. http://msdn.microsoft.com/en-us/library/aa365574.aspx

    For something happening locally, using sockets seems sort of overkill. Plus you have to implement your own security mechanism to prevent spoofing attacks, rather than depending on the integrated security mechanism of most of the other IPC methods.

    0 讨论(0)
  • This might help. Sharing Files and Memory

    0 讨论(0)
  • 2020-12-05 06:18

    I would agree somewhat with Juan Zamora M except that the service providing the data should have an API that can be requested when needed not pushed when changed via listeners.

    0 讨论(0)
  • 2020-12-05 06:26

    You can't effectively share data via a DLL. Other ways:

    • disk files
    • pipes
    • shared memory
    • messages
    • RPC
    • CORBA
    • COM
    • etc.
    0 讨论(0)
  • 2020-12-05 06:26

    Its always good to explore alternative possible solutions, but I personally believe that using sockets as a transport layer for data between applications is not only future proof, but scalable as well. Using sockets will eliminate the need for you to write copious amounts of OS specific code, which could proclude you from porting your application in the future to non-Windows operating systems.

    I would suggest sockets.

    0 讨论(0)
  • 2020-12-05 06:31

    You can have a shared cache (example a windows service or hidden process) that can be listening - returning data to all subscribers. This using a Observer pattern approach.

    0 讨论(0)
提交回复
热议问题