"Unsatisfied Link" exception when trying to use JNI
I have the following Java class:
package no.gaiasoft.fotoboks;
public class Capture {
// native method declaration
native byte[] grabImage();
// Load the library
static {
System.loadLibrary("canoncapture");
}
public static void main( String args[]) {
byte buf[];
Capture img = new Capture();
buf = img.grabImage();
String s = new String(buf);
System.out.println(s);
}
}
This I run thru javah to get this header file:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class no_gaiasoft_fotoboks_Capture */
#ifndef _Included_no_gaiasoft_fotoboks_Capture
#define _Included_no_gaiasoft_fotoboks_Capture
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: no_gaiasoft_fotoboks_Capture
* Method: grabImage
* Signature: ()[B
*/
JNIEXPORT jbyteArray JNICALL Java_no_gaiasoft_fotoboks_Capture_grabImage
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
I implement "canoncapture.dll" in visual studio like this:
#include "stdafx.h"
#include "jni.h"
JNIEXPORT jbyteArray JNICALL Java_no_gaiasoft_fotoboks_Capture_grabImage
(JNIEnv * env, jobject jobj) {
jbyteArray jb;
jb = env->NewByteArray(15);
env->SetByteArrayRegion(jb,0,14, (jbyte *)'A');
return (jb);
}
I put "canoncapture.dll" in java.library.path, and run Capture.
this gives me the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: grabImage
at no.gaiasoft.fotoboks.Capture.grabImage(Native Method)
at no.gaiasoft.fotoboks.Capture.main(Capture.java:17)
Can anyone shed som light on what i might be doing wrong here?
TIA...
--
Dag.
Listen to your brain - it has a lot of information.
(Chelsey, 7) -