title: Call native JNI DLL from C#
body: <p>I have a native DLL <code>abc.dll</code> (without source code) that was originally used in a JNI call in Java like this:</p>
  
  <pre><code>public class ABC_Proxy
  {
      private native void callABC(String parameter);
  
      public ABC_Proxy()
      {
          System.loadLibrary("abc");
      }
  
      public void Start(String paramater)
      {
          callABC(paramater);
      }
  }
  </code></pre>
  
  <p>Now I am trying to execute the same function in C#. Using <em>dumpbin</em> I found the correct full entry point, and this is what I came up with so far:</p>
  
  <pre><code>class Abc
  {
      [DllImport("abc.dll", EntryPoint="_Java_my_namespace_abc_1Proxy_callABC@12")]
      private static extern void CallAbc(string parameter);
  
      public void Start(string parameter)
      {
          CallAbc("test");
      }
  }
  </code></pre>
  
  <p>I can see that <code>CallAbc</code> is executed and does something (it creates a file) but then it throws an <code>AccessViolationException</code>, presumably when it tries to access the parameter.</p>
  
  <p>The <a href="http://www.purebasic.fr/english/viewtopic.php?f=27&amp;t=45226" rel="nofollow">PureDLLHelper</a> suggests that the function has 3 parameters, and after reading <a href="http://www.java-samples.com/showtutorial.php?tutorialid=334" rel="nofollow">this JNI tutorial</a> I have the feeling that I also need to pass the parameters <code>JNIEnv*, jobject</code> to simulate a JNI call. But from here on I'm lost...</p>
  
  <p>Any idea? Is it even possible what I'm trying to achieve?</p>
  
  <p><strong>Edit:</strong> I just want to mention <a href="http://forums.xamarin.com/discussion/325/native-library-integration" rel="nofollow">this forum post</a> that has a good explanation of the problems involved and how they <em>could</em> by solved. However, the solutions are based on <em>Xamarin.Android</em> to bridge the C#/Java gap and get hold of the JNIEnv, which is not really an option for me.</p>