Memory access exception instantiating c++ native code from /clr c++ code
-
Here is my setup. - c# wrapper calls managed c++ API code - managed c++ calls unmanaged API code (c++ compiled with the /clr flag, located in the same project) using static funtions - API tries to instantiate object defined in another dll (native c++)
void Screen::EvaluateScreen(LPCTSTR lpStrScreen, LPCTSTR lpStrSetName, LPCTSTR lpStrPeriods)
{
NativeDocument *screenDoc = NULL;
screenDoc = new NativeDocument;calling the constructor causes a "Attempted to read write protected memory. ....memory corupt?..." error in the contstructor code. I'm new to c++ coding as well as this interop stuff. Any ideas? Is there an issue instantiating native code from inside the /clr compiled c++? The code i'm using (EvaluateScreen) is lifted from another native DLL so the code in there should be good (i guess).
-
Here is my setup. - c# wrapper calls managed c++ API code - managed c++ calls unmanaged API code (c++ compiled with the /clr flag, located in the same project) using static funtions - API tries to instantiate object defined in another dll (native c++)
void Screen::EvaluateScreen(LPCTSTR lpStrScreen, LPCTSTR lpStrSetName, LPCTSTR lpStrPeriods)
{
NativeDocument *screenDoc = NULL;
screenDoc = new NativeDocument;calling the constructor causes a "Attempted to read write protected memory. ....memory corupt?..." error in the contstructor code. I'm new to c++ coding as well as this interop stuff. Any ideas? Is there an issue instantiating native code from inside the /clr compiled c++? The code i'm using (EvaluateScreen) is lifted from another native DLL so the code in there should be good (i guess).
redivider wrote:
Is there an issue instantiating native code from inside the /clr compiled c++
No.
/clr
compiler switch indicates that a mixed mode assembly has to be generated. It can work with both managed and unmanaged types. Where isNativeDocument
located? Is that in the DLL? Is your application multi-threaded?Best wishes, Navaneeth
-
redivider wrote:
Is there an issue instantiating native code from inside the /clr compiled c++
No.
/clr
compiler switch indicates that a mixed mode assembly has to be generated. It can work with both managed and unmanaged types. Where isNativeDocument
located? Is that in the DLL? Is your application multi-threaded?Best wishes, Navaneeth
-
Not multi-threaded. NativeDocument is in another dll C# dll -> /clr dll -> c++ dll (w/ NativeDocument class)
I couldn't reproduce this error. I have created a native DLL which has a sample
NativeDocument
class. Exported the functions and used this class from C++/CLI. Created a C# application and referred C++/CLI DLL there and everything worked as expected. If you can provide more information to reproduce, I will try.Best wishes, Navaneeth