C# Marshalling a C++ struct with wchar_t* member occasionally leaves the heap corrupted
问题 I have declared a struct as follows: // C++ struct TestStruct { wchar_t* TestString; }; and the corresponding managed representation // C# [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TestStruct { [MarshalAs(UnmanagedType.LPWStr)] public string TestString; } As well as this function: // C++ __declspec(dllexport) void __stdcall FillMultipleStructs(TestStruct* testStructures, const short arrayLength) { for(int i = 0; i < arrayLength; i++) { const wchar_t