이름이 공유 메모리를 읽는 Win32 C++ DLL이 있습니다. 앱에서 C# 응용 프로그램에 수신하는 값을 내보내려고합니다. 사실C# Named Shared Memory 판독기 변수를 C# App으로 내 보냅니다.
,이 코드를 가지고,하지만 난 C# 응용 프로그램에서 값을 액세스 할 때,이 나타납니다
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++ 코드 :
extern "C" {
__declspec(dllexport) int __cdecl returnGear();
}
extern int __cdecl returnGear()
{
return shared_memory->gear;
}
C# 코드 :
[DllImport("ETS2_Utilities_Plugin.dll")]
public static extern int returnGear();
void GetData()
{
res = returnGear();
lblMarcha.Text = "Marcha: " + res;
}
을
이 질문은 도움이 될 수도 있습니다 - http://stackoverflow.com/questions/18208084/proper-calling-convention-of-unmanaged-dll-function ('CallingConvention = CallingConvention.Cdecl'을'DllImport' 속성). –
C++ 코드를 디버깅해야합니다. 분명히 불만입니다. 프로젝트 + 속성, 디버그 탭에서 "네이티브 코드 디버깅 사용"옵션을 선택합니다. 함수의 진입 점에 중단 점을 설정하여 디버거가 작동하는지 확인하고 디버거가 어디에서 불면되는지 확인합니다. –