Data values in the parameters are beeing copied to the other parameters c++, c# -


in c++ method exporting is:

__declspec(dllexport) int __thiscall a::check(char *x,char *y,char *z) {   temp=new b(x,y,z); } 

in c# importing method this:

[dllimport("idll.dll", callingconvention=callingconvention.thiscall, exactspelling = true, entrypoint = "check")]     public static extern int check(string x, string y, string z); 

i calling method in c# , passing 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 when debug in native code see parameters x,y,z having values sdf,dfggh,vbnfg , being altered when reach c++ dll before entering native c++ dll method.

x=dfggh,y=vbnfg,z=null value 

and giving me error saying null pointer value passed function. can 1 me out fixing weird problem.

looks native method instance(vs static) method. guess first parameter gets mapped 'this' somehow.

here example:

#include <fstream> using namespace std;  class { public: __declspec(dllexport) static int __stdcall check(char *x,char *y,char *z) {     ofstream f;     f.open("c:\\temp\\test.txt");     f<<x<<endl;     f<<y<<endl;     f<<z<<endl;     return 0;      }  __declspec(dllexport) int __thiscall checkinst(char *x,char *y,char *z) {     ofstream f;     f.open("c:\\temp\\testinst.txt");     f<<x<<endl;     f<<y<<endl;     f<<z<<endl;     return 0;      } }; 

see static keyword on first one?

imports(i used mangled names because i'm lazy):

[dllimport("testdll.dll", callingconvention = callingconvention.stdcall, exactspelling = true, entrypoint = "?check@a@@sghpad00@z")]     public static extern int check(string x, string y, string z);      [dllimport("testdll.dll", callingconvention = callingconvention.thiscall, exactspelling = true, entrypoint = "?checkinst@a@@qaehpad00@z")]     public static extern int checkinst(intptr theobject, string x, string y, string z); 

that makes work that:

check("x", "yy", "zzz"); 

the instance method requires intptr

intptr obj = intptr.zero; checkinst(obj, "1", "12", "123"); 

and contents of test.txt are:

x yy zzz 

and testinst.txt

1 12 123 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -