I have Win32 C++ DLL that reads a named shared memory, I want to export these values that the app receives to a C# application.
Actually, I have this code, but when I will access the values in C# App, I receive this:
An unhandled exception of type 'System.AccessViolationException' occurred in ETS2 Utilities.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
C++ code:
extern "C" {
__declspec(dllexport) int __cdecl returnGear();
}
extern int __cdecl returnGear()
{
return shared_memory->gear;
}
C# code:
[DllImport("ETS2_Utilities_Plugin.dll")]
public static extern int returnGear();
void GetData()
{
res = returnGear();
lblMarcha.Text = "Marcha: " + res;
}