title: How can I marshall a vector<int> from a C++ dll to a C# application?
body: <p>I have a C++ function that produces a list of rectangles that are interesting.  I want to be able to get that list out of the C++ library and back into the C# application that is calling it.</p>
  
  <p>So far, I'm encoding the rectangles like so:</p>
  
  <pre><code>struct ImagePatch{ 
     int xmin, xmax, ymin, ymax;
  }
  </code></pre>
  
  <p>and then encoding some vectors:</p>
  
  <pre><code>void MyFunc(..., std::vector&lt;int&gt;&amp; rectanglePoints){
     std::vector&lt;ImagePatch&gt; patches; //this is filled with rectangles
     for(i = 0; i &lt; patches.size(); i++){
         rectanglePoints.push_back(patches[i].xmin);
         rectanglePoints.push_back(patches[i].xmax);
         rectanglePoints.push_back(patches[i].ymin);
         rectanglePoints.push_back(patches[i].ymax);
     }
  }
  </code></pre>
  
  <p>The header for interacting with C# looks like (and works for a bunch of other functions):</p>
  
  <pre><code>extern "C" {
      __declspec(dllexport) void __cdecl MyFunc(..., std::vector&lt;int&gt;&amp; rectanglePoints);
  }
  </code></pre>
  
  <p>Are there some keywords or other things I can do to get that set of rectangles out?  I found <a href="http://msdn.microsoft.com/en-us/library/ms235281(VS.80).aspx" rel="noreferrer">this article</a> for marshalling objects in C#, but it seems way too complicated and way too underexplained.  Is a vector of integers the right way to do this, or is there some other trick or approach?</p>