结构内部结构的元帅安全阵列

时间:2010-02-10 01:16:03

标签: c++ c

我在C ++中有以下代码,我需要能够从C#调用:

struct Inner
{
 double data1;
 double data2;
};

struct Outer
{
 double data3;
 SAFEARRAY innerData;
};

int WINAPI ProcessData (Outer& outer )
{
  ...
}

我尝试了以下但是它没有用我做错了什么?

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Inner 
{
 public double data1;
 public double data2;
}

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Outer 
{
 public double data3;
[MarshalAsAttribute(UnmanagedType.Safearray,ArraySubType = UnmanagedType.Struct)]
 public Inner[] innerData;
}

2 个答案:

答案 0 :(得分:1)

你试过这个吗?

  [StructLayoutAttribute (LayoutKind.Sequential)]
  public struct Outer
  {
     public double data3;
     [MarshalAsAttribute (UnmanagedType.SafeArray, SafeArrayUserDefinedSubType=typeof(Inner))]
     public Inner [] innerData;
  }

答案 1 :(得分:0)

看起来好像属性声明不正确,因为它拒绝编译......

[StructLayoutAttribute(LayoutKind.Sequential)]
        public struct Outer
        {
            public double data3;
            [MarshalAsAttribute(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_SAFEARRAY)]
            public Inner[] innerData;
        }

希望这有帮助, 最好的祝福, 汤姆。