How to organize a list in C #

I need to send a list from C # to C ++. C # List<string>MyList , and C ++ code accepts it as list<wstring>cppList . How to use marshals for this.

thanks

+4
source share
3 answers

It is always wise not to use a complex type of marshaling between native code and managed code. In the case of List , these types are completely different from each other, since they have a different memory structure for each element.

Thus, the best way is to write a utility function in the native dll that takes an array of strings (char *) and manually build your own List and ultimately call the desired method. It is easy to create a wrapper for this utility function.

+2
source

C # cannot P / call complex C ++ types. You will need to use C ++ / CLI, they may have a method for sorting it. In addition, you will need to translate each line individually.

+3
source

strings in C # are wstrings (2 byte Unicode strings), so if you are telling the truth, then no special conversions are required.

0
source

All Articles