Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
-
Hi All, I am calling a c++ dll from c#. it throwing error like "An unhandled exception of type 'System.AccessViolationException' occurred in exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
[DllImport(@"D:\Project\Working\Toolkit-2.0\output\Win32\Debug\ipetk.dll",
EntryPoint = "?GetModuleTypeString@ModuleIndex@Infrastructure@IPETK@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
CallingConvention = CallingConvention.Cdecl)]
static extern string GetModuleTypeString(ModuleType ths);string ModuleIndex = GetModuleTypeString(ModuleType.IPD);
MessageBox.Show(ModuleIndex.ToString());how can i resolve this issue..? any help will be appriciated. Thanks
G.Paulraj
-
Hi All, I am calling a c++ dll from c#. it throwing error like "An unhandled exception of type 'System.AccessViolationException' occurred in exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
[DllImport(@"D:\Project\Working\Toolkit-2.0\output\Win32\Debug\ipetk.dll",
EntryPoint = "?GetModuleTypeString@ModuleIndex@Infrastructure@IPETK@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
CallingConvention = CallingConvention.Cdecl)]
static extern string GetModuleTypeString(ModuleType ths);string ModuleIndex = GetModuleTypeString(ModuleType.IPD);
MessageBox.Show(ModuleIndex.ToString());how can i resolve this issue..? any help will be appriciated. Thanks
G.Paulraj
-
Hi All, I am calling a c++ dll from c#. it throwing error like "An unhandled exception of type 'System.AccessViolationException' occurred in exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
[DllImport(@"D:\Project\Working\Toolkit-2.0\output\Win32\Debug\ipetk.dll",
EntryPoint = "?GetModuleTypeString@ModuleIndex@Infrastructure@IPETK@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
CallingConvention = CallingConvention.Cdecl)]
static extern string GetModuleTypeString(ModuleType ths);string ModuleIndex = GetModuleTypeString(ModuleType.IPD);
MessageBox.Show(ModuleIndex.ToString());how can i resolve this issue..? any help will be appriciated. Thanks
G.Paulraj
Looks like the definition of your C function should be changed to something like:
extern "C" char* GetModuleTypeString(char*);
STL
string
s do not work well between managed and unmanaged code.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Hi All, I am calling a c++ dll from c#. it throwing error like "An unhandled exception of type 'System.AccessViolationException' occurred in exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
[DllImport(@"D:\Project\Working\Toolkit-2.0\output\Win32\Debug\ipetk.dll",
EntryPoint = "?GetModuleTypeString@ModuleIndex@Infrastructure@IPETK@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
CallingConvention = CallingConvention.Cdecl)]
static extern string GetModuleTypeString(ModuleType ths);string ModuleIndex = GetModuleTypeString(ModuleType.IPD);
MessageBox.Show(ModuleIndex.ToString());how can i resolve this issue..? any help will be appriciated. Thanks
G.Paulraj
The error message can also originate from a DEP (data execution protection) problem. If you get the error only when you run your compiled executable directly, but not when you debug from Visual Studio, set the DEP flag off:
editbin.exe /NXCOMPAT:NO "$(TargetPath)"