Solved

Communication between C++ / C# applications

Posted on 2011-03-01
9
108 Views
Last Modified: 2015-06-21
I am launching an applicaton written in C# from within a C++ application and need to pass data to the C# application when it is launched and pass data back to the c++ application when the c# application is closed.  How can I accomplish this? I tried comman line arguments for the C++ to C# side and WM_COPYDATA for c# to c++ to no avail.  
0
Comment
Question by:harry12
9 Comments
 
LVL 6

Accepted Solution

by:
Mistralol earned 168 total points
ID: 35012329

Named pipe

0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 35013910
What kind of applications are they? Console, Winforms, server/client.
can you modify them (C# app) to a server app?
0
 

Author Comment

by:harry12
ID: 35017686
They are basic UI apps where the user enters in data and the data entered is eventually saved to a file. The C++ app should send data from a file to the c# app where the data will get updated.  The c# app needs to send the updated data back to c++ app where it will be saved.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Assisted Solution

by:mordorph
mordorph earned 166 total points
ID: 37856305
Why don't you just use the file as the neutral means of communication.  Since your already writing to a file, close it from c++.  Then open it in c#, work with it, close it.  And then the c++ app can take back over.
0
 
LVL 1

Assisted Solution

by:Hurty
Hurty earned 166 total points
ID: 38447047
So besides "NamedPipes" mentioned before, one good possibility is to use sockets
For C# you can use System.Net namespace and for C/C++ you can youe WSA (windows.h/winsock2.h) to establish a communication. This method is sure to work, but you will have to establish kind of a protocol. For example:

1. launch C++
2. launch C#
3. put C# in "listening" mode
4. trying to connect to C# socket
5. after connect send data to C# and put C++ in listening mode
6. process data within C# and connect to C++
7.receive data back in C++
8. close C# program
9. process returned data in C++
10. close C++ program

This is the basic algorithm :)
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 38452628
If the files do not have a lot of read/writes uses it and it is not slow, then you can use the file as a means of communication. Just be aware that your programs must :
- Lock the file for multiple read and exclusive write. e.g.
  lock alternatives  
  FileShare
- File permissions
- File contents encoding (ASCII, UTF-8 or Unicode)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38545869
If your C# application is a console application, I would suggest to output your result of your C# app to the console and trap the output from your C++ application.
There are lots of examples of that in internet, for example:
http://stackoverflow.com/questions/300669/launch-app-capture-stdout-and-stderr-in-c
http://ubuntuforums.org/showthread.php?t=610271
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question