Pass a reference of string from C# to C++ function -



Pass a reference of string from C# to C++ function -

i have c++ library , wrote functions in it. function must homecoming integer , string. (2 outputs) , i'm going phone call function c# program. here code in c++:

extern "c"{ __declspec(dllexport) uint read(out char* temp ) { ..... } }

and it's c# code in importdll class:

[dllimport("library.dll", callingconvention = callingconvention.cdecl)] public static extern uint read(char[] temp);

and in form have this:

char[] str = new char[256]; importdll.read(str);

it returns int correctly string result (str array) totally 0 (\0)! wrong code? give thanks you.

one add-on reply matthew watson: need marshal stringbuilder parameter lpstr (char *), like

[dllimport("library.dll", callingconvention = callingconvention.cdecl)] public static extern uint read([marshalas(unmanagedtype.lpstr)] stringbuilder temp);

c# c++ mfc

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -