In c++ the method that I am exporting is:
__declspec(dllexport) int __thiscall A::check(char *x,char *y,char *z)
{
temp=new B(x,y,z);
}
In c# I am importing this method like this:
[DllImport("IDLL.dll", CallingConvention=CallingConvention.ThisCall, ExactSpelling = true, EntryPoint = "check")]
public static extern int check(string x, string y, string z);
I am calling this method in c# like this and passing the values:
public int temp()
{
string x="sdf";
string y="dfggh";
string z="vbnfg";
int t;
t=Class1.check(x,y,z);
return t;
}
The problem is that when I debug in to the native code I see that the parameters x,y,z having values sdf,dfggh,vbnfg and being altered when they reach c++ dll like this even before it is entering the native c++ dll method.
x=dfggh,y=vbnfg,z=null value
and is giving me the error saying that null pointer value is passed to the function. Can any one help me out fixing this weird problem.
Looks like your native method is an instance(vs static) method. I guess your first parameter gets mapped to ‘this’ somehow.
Here is an example:
see the static keyword on the first one?
Imports(i used the mangled names because I’m lazy):
That makes it work just like that:
the instance method requires an IntPtr
and the contents of my test.txt are:
and testInst.txt