msg is a stack variable, you can't return it iirc. Either create a var on the heap, or pass msg in as a parameter.
Mike On Tue, Nov 26, 2019, 08:03 Greg Keogh <gfke...@gmail.com> wrote: > Folks, I have to make a quick demo of how a VS C++ coder can return a > Unicode string from a function back to a C# caller. Easy I thought... I > haven't written serious C++ since 2004 and things have changed for the > worse. The introduction of 'W' wide character support has blown everything > to the merdehouse. I don't even know which "string" to use, but I guess > that std:string (or std:wstring actually) is the preferred modern choice. > Then there are all the type aliases (wchar_t, LPCWSTR, etc). Then I find > many library functions (like localtime) are deprecated and cause compile > errors. The whole C++ language and ecosystem is now bigger than a > cyclotron. Anyway, I've pasted the code snippets here: > > [image: image.png] > > [image: image.png] > > Unfortunately all I get back is a garbage string full of \uDDDD > characters. I've tried dozens of combinations of changes everywhere, even > putting everything back to plain ASCII, but nothing will give me a good > string back from the function. > > Does anyone know for sure how to get a Unicode string back from C++? Web > searches produce hundreds of contradictory suggestions, all of which don't > compile, don't work or crash. > > Thanks > *Greg Keogh* >