How to marshal an array of structs - (.Net/C# => C++)

前端 未结 2 1642
甜味超标
甜味超标 2021-01-07 02:17

Disclaimer: Near zero with marshalling concepts..

I have a struct B that contains a string + an array of structs C. I need to send this across the giant interop chas

2条回答
  •  生来不讨喜
    2021-01-07 03:01

    The answer depends on what the native definitions are that you are trying to marshal too. You haven't provided enough information for anyone to be able to really help.

    A common thing that trips people up when marshalling strings in native arrays is that native arrays often use a fixed-size buffer for the string that is allocated inline with the struct. Your definition is marshalling the strings as a pointer to another block of memory containing the string (which is the default).

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ##)] might be what you are looking for...

提交回复
热议问题