Solved

Communication between C++ / C# applications

Posted on 2011-03-01
9
84 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
Comment Utility

Named pipe

0
 
LVL 35

Expert Comment

by:Miguel Oz
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Assisted Solution

by:mordorph
mordorph earned 166 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now