Passing data between C++ (MFC) app and C#

前端 未结 9 1331
一向
一向 2020-12-31 17:45

We have a monolithic MFC GUI app that is nearing the end of it\'s life in C++. We are planning to build new functionality in C# and pass data between each app.

Quest

相关标签:
9条回答
  • 2020-12-31 18:29

    The options you list are certainly valid, but you could also consider COM.

    0 讨论(0)
  • 2020-12-31 18:31

    My picks would be either standard window messages (e.g. WM_FOO) or DCOM:

    • Messages would work as long as the communication is very simple, and the overhead in setting it up is minimal. If you can boil the communication down to one or two integers per message, this would probably be a good place to start. If both apps are already windowed applications, they both already have message loops, so you're already most of the way there.

    • DCOM requires a lot more programmer overhead, but it's nice in that you can define a richer interface and avoid having to convert complex messages to/from binary form. If you go this route, CoRegisterClassObject is the starting point for publishing an object via DCOM. I've never tried doing this from a C# app, but in principle it should be entirely possible

    0 讨论(0)
  • 2020-12-31 18:35

    Take your pick:

    • files
    • named pipes <-- My recommendation
    • shared memory
    • sockets
    • COM
    • Windows messages

    Why named pipes?

    • Gives you a FIFO way of working for free (like sockets, but not like shared memory)
    • Can easily communicate both ways
    • Well supported on all platforms
    • Easy to use
    • Reliable data passing and delivery
    • Can be blocking and non blocking
    • Can read data without removing (unlike sockets)
    • Can be expanded to include a third app easily.

    In .Net just use System.IO.Pipes.

    In C++ use CreateNamedPipe and CreateFile.

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