且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c ++ / clr StructureToPtr堆栈缓冲区溢出

更新时间:2023-11-08 08:37:16

当你使用

因为您的C ++ typedef lines all use char ,not wchar_t ,you need

Because your C++ typedef lines all use char, not wchar_t, you need

[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Ansi)]

如果编组人员不正确地使用Unicode,它将为每个字符串写入两倍的数据,溢出缓冲区并破坏附近的内存。

If the marshaller incorrectly uses Unicode, it will write twice as much data for each string as it should, overflowing the buffer and corrupting nearby memory.