Marshal array of doubles from c to c#

2019-10-09 16:57发布

Can someone please tell me exactly what I should write to marshal an array of double pointers between C and C#?

struct foo { double *abc[20]; };

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class foo {  // ??? abc;   }

I have had many oblique resonses to 2 previous queries, and I have read another dozen or so questions here on this same topic, but I can't find in any of them a simple answer to this question.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-10-09 17:45

Ok, here is the simple, straightforward answer to this question:

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public IntPtr[] abc;

The trick is that, counterintuitively, you must use an IntPtr despite the fact this is an array of double pointers, not int pointers.

查看更多
登录 后发表回答