title: Function callback handler unable to pass the full float array from CLI/C++ to C#
body: <p>I have to pass a float array as a parameter of a function callback handler. The float array(image data) will be generated in C++ side, and C# code can receive the array. My current code only pass the first element <code>array[0]</code> to the C#. </p>
  
  <p>I declared the handler in c++ code like this </p>
  
  <pre><code>class ArrayHandler { 
      public:
  
      typedef void(*ImageHandler) (float *img, int size, char *msg);
  
      ArrayHandler();
      ~ArrayHandler();
  
      void Hello(ImageHandler);
  
  private:
      ImageHandler m_imgHandler;
  };
  </code></pre>
  
  <p>The implementation of member function <code>Hello(ImageHandler)</code> is</p>
  
  <pre><code>void ArrayHandler::Hello(ImageHandler h)
  {
      m_imgHandler = h;
      int size = 5;
      char *msg = "Hello";
      float arry[5] {1, 2, 3, 4, 5};
  
      m_imgHandler(arry, 5, msg);
  }
  </code></pre>
  
  <p><br>In CLI/C++ wrapper, I declare the <code>ImageHandler</code> as</p>
  
  <pre><code>delegate void ImageHandler(cli::array&lt;float&gt;^ img, int size, String ^msg);
  </code></pre>
  
  <p>The implementation of <code>Hello(ImageHandler ^ih)</code> in wrapper is</p>
  
  <pre><code>void WrappedHandler::Wrapped::Hello(ImageHandler ^ih)
  {
      wrapped_ImageHandler = ih;
      IntPtr ip = 
      Marshal::GetFunctionPointerForDelegate(wrapped_ImageHandler);
  
      ArrayHandler::ImageHandler nativeHandler = 
      reinterpret_cast&lt;ArrayHandler::ImageHandler&gt;(ip.ToPointer());
  
      m_ArrayHandler-&gt;Hello(nativeHandler);
  }
  </code></pre>
  
  <p><br></p>
  
  <p>I use the following to call the function in C#.</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Wrapped test = new Wrapped();
          test.Hello(ImageFromHandler);
      }
  
      private static void ImageFromHandler(float[] img, int size, string msg)
      {
          Console.WriteLine(msg);
          int l = img.Length;
          if(l != size){
              Console.WriteLine("Size not match");
          }
      }
  }
  </code></pre>
  
  <p>I run the program, and I found the size of float array passed to C# is 1, and only the first element is passed. Then I tried something not intuitive such as passing a array of float array, but the program break for some reasons. I think the problem may occur when I marshal the handler to native pointer. I'm also confused that the string type parameter which is declared as <code>char *</code> in c++ is able to be passed, but the <code>float *</code> failed.</p>
  
  <p>Thanks.</p>