title: How to call C# function from java
body: <p>I need to call C# function from java and to this I have created the following.
  I have a create a java header file Authenticator.h , here is the code:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  /* Header for class Authenticator */
  
  #ifndef _Included_Authenticator
  #define _Included_Authenticator
  #ifdef __cplusplus
  extern "C" {
  #endif
  /*
   * Class:     Authenticator
   * Method:    authenticate
   * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
   */
  JNIEXPORT jboolean JNICALL Java_Authenticator_authenticate
    (JNIEnv *, jobject, jstring, jstring);
  
  #ifdef __cplusplus
  }
  #endif
  #endif
  </code></pre>
  
  <p>I have then create a C# function that Authenticate </p>
  
  <pre><code>namespace SharpAuthenticator
  {
      public class Authenticator
      {
  
  
  
          public  bool Authenticate(String username,String password)
          {
              return username == "user" &amp;&amp; password == "login";
          }
  
      }
  }
  </code></pre>
  
  <p>Then I am trying to call the C# function from C++(project to create a dll) using the code below;</p>
  
  <pre><code>String^ toString(const char *str)
  {
      int len = (int)strlen(str);
      array&lt;unsigned char&gt;^ a = gcnew array&lt;unsigned char&gt;(len);
      int i = 0;
      while (i &lt; len)
      {
          a[i] = str[i];
          i++;
      }
      return Encoding::UTF8-&gt;GetString(a);
  }
  bool authenticate(const char *username, const char *password)
  {
       SharpAuthenticator::Authenticator::Authenticate(toString(username), toString(password));
  
  }
  JNIEXPORT jboolean JNICALL Java_Authenticator_authenticate
  (JNIEnv *env, jobject c, jstring name, jstring pass)
  {
      jboolean result;
  
      jboolean isCopyUsername;
      const char * username = env-&gt;GetStringUTFChars(name, &amp;isCopyUsername);
      jboolean isCopypassword;
      const char * password = env-&gt;GetStringUTFChars(pass, &amp;isCopypassword);
  
      result = authenticate(username, password);
      env-&gt;ReleaseStringUTFChars(name, username);
      env-&gt;ReleaseStringUTFChars(pass, password);
      return result;
  }
  </code></pre>
  
  <p>And finnally create a dll that i need to call from java. The dll is created and I load it well in java but I get this error log in java. What could I be Missing.</p>
  
  <pre><code>#
  # A fatal error has been detected by the Java Runtime Environment:
  #
  #  Internal Error (0xe0434352), pid=9708, tid=7756
  #
  # JRE version: 7.0-b147
  # Java VM: Java HotSpot(TM) Client VM (21.0-b17 mixed mode, sharing windows-x86 )
  # Problematic frame:
  # C  [KERNELBASE.dll+0x812f]
  #
  # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
  </code></pre>