C++ program communication with a C#

Asked

Viewed 161 times

2

Good people, I’m going through a little problem, I have an application in c++ and I have to make the output of it read by a program made in C#. would you like to know if there is any way to do that? , would you like to have a communication between them.

  • 1

    Hello be welcome ! try to add some more details of your application in c++ in the statement, you can start with the code snippet , we have to understand how and made the "exit" of your program. The "output" would be text in a console application ?

  • Initially the output is done by console, but I wanted it to be otherwise, I do not have much c base++.

  • How about saving the output to a text file ( .txt ) ? so you can read in a program in C# I believe it would be the easiest way.

  • but I could make my program in c# check if there is content in that txt?

  • My real problem is this, I’m trying to develop an application that through a camera identifies the plate of a vehicle and sends this response to my program done in c#, I wanted to do everything in c# but I couldn’t find any tools to help me develop the identification part of the plate in this language, only in c++.

  • But Opencv for example is possible to integrate with C#

  • http://answall.com/q/69742/101

  • Opencv in C#: http://www.emgu.com/wiki/index.php/Main_Page

Show 3 more comments

2 answers

0


"i have an application in c++ and have to make the output from it be read by a program done in C#. I would like to know if it exists some way to do it?"

Yes, my suggestion is that you do the storage of the output information in a arquivo.txt.

The following examples are applications made in Console.

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

Program C++

#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 perform the reading of the text file. where so in your program c# will perform the desired treatment for plate information.

Program in C#

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 the namespace System.IO.

Obs : Note that a well simplified example, and was made to meet the need for everything that was said up to the moment.

You can consult the sources clicking here and here.

0

What you need is to realize Interop between applications.
If you have the module signature in C/C++, you can use this tool which makes mounting of types interfacing automatically:
Pinvoke Interop Assistant

Browser other questions tagged

You are not signed in. Login or sign up in order to post.