title: pointers between c# and c++ - p/invoke
body: <p>hi im trying to call some c++ code from c#. So i followed several tutorials, amde my own dll, and now i call it from my c# wrapper. the thing is, i have a function that receives a pointer and i can't seem to make it work, visual studio just shows me red errors that i don't understand very well. can someone tell me what im doing wrong? 
  and i have another question, if the functions in c++ call other functions, all the data will remain intact right? because this array that i pass will be manipulated inside the dll and, afterwards, im gonna call other function from the dll to get the results - my fear is that the data is lost between function calls!</p>
  
  <p>thanks!</p>
  
  <p>dll .h
         #include  </p>
  
  <pre><code>   #include &lt;stdio.h&gt; 
  
     #include &lt;stdlib.h&gt; 
  
     #include &lt;math.h&gt; 
  
     #include &lt;string&gt; 
  
     #include &lt;vector&gt; 
  
     #include &lt;fstream&gt; 
  
     #include &lt;sstream&gt; 
  
     #include &lt;cstring&gt; 
  
     #include &lt;fstream&gt;
  
     #include &lt;iomanip&gt; 
  
     #include &lt;cstdlib&gt; 
  
     #include &lt;string&gt; 
  
     #include &lt;cstring&gt; 
  
     #include "opencv\ml.h"
  
     struct points{
      double x;
      double y;
      double z;
     };
  
  #define db at&lt;double&gt;
  
  
     extern "C" __declspec(dllexport) points * mapear_kinect_porto(points pontos[]);
  
  
     CvERTrees *  Rtree ;
  
  
     extern "C" __declspec(dllexport)     void calibrate_to_file(points pontos[]);
  
     extern "C" __declspec(dllexport)     int calibration_neutral();
  
     extern "C" __declspec(dllexport)       int EmotionsRecognition();
  </code></pre>
  
  <p>c# wrapper</p>
  
  <pre><code>             [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
  public struct points
  {
  
      /// double
      public double x;
  
      /// double
      public double y;
  
      /// double
      public double z;
  }
  
  
  class CPlusPlusWrapper
  {
  
  /// Return Type: void
      ///pontos: points*
      [System.Runtime.InteropServices.DllImportAttribute("DLLTUT.dll", EntryPoint =  "calibrate_to_file")]
      public static extern void calibrate_to_file(ref points pontos);
      public unsafe void calibrate_file()
      {
  
          points[] shit = new points[8];
          points*[] pBLA; //error here!!!!
          pBLA = &amp;shit;
     //            calibrate_to_file(pbla);
      }
  </code></pre>
  
  <p>}</p>
  
  <p>btw i used p/invoke assistant and i got this</p>
  
  <pre><code>public partial class NativeConstants {
  
  /// db -&gt; at&lt;double&gt;
  /// Error generating expression: Expression is not parsable.  Treating value as a raw string
  public const string db = "at&lt;double&gt;";
  }
  
  [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
  public struct points {
  
  /// double
  public double x;
  
  /// double
  public double y;
  
  /// double
  public double z;
  }
  
  public partial class NativeMethods {
  
  /// Return Type: points*
  ///pontos: points*
  [System.Runtime.InteropServices.DllImportAttribute("&lt;Unknown&gt;", EntryPoint="mapear_kinect_porto")]
  public static extern  System.IntPtr mapear_kinect_porto(ref points pontos) ;
  
  
  /// Return Type: void
  ///pontos: points*
  [System.Runtime.InteropServices.DllImportAttribute("&lt;Unknown&gt;", EntryPoint="calibrate_to_file")]
  public static extern  void calibrate_to_file(ref points pontos) ;
  
  
  /// Return Type: int
  [System.Runtime.InteropServices.DllImportAttribute("&lt;Unknown&gt;", EntryPoint="calibration_neutral")]
  public static extern  int calibration_neutral() ;
  
  
  /// Return Type: int
  [System.Runtime.InteropServices.DllImportAttribute("&lt;Unknown&gt;", EntryPoint="EmotionsRecognition")]
  public static extern  int EmotionsRecognition() ;
  
  }
  </code></pre>