title: Marshaling byval C-structure as return value in C#
body: <p>I have unmanaged code:  </p>
  
  <pre><code>...
  typedef struct foo  
  {  
   int  a;  
   bool b
   int  c;  
  } FOO,*LPFOO;
  ....
  __declspec(dllexport) FOO __stdcall GetFoo()  
  {  
     FOO f;  
     &lt;some work&gt;  
     return f;   
  }  
  ....
  </code></pre>
  
  <p>I've declare C# prototype for GetFoo function:  </p>
  
  <pre><code>    [StructLayout(LayoutKind.Sequential, Pack = 1)]
      private struct Foo
      {
        public int  a;  
        public bool b
        public int  c; 
      };
  
      [DllImport("foo.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      [return:MarshalAs( UnmanagedType.Struct)]        
      private static extern Foo GetFoo();
  </code></pre>
  
  <p>But when I calling GetFoo from C# code I alway have MarshalDirectiveException- Method's type signature is not PInvoke compatible. How I should declare C# prototype?</p>