Board index » jbuilder » call C code from java

call C code from java


2003-07-29 09:13:15 PM
jbuilder12
Hi there,
I trying to call some function, written in C from java. The function placed in regular DLL. The DLL was built with Microsoft Visual C++ 6.0.
Step by step:
1. Write an Java application
2. Compile it using Borland JBuilder 8.
3. Create a class named “NativeCaller? The class looks like:
public class NativeCaller extends Object {
public NativeCaller(){ }
static {
System.loadLibrary("NativeCaller");
}
public native int CallNativeFunc(String str1, String str2);
}
4. Create the .h file using javah.exe from jdk1.4
5. Write implementation file for CallNativeFunc ?NativeCaller.c
#include <windows.h>
#include <jni.h>
#include "NativeCaller.h"
JNIEXPORT jint JNICALL Java_NativeCaller_CallNativeFunc(
JNIEnv *env,
jobject obj,
jstring str1,
jstring str2
)
{
return 0;
}
6. Build the DLL.
7. Execute the Java application. ?You’ll get
error “UnsatisfiedLinkError?
In the detailMessage: java.lang.String
= “CallNativeFunc?
Can somebody explain it to me please.
 
 

Re:call C code from java

JVM can't find your DLL. Call your java app as follows:
cd /d c:\path_to_your_project\classes
java -Djava.library.path=c:\path\to\your\dll\directory
yourpackage.MainClass
Another approach can be to copy your DLL into one of the directories listed
in the java.library.path property (System.getProperty("java.library.path")
or go to JB Help/About JBuilder.../Info tab).
--Sultan
On 29 Jul 2003 06:13:15 -0700, Dimitry < XXXX@XXXXX.COM >wrote:
Quote

Hi there,

I trying to call some function, written in C from java. The function
placed in regular DLL. The DLL was built with Microsoft Visual C++ 6.0.

Step by step:
1. Write an Java application 2. Compile it using Borland JBuilder 8.
3. Create a class named “NativeCaller� The class looks like:
public class NativeCaller extends Object {
public NativeCaller(){ }
static {
System.loadLibrary("NativeCaller");
}

public native int CallNativeFunc(String str1, String str2);
}
4. Create the .h file using javah.exe from jdk1.4 5. Write implementation
file for CallNativeFunc �NativeCaller.c
#include <windows.h>
#include <jni.h>
#include "NativeCaller.h"
JNIEXPORT jint JNICALL Java_NativeCaller_CallNativeFunc(
JNIEnv *env, jobject obj, jstring str1, jstring str2
)
{
return 0;
}

6. Build the DLL.
7. Execute the Java application. �You’ll get error
“UnsatisfiedLinkError� In the detailMessage: java.lang.String =
“CallNativeFunc�

Can somebody explain it to me please.