title: AccessViolationException when accessing unmanaged C++ DLL with C#
body: <p>I am trying to access a Double Dummy Solver dll (<a href="http://privat.bahnhof.se/wb758135/bridge/dll.html" rel="nofollow">http://privat.bahnhof.se/wb758135/bridge/dll.html</a> ) of unmanaged C++ code from a C# project, but I get the following error message:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.AccessViolationException'
    occurred in Dds.Net.dll</p>
    
    <p>Additional information: Attempted to read or write protected memory.
    This is often an indication that other memory is corrupt.</p>
  </blockquote>
  
  <p>The error seems to be around calling the method
  Par which takes the three arguments</p>
  
  <blockquote>
    <p>struct ddTableResults *tablep,  struct parResults *presp,  int vulnerable</p>
  </blockquote>
  
  <p>Specifically, related to passing in the 2nd parameter which is described to be: </p>
  
  <blockquote>
    <p>struct parResults 
    char parScore[2][16]; 
    char parContractsString [2][128]; </p>
  </blockquote>
  
  <p>Here is my code:
  My c# struct:</p>
  
  <pre><code>using System.Runtime.InteropServices;
  
  namespace Dds.Net.Integration
  {
      [StructLayout(LayoutKind.Sequential)]
      internal struct ParResults
      {
          [MarshalAs(UnmanagedType.ByValArray, SizeConst =32)]
          public char[,] parScore;
          [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
          public char[,] parContractString;
  
  
      }
  }
  </code></pre>
  
  <p>dllimport to call the function : </p>
  
  <pre><code>[DllImport("dds.dll")]
          public static extern int Par(DdTableResults tablep, int vulnerable, ParResults parResults);
  </code></pre>
  
  <p>Any idea of what I can do to get this working?</p>
  
  <p>Many thanks!</p>