Question:
How can I make C# code call a variable that is in a C++ file for example. Knowing that 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#
Answer:
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 you will import this dll and then call the native code within the managed code. There's a great series on MSDN talking about using Pinvoke.
- https://msdn.microsoft.com/en-us/library/eyzhw3s8.aspx
- https://msdn.microsoft.com/en-us/library/2x8kf7zx.aspx
Keywords for search: Pinvoke, Interop, dllimporter