title: How to pass a list of objects from C++ to C#?
body: <p>My first question here :)</p>
  
  <p>I am working with an application written in C++ (a map editor for a game) that has the front end UI written in C#. Since i'm new to C# i'm trying to do as much as possible on the C++ side.</p>
  
  <p>From C# i want to call a C++ function that will return a list of structs with simple variable types (int and string) so that i can populate a listBox i have in the UI with them. Is this possible? How should i write the dll import function in C#?</p>
  
  <p>I have tried searching here for the answer, but i only found post on how to pass lists from C# to C++.</p>
  
  <p>The C++ code:</p>
  
  <pre><code>struct PropData
  {
  PropData( const std::string aName, const int aId )
  {
      myName = aName;
      myID = aId;
  }
  
  std::string myName;
  int myID;
  };
  
  extern "C" _declspec(dllexport) std::vector&lt;PropData&gt; _stdcall GetPropData()
  {
  std::vector&lt;PropData&gt; myProps;
  
  myProps.push_back( PropData("Bush", 0) );
  myProps.push_back( PropData("Tree", 1) );
  myProps.push_back( PropData("Rock", 2) );
  myProps.push_back( PropData("Shroom", 3) );
  
  return myProps;
  }
  </code></pre>
  
  <p>The C# import function:</p>
  
  <pre><code>    [DllImport("MapEditor.dll")]
      static extern ??? GetPropData();
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>After the post from Ed S. I changed the c++ code to 
      struct PropData
      {
          PropData( const std::string aName, const int aId )
          {
              myName = aName;
              myID = aId;
          }</p>
  
  <pre><code>    std::string myName;
      int myID;
  };
  
  extern "C" _declspec(dllexport) PropData* _stdcall GetPropData()
  {
      std::vector&lt;PropData&gt; myProps;
  
      myProps.push_back( PropData("Bush", 0) );
      myProps.push_back( PropData("Tree", 1) );
      myProps.push_back( PropData("Rock", 2) );
      myProps.push_back( PropData("Shroom", 3) );
  
      return &amp;myProps[0];
  }
  </code></pre>
  
  <p>and the C# to 
          [DllImport("MapEditor.dll")]
          static extern PropData GetPropData();</p>
  
  <pre><code>    struct PropData
      {
          string myName;
          int myID;
      }
  
      private void GetPropDataFromEditor()
      {
          List&lt;PropData&gt; myProps = GetPropData();
      }
  </code></pre>
  
  <p>but of course this doesn't compile as GetPropData() doesn't return anything that translates to a list.</p>
  
  <p>Thanks a lot Ed S. for getting me this far!</p>