🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.programmer
2 messages
2 total messages Started by Editions Vigdor Mon, 03 Aug 1998 00:00
Yet another JNI problem
#322
Author: Editions Vigdor
Date: Mon, 03 Aug 1998 00:00
116 lines
2924 bytes
Hi !

I am encoutering a problem with JNI. I am trying to program a class that

would allow Java to access the W95/WNT Registry base and it seems that

the Java part of the program doesn't find the methods inside my dll :



Java source code :



package com.vigdor.vector;

public class Registres {

//Constants [skipped]..

  public Registres() {

         super();
	try {

         System.loadLibrary("Registres");
	} (catch Exception e) {
	 System.out.println("Erreur ! :"+e.getMessage())
	}

  }

    public native long setKey(int mainKey, String subKey, String entree,

String classe, String valeur);

    public native String getKey(int mainKey, String subKey, String

entree, String defaut);

}



C++ source code :



#include "com_vigdor_vector_Registres.h"

#include "winreg.h"

#include <windows.h>

#include <stdlib.h>



JNIEXPORT jlong JNICALL Java_com_vigdor_vector_Registres_setKey

  (JNIEnv *env, jobject obj, jint jMainKey, jstring jSubKey, jstring
jClasse, jstring jEntry, jstring jValue) {

//blah blah blah

	return(RegCloseKey(currentKey));

};



JNIEXPORT jstring JNICALL Java_com_vigdor_vector_Registres_getKey

  (JNIEnv *env, jobject obj, jint jMainKey, jstring jSubKey, jstring
jEntree, jstring jDefaut) {

//blah blah blah

  	return env-> NewStringUTF(retour);

};



The code compiles (with CodeWarrior 3) to a 1 kb Registres.dll. The java
code seems to find this dll (i.e. no UnsatisfiedLinkException during the
initialization) but as soon as I try to use either setKey or getKey, an
UnsatisfiedLinkException is thrown without message.
I have tried putting Registres.dll in the directories Windows,
Windows\System, Windows\System32, in the directory of the .class files
and in the directory of the final output file. 


Does anyone have an idea ?
Thanks in advance,
  David

-- 

�ditions

  num�riques scientifiques et universitaires

    VIGDOR



exploration de textes

    par ordinateur



http://www.vigdor.com

    contact@vigdor.com
Re: Yet another JNI problem
#323
Author: Joseph Millar
Date: Mon, 03 Aug 1998 00:00
38 lines
2529 bytes
Editions Vigdor <contact@vigdor.com> wrote:
[snip!]
> The code compiles (with CodeWarrior 3) to a 1 kb Registres.dll. The java
> code seems to find this dll (i.e. no UnsatisfiedLinkException during the
> initialization) but as soon as I try to use either setKey or getKey, an
> UnsatisfiedLinkException is thrown without message.

If the exception is thrown on the call to the native
method, then it's not a DLL finding or loading problem,
but either a construction or JVM restriction problem.

The code you posted looks good in terms of names and
general format.  I have no experience with CodeWarrior,
but if you dump the exported entrypoints in the DLL,
do the Java native method functions show and do they
have the correct names (ie. no preceding "_" or funny
trailing chars)?  Using MSVC++ compiler, this is done
using "dumpbin /exports name.dll".

Where is the class loaded from when it calls the native
method?  If the class has a classloader, the native
method will fail explicitly due to a hard wired check
in the JVM.

> I have tried putting Registres.dll in the directories Windows,
> Windows\System, Windows\System32, in the directory of the .class files
> and in the directory of the final output file. 

From your post, the DLL is loading fine.  If it wasn't
found, the exception would be on the loadLibrary()
call.  And the DLL should be somewhere in the PATH or
one of the dirs searched by default (ie. exe dir, cwd, 
etc).

--Joe
_____________________________________________________________________
Joseph A. Millar      Sr. Software Engineer     Iris Associates, Inc.
<jmillar@iris.com>                                http://www.iris.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads