Your C# application tries to deallocate the string returned by the C++ DLL. But this fails with undefined behaviour because the string is not allocated but a static object. I don't know how and if this is related to
vshost32.exe.
You can change the C++ code to return an allocated string using
CoTaskMemAlloc
, or the C# code to treat the return value as
IntPtr
and call
Marshal.PtrToString
. Note that the latter should only be used with constant objects (when your C++ function returns a
const char*
).
You might have a look at
Returning Strings from a C++ API to C# | limbioliong[
^] which explaias the different methods in detail.