0

I have two process(.exe), once is implemented in C++ and another is implemented in C#. what I want is to communication between both the process. for that I have choose "Named Pipe" approach. the issue which I am facing is to pass a class object from one application to another. I am easily able to send a string data but I don't know how to send a class object from application to another. my class structure is like below:

enum information
{
 TITLE,
 STATUS,
 DEBUG,
 INFO,
 OTHER
};

class CInformation
{
  private:
    information _info;
    string _text;
  public:
    void setInformation(information info, string text) { _info = info; _text = text; }
    inline information GetInfo() { return _info; }
    inline string GetText() { return _text; }
};

so how to Serialize this class in C++, send it over named pipe and Deserialize it in C# and vice versa also for the same class. please give me an example. I am open for any other solution also for two way communication between both the process.

NIKHIL
  • 17
  • 4
  • 1
    Does this answer your question? [Object Sharing between Applications?](https://stackoverflow.com/questions/28335037/object-sharing-between-applications) –  Apr 03 '21 at 11:10

1 Answers1

1

Just as you chose named pipes you must now choose a serialization method/convention. If your C++ code has access to .Net through CLI then you are off to a good start because you can ensure that the same rules are applied at both ends. Otherwise you have options like JSON, XML, simple text strings or even binary. You may have a technical reason for making this choice (data and structure vs compactness etc) or it might be driven by the availability of tools/frameworks (probably steering you towards JSON or XML) to do (de)serialization for you. Note that even with simple text strings you will have to make sure that both sides use the same encoding (UTF-8, ASCII, ...).

Note that C++ and C# make no "language guarantees" to implement classes in any "compatible" way, it is up to you to map the two views to each other and/or structure the classes to have - for example - similar JSON-serialized layouts.

AlanK
  • 1,827
  • 13
  • 16