See the question and my original answer on StackOverflow

There are multiple problems. First of all your C++ function returns a pointer (emxArray_real_T *) but your import declaration returns a struct. That cannot work. Also, you declare data as double[,] in the import declaration, but as double[] in the structure. Suggestions:

  • Replace the struct by a class
  • Determine if data should be a double[] or a double[,]
  • Also check the final size of real_T. I believe it's a platform dependent variable that could be float (32 bit) or double (64 bit).