Communication of c# and c++

Asked

Viewed 104 times

5

How can I make the C# code call a variable that is in a C++ file for example. Knowing that I am using Visual Studio.

Code C++:

#include "stdafx.h"
#include <iostream>


int main()
{
    int test = 10;
    return 0;
}

but how can I access this variable in c#

  • It is not possible to do directly in the same source code... because the c# compiler works differently than c++.

  • There are ways to do this, incidentally great question !

  • Well I tried with Qt but it was a complete failure to make a I then decided to use the c# so I would urgently need it, but the tutorials of the forums are very old and messy

  • What is the call flow? It is your c++ application that will call a c#library, or it is a c# interface that calls a c library++?

  • 1

    Basically you need an interface, a method that allows you to access the variable value. Then compile the code c++ as a library dll so it can be accessed inside the code c#.

  • @Williamjohnadamtrindade c# calling a library in c++

  • Check out this article: Using C++ in C# by Example.

  • 1

    How do you want to do this? By dll (works, already done with Delphi and c#)? vc what inline source code? Create a CLR project in Solution? (works, you can have different language projects in the same Solution, C#,VB,C++)

  • @Yes but I need to establish a communication between the two

  • Dlls communicate with . exe through methods that pass primitive as parameters and return. Already if you have two projects, a C++ and another c# in visual studio maybe it’s easy because they can share classes

Show 5 more comments

2 answers

0


0

Since it is a single variable, keep the C++ variable saved in an XML and when you want to get it in c#, just read the xml. This idea of the interface by the file . dll is interesting to be used in a very heavy application.

Browser other questions tagged

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