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++.
– Leonardo Bonetti
There are ways to do this, incidentally great question !
– Leonardo Bonetti
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
– Nathan Miguel
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++?
– William John Adam Trindade
Basically you need an interface, a method that allows you to access the variable value. Then compile the code
c++
as a librarydll
so it can be accessed inside the codec#
.– Ricardo Pontual
@Williamjohnadamtrindade c# calling a library in c++
– Nathan Miguel
Check out this article: Using C++ in C# by Example.
– William John Adam Trindade
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++)
– jean
@Yes but I need to establish a communication between the two
– Nathan Miguel
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
– jean