Attempted to read or write protected memory error while c++ dll is being accessed by c# -


below c++ dll class

class {   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 below

__declspec(dllexport) int __thiscall a::check(char *x,char *y,char *z) {   temp=new b(x,y,z); //getting error @ point when assigning memory temp   return 1; } 

c# dll import 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 when c# calls c++ dll method looks , when enters function , in first line of method try's create memory temp pointer has been declared in class pointer of class b private. error giving

attempted read or write protected memory. indication other memory corrupt. 

the __declspec(dllexport) should on class (e.g. class __declspec(dllexport) myclass), not on member methods.

the entry point should mangled c++ name (e.g. 2@myclass@mymethod?zii), not "check".
can use depends.exe find name.


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 -