Marshal safearray of struct inside struct

前端 未结 2 1867
遥遥无期
遥遥无期 2021-01-19 19:21

I have the following code in C++ which I need to be able to call from C#:

struct Inner
{
 double data1;
 double data2;
};

struct Outer
{
 double data3;
 SAF         


        
相关标签:
2条回答
  • 2021-01-19 19:42

    Did you try this?

      [StructLayoutAttribute (LayoutKind.Sequential)]
      public struct Outer
      {
         public double data3;
         [MarshalAsAttribute (UnmanagedType.SafeArray, SafeArrayUserDefinedSubType=typeof(Inner))]
         public Inner [] innerData;
      }
    
    0 讨论(0)
  • 2021-01-19 19:51

    It looks as if the attribute declaration is not correct as its refusing to compile...

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

    Hope this helps, Best regards, Tom.

    0 讨论(0)
提交回复
热议问题