?
Solved

Communication between C++ / C# applications

Posted on 2011-03-01
9
Medium Priority
?
154 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 672 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Assisted Solution

by:mordorph
mordorph earned 664 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 664 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

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

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)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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