title: DllImport StackOverflowException
body: <p>I'm trying to use C++ DLL(borland c builder) from c#. Function writeParameter works fine, it writes correct data to a file, but then i have an exception "An unhandled exception of type 'System.StackOverflowException' occurred in PresentationFramework.dll"</p>
  
  <p>C++ code:</p>
  
  <pre><code>#include &lt;vcl.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;fstream.h&gt;
  #pragma hdrstop
  #pragma argsused
  BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
  {
    return 1;
  }
  //---------------------------------------------------------------------------
  #pragma pack (push,1)
  typedef struct     
  {
       int     a;
  }ABC;
  #pragma pack (pop)
  //---------------------------------------------------------------------------
  
  extern "C" void __declspec(dllexport) __cdecl writeParameter(ABC *abc)
  {
     ofstream outfile("result.txt");
     outfile&lt;&lt; "A="   &lt;&lt;endl;
     outfile &lt;&lt; abc-&gt;a &lt;&lt;endl;
     outfile.close();
  }
  </code></pre>
  
  <p>c#:</p>
  
  <pre><code>[StructLayoutAttribute(LayoutKind.Sequential)]
  public class ABC
  {
      public int a;
  }
  [DllImport("D:\\monitorVC.dll", EntryPoint = "_writeParameter", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
          public static extern void WriteParameter( 
              [In,MarshalAs(UnmanagedType.LPStruct)]
              ABC abc
              );
  
          private void Grid_Loaded(object sender, RoutedEventArgs e)
          {
                  var abc = new ABC() {a = 123};
                  WriteParameter(abc);
          }
  </code></pre>