title: I'm writing a wrapper library in c# for c++ using the dll's header file, but can't figure out how to convert types.
body: <p>I have a struct in the c++ header file that looks like:</p>
  
  <pre><code>typedef struct sFrameOfData
  {
      int            iFrame;                  
      float          fDelay;                 
      int            nBodies;                 
      sBodyData      BodyData[MAX_N_BODIES]; 
  
      int            nUnidentifiedMarkers;    
      tMarkerData*   UnidentifiedMarkers;    
  
      sAnalogData    AnalogData;              
  
      sRecordingStatus RecordingStatus;      
  
  }
  </code></pre>
  
  <p>where <code>sAnalogData</code>,<code>tMarkerData</code>, and <code>sRecordingStatus</code> are custom c++ structs. 
  The c# method being called is:</p>
  
  <pre><code>[DllImport("Cortex_SDK.dll")]
      public static extern unsafe sFrameOfData* Cortex_GetCurrentFrame();
  </code></pre>
  
  <p>and I rewrote the structs as:</p>
  
  <pre><code> [StructLayout(LayoutKind.Sequential)]
      public unsafe struct sFrameOfData
      {
          private readonly int iFrame; //!&lt; Cortex's frame number
          private readonly float fDelay; //!&lt; Total time (seconds) from Camera to the Host sending the data
  
          private readonly int nBodies; //!&lt; The bodies should match the descriptions
  
          [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] private readonly sBodyData BodyData;
          //!&lt; The data for each body
  
          private readonly int nUnidentifiedMarkers; //!&lt; Number of unrecognized markers
          private readonly tMarkerData* UnidentifiedMarkers; //!&lt; The unrecognized markers
  
          private readonly sAnalogData AnalogData; //!&lt; The analog data packaged
  
          private readonly sRecordingStatus RecordingStatus; //!&lt; Info about name and frames being recorded
      }
  </code></pre>
  
  <p>but I get <code>cannot marshal 'return value'. Pointers cannot reference marshaled structures.</code></p>