Pass C# string to C++ and pass C++ result (string, char*.. whatever) to C# -


I tried different things but I'm getting mad with the interop.

(Here the word string is not a variabile type, but is called "a collection of four"): I have an unmanaged C ++ function, which is defined in DLL, I # I'm trying to reach, this function has string parameter and string return value such as:

  string myFunction (string inputstring) {}  

Should be string in C ++ side? And C # one? And what parameters do DllImport need for it?

what I have found to be the best thing to be and should be more clear what's going on here : In this situation it is not recommended to have a string as the return type.

A common method is to pass buffer and buffer size to the C + + side. If the gatestring is kept in it, then it is not large enough, it has been modified to modify the buffers variable, what would be a proper size. The calling program (C #) will then increase the size of the buffer to the appropriate size.

If it is your exported DLL function (C ++):

  extern "C" __declspec zero GetString (four * buffer, intestine * buffer size);  

The matching C # will be the following:

  zero received string (stringbillter buffer, ref eff buffer size);  

To use it in C #, you would do something like:

  int bufferize = 512; StringBillter buffer = new stringbiller (buffer size); GetString (buffer, ref buffer size);  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -