Hallo, ich versuche mich gerade an JNI und ich habe jetzt ein java programm und das C programm. Die DLL wird erstellt. Wenn ich sie aber in dem Java programm ausführe dann wirft sie einen Fehler. Wenn ich eine DLL von einem Freund benutze funktioniert es. Weiters wollte ich wissen ob es in netbeans eine funktion gibt um das headerfile zu erstellen?
Ich poste mal den Code:
hier die c datei
und hier die h datei
bitte um rasche hilfe
Ich poste mal den Code:
Java:
package test;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class JNITest {
static{
try{
System.loadLibrary("libAPR_-_C_-_JNI_-_FirstDLL");
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public JNITest()
{
try{
System.out.println(callNative());
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public native String callNative();
public static void main(String[] args) {
new JNITest();
}
}
Code:
#include <stdio.h>
#include <jni.h>
#include "JNITest.h"
JNIEXPORT jstring JNICALL Java_test_JNITest_callNative(JNIEnv *env, jobject obj)
{
jstring jstr;
printf("Java ruft native Code auf\n");
jstr = (*env) -> NewStringUTF(env, "Hallo");
return jstr;
}
Code:
/*
* File: JNITest.h
* Author: Administrator
*
* Created on 16. November 2011, 12:14
*/
#include <jni.h>
#ifdef _cplusplus
extern "C" {
#endif
JNIEXPORT jstring JNICALL Java_test_JNITest_callNative(JNIEnv *, jobject);
#ifdef _cplusplus
}
#endif