C ++ data output to C #
Is there an easy way to get multiple variable data from a C ++ program in C #? Both programs will run on the same computer.
I need this to report the results of a C ++ encoded program (position: x, y (integer) and orientation (double)) to another device using C # cdk ...
I am thinking about allocating an area of memory and then declaring it in a file, reading the file in C # to get the pointers and then working from there using a semaphore to control access.
Will this work? Any links on how to write something like this in C # and C ++?
All help is greatly appreciated!
source to share
Sure! One example is shared memory: Sharing Variables Between C # and C ++ (this is what you mean when allocating memory, etc.)
The second method is "named pipes": http://www.codeproject.com/Tips/420582/Inter-Process-Communication-between-Csharp-and-Cpl
source to share
You can communicate between two separate processes in many ways. I point out a few of them -
- Inter Process Communication . The first one that I like is the inter-process communication known as IPC . There are many articles on it. Therefore I do not provide a sample code, you can get it from the code project here -
Interprocess communication between C # and C ++ using named pipes
- Shared memory . You can also use shared memory, I personally find it a little harmful because it breaks the rule for reading and writing to other program memory. Here is an example -
Swapping variables between C # and C ++
-
Database . This is only possible if both of your programs are using the same database. Very easy, you already know that. But it only works in limited cases.
-
Your own custom implementation Example: Writing to a file in place and then accessing that file for both programs.
Choose your choice !!! ... Personally, I would go to IPC for your case.
source to share
Since you are saying that both programs run on the same system, a simple solution would be to write the output of your C ++ program to a file and use that file as the input for your C # program. Perhaps you can use the FileSystemWatcher on the C # side to monitor this file for changes.
A few more links:
source to share