Send message from C# to C++

M

Magdy

Hello,

I have two applications, one c# and another c++. I want the c# one to
run the c++ application and sends message (ex. string ... certain data
needed to initialize the c++ application) to it.

Please, help me... how to implement that in both sides (C# sends
message & C++ receives it)

Any thoughts, ideas, advice will be highly appreciated. :)
Thanks!
 
C

Camiel

Couldn't you simply use Process.Start() to start the C++ application
with some command line arguments (the data you want to pass), and pick
up that data from the arguments list to main() in the C++ app?
 
M

Maxim Yegorushkin

I have two applications, one c# and another c++. I want the c# one to
run the c++ application and sends message (ex. string ... certain data
needed to initialize the c++ application) to it.

Please, help me... how to implement that in both sides (C# sends
message & C++ receives it)

Any thoughts, ideas, advice will be highly appreciated. :)

You can redirect standard input and output of your C++ program, so
that it receives commands on its standard input from a C# application,
and writes responses into its standard output, which the C#
application reads.

Or, if the C++ application is a standalone server, you can use TCP
sockets for sending commands and receiving responses.
 
M

Magdy Wageeh

Couldn't you simply use Process.Start() to start the C++ application
with some command line arguments (the data you want to pass), and pick
up that data from the arguments list to main() in the C++ app?

Thanks both of you!
I used the Process & StartInfo in c# and sent data in arguments using
the command line to c++.

very simple, thanks once more. :)
 
C

cr88192

I have two applications, one c# and another c++. I want the c# one to
run the c++ application and sends message (ex. string ... certain data
needed to initialize the c++ application) to it.

Please, help me... how to implement that in both sides (C# sends
message & C++ receives it)

Any thoughts, ideas, advice will be highly appreciated. :)

<
You can redirect standard input and output of your C++ program, so
that it receives commands on its standard input from a C# application,
and writes responses into its standard output, which the C#
application reads.

Or, if the C++ application is a standalone server, you can use TCP
sockets for sending commands and receiving responses.

or, if running within the same process, one can make use of C code (true, or
'extern "C" { ...}') and P/Invoke...

C# -> C, C -> C++

getting things the other way (C++ -> C#) is a little harder AFAIK (not much
real experience with .NET in my case...), although particular .NET VMs are
likely to provide APIs for this case.
 
J

Jorgen Grahn

You can redirect standard input and output of your C++ program, so
that it receives commands on its standard input from a C# application,
and writes responses into its standard output, which the C#
application reads.

That is usually a bad idea, prone to lockups. (Just *one* of the
directions is usually a good idea, known as popen()).

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top