below is the c++ dll class
class A
{
public:
int __thiscall check(char *x,char *y,char *z);
private:
B *temp;
};
class B
{
friend class A;
Public:
B();
B(string x,string y,string z);
~B();
private:
string x;
string y;
string z;
};
c++ dll method definition is below
__declspec(dllexport) int __thiscall A::check(char *x,char *y,char *z)
{
temp=new B(x,y,z); //getting error at this point when i am assigning memory to temp
return 1;
}
c# dll import is like this
[DllImport("MyDll.dll", CallingConvention = CallingConvention.ThisCall, ExactSpelling = true, EntryPoint = "check")]
public static extern int check(IntPtr val,string x,string y,string z);
c++ dll build works fine but when c# calls the c++ dll method also it looks good and when it enters the function and in the first line of the method it try's to create memory for temp pointer which has been declared in class A as pointer of class B which is private. the error that it is giving is
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.