Solved

Communication between C++ / C# applications

Posted on 2011-03-01
9
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Accepted Solution

by:
Mistralol earned 168 total points
ID: 35012329

Named pipe

0
 
LVL 36

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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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 36

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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)…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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