Communication of C # and C ++

5

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

C ++ code:

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


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

but how can I access this variable in C #

    
asked by anonymous 24.07.2018 / 19:05

2 answers

0

You need to do interop. Basically you will generate a dll in c ++ exposing an interface to be consumed in C #. In the c # application tu will import this dll and then call the native code inside the managed code. On MSDN you have a great series talking about using Pinvoke.

Keywords for search: Pinvoke, Interop, dllimporter

    
25.07.2018 / 13:57
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 through the .dll file is interesting to use in a very heavy application.

    
28.07.2018 / 01:25