none
Best way to send data/object from one process (c layer) to another process .net core using IPC RRS feed

  • Question

  • Hi Team,

    Please suggest best solution for the data transfer from c layer to C# (.net core) in linux/windows environment.

    If possible please provide snippet code.

    My idea : For IPC named pipes and serialize and de serialization need help.

    Thanks in advance,

    Ravi

    Wednesday, July 31, 2019 2:00 PM

All replies

  • https://en.wikipedia.org/wiki/Data_transfer_object

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    The DTO would be in XML or Json 
    • Edited by DA924x Wednesday, July 31, 2019 5:19 PM
    Wednesday, July 31, 2019 2:48 PM
  • Did you really mean IPC, as in communication between different processes?  Or are you just interested in crossing the C/C# boundary within a single process?

    Named pipes are a Windows thing (well, Linux has them, but they're different).  A TCP socket can be a good way to communicate between processes, and they work the same across platforms.

    For the actual data format, as DA924x says, JSON and XML are both popular choices.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, July 31, 2019 5:38 PM
  • Hi RaviRaju,

    Thank you for posting here.

    I make a simple code, which could send data by using IPC.

       class Program
        {
            [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
    
            [DllImport("User32.dll")]
            public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
    
            static void Main(string[] args)
            {
                DoSendMessage("Hello, world");
                Console.WriteLine("success");
                Console.ReadKey();
            }
            private static void DoSendMessage(string message)
            {
                Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
                notepad.WaitForInputIdle();
    
                if (notepad != null)
                {
                    IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
                    SendMessage(child, 0x000C, 0, message);
                }
            }
        }

    Result:

    Besides, If you want to send data from c to c# .net core, I think you could ask in c forum instead of c# forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 1, 2019 5:49 AM
    Moderator
  • Thank you so much for the response,

    I have two process one is developed by native language (C) and another is developed by C#.net.

    I need to establish connection b/w two process using some IPC technigue.

    This two need to communicate and exchange the objects or structure.

    Thank you,

    Ravi


    • Edited by RaviRaju Thursday, August 1, 2019 9:32 AM
    Thursday, August 1, 2019 9:31 AM
  • Thank you so much for the response,

    I have two process one is developed by native language (C) and another is developed by C#.net.

    I need to establish connection b/w two process using some IPC technigue.

    This two need to communicate and exchange the objects or structure.

    Thank you,

    Ravi


    IMHO, you need a file system between the two processes that is  going to read/write either XML or Json between them.
    Thursday, August 1, 2019 11:23 AM
  • Then my previous answer still stands.  You can use a TCP socket to send the data, and use JSON or XML to encode the data for transmission.  Very common strategy.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, August 1, 2019 4:49 PM