There are many ways to solve this problem, but they are all more complex than what you currently have.
Probably the easiest way to pass a string allocated in C ++ to C # is through BSTR . This allows you to highlight a line in C ++ and allow C # code to free it. This is the biggest problem you encounter and sorting as BSTR resolves it trivially.
Since you need a list of strings, you can change its sorting as a BSTR array. This is one way, this is probably the route I would take, but there are many other approaches.
source share