Program communication in C ++ with one in C # [closed]

2

Good people, I'm going through a little problem, I have a c ++ application and I have to get the output of it to be read by a C # program. I would like to know if there is any way to do this? I wanted to have a communication between them.

    
asked by anonymous 12.04.2016 / 13:13

2 answers

0
  

"I have an application in C ++ and I have to get the output of it   be read by a program done in C #. I would like to know if there is   any way to do that? "

Yes , my suggestion is that you store the output information in arquivo.txt .

The following examples are applications made with Console .

The first example is a program with c++ that creates and writes the board information to a file .txt

C ++ Program

#include <iostream>
#include <fstream>
using namespace std;
int main () {
  ofstream myfile;
  myfile.open ("Placa_Veiculo.txt");
  myfile << "ABC-1234";
  myfile.close();
  return 0;
} 

The second will read the text file. where in this program c# will perform the desired treatment for the plate information.

C # program

static void Main(string[] args)
        {
            try
            {   // abrir arquivo de texto usando stream reader.
                using (StreamReader sr = new StreamReader(@"C:\Users\usuario_do_mal\Desktop\Pasta do meu Projeto C++\Placa_Veiculo.txt"))
                {
                    // Ler arquivo e armazenar a informação da placa
                    String Leitura_Arquivo = sr.ReadToEnd();
                    string Placa = Leitura_Arquivo;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Erro  :");
                Console.WriteLine(e.Message);
            }
        }

Remember to use namespace System.IO .

Obs : Note that a very simplified example, and was made to meet the need for everything that has been said so far.

You can check the sources by clicking here and here .

    
12.04.2016 / 18:17
0

What you need is to perform interop between the applications. If you have the module signature in C / C ++, you can use this tool that does the autotype assembly of types automatically:
PInvoke Interop Assistant

    
12.04.2016 / 15:27