title: define a structure in C++ IDL, then MarshalAs() appropriately in C#
body: <p>I have a C++ COM server that fills a C# caller's structure with data.</p>
  
  <p>The structure is defined in the C++ IDL, something like the following:</p>
  
  <pre><code>interface Icontrol : IDispatch{
      [ 
      uuid(...), 
      version(1.0) ]
      typedef struct testStructure
      { 
          int x;
          int y;
          int z;
          ...
      } testStructure; 
  
      ...
      [id(9)] HRESULT getStruct([ref,in,out] testStructure * theData);
      ...
  </code></pre>
  
  <p>Then, in the C# code:</p>
  
  <pre><code>EO_Lib.testStructure test = new EO_Lib.testStructure();
  EO_Lib.getStruct(ref test);
  </code></pre>
  
  <p>I can make this work no problem with a regular .DLL by simply using MarshallAs in a C# structure for the fields non-native to C#. But I can't get that to work on a COM .DLL. I suspect it's because of my lack of knowledge about IDL.</p>
  
  <p>What I need to be able to do is call getStruct() with a new C# type that I've created with appropriate MarshallAs() information. How do I do this?</p>
  
  <p>I am using Visual Studio 2010 MFC/ATL C++ and C# .NET 4 Framework, if it helps.</p>