title: Sending an array in a UWP app from C# to a C++/Cx dll
body: <p>I'm working on a UWP project. I want to send an array of position data (currently I'm just sening a float array as a test) from c# to C++ (in order to render a generated mesh in DirectX on top of XAML stuff).</p>
  
  <p>I tried this: <a href="https://stackoverflow.com/questions/7309838/improper-marshaling-c-sharp-array-to-a-c-unmanaged-array">Improper marshaling: C# array to a C++ unmanaged array</a> (the accepted answer). But it doesn't work, I'm guessing I'm missing something, but I don't know what. When I try what he suggests, my compiler complains about the CInput struct declared in C++, because it's native, and so it can't be a parameter in a public function. (the function that is called from c#)</p>
  
  <p>(I would have commented on that question, but I don't have that privilege yet.)</p>
  
  <p>This is my code:</p>
  
  <p>in C#:</p>
  
  <pre><code>public struct CInput
  {
      public IntPtr array;
  }
  
  public VideoView()
  {
      InitializeComponent();
      Loaded += OnLoaded;
  
      float[] test = new float[4];
      CInput input = new CInput();
      input.array = Marshal.AllocHGlobal(Marshal.SizeOf&lt;float&gt;() * test.Length);
      Marshal.Copy(test, 0, input.array, test.Length);
      D3DPanel.CreateMesh(out input, test.Length);
      Marshal.FreeHGlobal(input.array);
  }
  </code></pre>
  
  <p>in C++ (in D3DPanel.h):</p>
  
  <pre><code>struct CInput
  {
      float* array;
  };
  
  [Windows::Foundation::Metadata::WebHostHidden]
  public ref class D3DPanel sealed : public Track3DComponent::DirectXPanelBase
  {
  public:
      D3DPanel();
  
      void CreateMesh(CInput points, int length);
  }
  </code></pre>
  
  <p>Can anyone tell me what I'm doing wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried the PassArray pattern, as described <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700131.aspx" rel="nofollow noreferrer">here</a>, but it gives this error: "Error C4400 'const int': const/volatile qualifiers on this type are not supported"</p>
  
  <pre><code>void CreateMesh(const Array&lt;float&gt;^ points, int length);
  </code></pre>
  
  <p>And replacing "const Array^" with "Array" gives "syntax error: identifier 'Array'".</p>