title: c++  dll  using dllimport c#
body: <p>I have a dll i wish to use in .net. I am trying to use dllimport but I am getting errors. I have put the dll in windows system32 folder and also where the exe is stored.the function definition I have been given that works in vb is.</p>
  
  <pre><code>        declare function LocalToWGS84 lib "TTDatum3.Dll"(Lat As Double, Lon As Double, ByVal Datum As Long) As Long
  </code></pre>
  
  <p>method sig</p>
  
  <pre><code>    #ifdef __cplusplus
  extern "C" {
  #endif
  
  int __stdcall WGS84ToLocal(double * lat, double * longt, int d);
  </code></pre>
  
  <p>c#</p>
  
  <pre><code>  class Program
  {
  
      [DllImport("TTDatum3.Dll", EntryPoint="LocalToWGS84")]
      public static extern long LocalToWGS84([In,Out]double lat, [In,Out]double lon,[In,Out]long datum);
  
      public static void Main(string[] args)
      {
          Console.WriteLine(LocalToWGS84(50.82011492,-0.117981131, 150));
  
      }
  }
  </code></pre>
  
  <p>the error is:</p>
  
  <blockquote>
    <p>Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an idication that other memory is corrupt</p>
  </blockquote>