以下はc++ dllクラスです
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 メソッドの定義は以下のとおりです
__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のインポートはこんな感じ
[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 ビルドは正常に動作しますが、c# が c++ dll メソッドを呼び出すときも見栄えがよく、関数に入ると、メソッドの最初の行で、クラス A でクラスのポインターとして宣言されている一時ポインター用のメモリを作成しようとします。プライベートなB. それが与えているエラーは
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.