title: Marshall array in C++ struct in C# struct
body: <p>I am having a struct defined in C++ which contains int and std::string arrays which is a native C++ code (dll). I have used following method to get it in C#:</p>
  
  <pre><code>public class PInvokeData
  {
      [StructLayout(LayoutKind.Sequential)]        
      public struct pinvoke_call
      {
          //[MarshalAs(UnmanagedType.LPArray,SizeConst=5,SizeParamIndex=0,MarshalType="int")]
          [MarshalAs(UnmanagedType.ByValArray, SizeConst=5)]//,SizeParamIndex =0,SafeArraySubType = VarEnum.VT_I4)]
          public int[] mynum;
      }
      [DllImport("DLL_pinvoke_base.dll")]
      public extern static pinvoke_call TestPInvoke();
  }
  </code></pre>
  
  <p>the code compiles well.
  when i call this static method and get return value of struct from C++ and assign to another struct object in C# like</p>
  
  <pre><code>input = PInvokeData.TestPInvoke();
  </code></pre>
  
  <p>i get exception of MarshalDirectiveException was unhandeled. Method's type signature is not PInvoke compatible. I tryed to solve the problem via other forum threads, but i did not get the result.</p>
  
  <p>the struct in C++ code is same as there shown for C# struct like</p>
  
  <pre><code>struct pinvoke_call
  {
      int mynum[5]
  };
  </code></pre>
  
  <p>After calling a function C++ it returns this structure variable from there to C# which i want to marshal</p>
  
  <p>Thanks for reply,
  Ashutosh</p>