Full duplex operation, functions C++ C#

Noah Aas 585 Reputation points
2025-01-30T18:47:23.8+00:00

I have a C# application and a C++ application. Between the two, data should now be exchanged.

In C# 
   ReceiveDataFromCPP(String data)    
   SendDatatoCPP(string data)       
   
In C++ 
   ReceiveDataFromCSharp(String data)
   SendDatatoCSharp(string data)      

  How can I achieve this?    I think I need CLI.       
Can you give me an example?  

I don't know when who sends what, it's event-oriented.

Picture, overview

Full_Duplex_C#C++

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
342 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,266 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,842 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Minxin Yu 12,506 Reputation points Microsoft Vendor
    2025-01-31T07:13:38.9966667+00:00

    Hi,

    Windows Message, you can refer to the sample:
    https://learn.microsoft.com/en-us/windows/win32/dataxchg/using-data-copy

    The following example demonstrates how to send information between two applications using the WM_COPYDATA message.

    For named pipes, check sample: How to: Use Named Pipes for Network Interprocess Communication

    Using Pipes

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. RLWA32 46,756 Reputation points
    2025-02-02T16:16:36.61+00:00

    @Noah Aas I put together a sample that demonstrates using WM_COPYDATA to transfer strings between two different processes. The sample was created with VS2022 and includes an MFC C++ application and two C# Winforms applications (.Net Framework 4.8 and .Net 8). The sample applications transfer unicode strings (UTF-16LE) so do not change character encodings without making the appropriate changes to the sample code. The samples use a registered windows message to broadcast their process id and main window handle when they start up. So they can be started in any order. These samples were written so that only two processes can communicate with each other.

    You can get the samples from https://1drv.ms/u/c/c389bf4121acea69/EfJ-SJJqXI9Fk2LruNlkr4oBjXrHT1q9skW_Y1dUe92_cg?e=NXaucj Don't forget to unblock the zip file before extracting the contents.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.