【问题标题】:How to marshall pointer to array in C#如何在 C# 中编组指向数组的指针
【发布时间】:2012-06-13 08:30:22
【问题描述】:

我有带有 int** 参数的 c++ 方法,它是指向 int 数组的指针。

如何将其编组为 C#?

【问题讨论】:

  • 不发布这个作为答案,因为我无法确认;但尝试将参数编组为ref int[]
  • 试过这个。不工作
  • @Redwan - “不起作用”是什么意思?
  • @Bond - System.AccessViolationException 被抛出
  • 我会尝试使用 ref IntPtr,但不确定。

标签: c# interop marshalling .net


【解决方案1】:

你可以尝试从这个方法签名中获得灵感:

void MyMethod([MarshalAs(UnmanagedType.LPArray, SizeConst=10)] int[] ar);

(数组长度为10)

【讨论】:

  • 不要忘记添加“使用 System.Runtime.InteropServices;”
  • 不,那行不通。我的数组没有 const 大小。它因呼叫而异。而且我不能将非常量数据放入属性中。
  • 怎么样:void MyMethod([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VT_I4)] int[] ar);
  • 请参阅 msdn.microsoft.com/en-us/library/… 了解“VT_I4”安全数组子类型的替代方案。
猜你喜欢
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-25
  • 2011-01-29
  • 1970-01-01
  • 2013-07-11
相关资源
最近更新 更多