

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
1 message in net.java.dev.jna.usersRES: RES: [jna-users] Using multiple ...| From | Sent On | Attachments |
|---|---|---|
| Felipe Armoni, felipe.armoni | May 21, 2009 9:44 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | RES: RES: [jna-users] Using multiple libraries | Actions... |
|---|---|---|
| From: | Felipe Armoni, felipe.armoni (farm...@itautec.com) | |
| Date: | May 21, 2009 9:44:19 am | |
| List: | net.java.dev.jna.users | |
Hi Timothy,
I've implemented the callback function and it is just what I needed.
Thank you very much, Felipe
-----Mensagem original----- De: Timothy Wall [mailto:twal...@dev.java.net] Enviada em: quarta-feira, 20 de maio de 2009 17:35 Para: use...@jna.dev.java.net Assunto: Re: RES: [jna-users] Using multiple libraries
Have your JAva program register a callback with your native code, e.g.
extern "C" void registerLogHandler((*func)(char *message));
Map that function and pass it an object implementing the Callback interface,
with a single method that takes a String argument, which you can then forward on
to log4j.
On May 20, 2009, at 4:05 PM, Felipe Armoni, felipe.armoni wrote:
Hi,
I've setteded the jna.library.path property using the System.setProperty() method and then changed my code to:
public Lumidigm INSTANCE = (Lumidigm) Native.loadLibrary("lumidigmhelper", Lumidigm.class);
I've ran the program and all went well.
As for my other problem I think that for now, I'll stick with returning a string containing the log for each function, and use log4j in my java program to ouput it to a file.
What I thought was to receive the reference to a char* in the function parameters and then writing the log in this variable.
Thus, I made a small test program to see what I could do...
The code for the C++ function is:
extern "C" EXPORT void teste (char* (&str)) { str = "Testando"; cout << "String recebida: " << str; }
And the Java code from my library interface is:
public void teste(StringByReference str);
I then created the class StringByReference that extends the ByReference classe to handle the char* (&str) from the C++ test function:
package br.com.itautec.centralbiometrica.nativeInterfaces.lumidigm;
import com.sun.jna.Pointer; import com.sun.jna.ptr.ByReference;
public class StringByReference extends ByReference { public StringByReference() { this(new String()); }
public StringByReference(String value) { super(16); setValue(value); }
public void setValue(String value) { getPointer().setString(0, value); }
public String getValue() { Pointer ptr = super.getPointer();
return ptr.getString(0); } }
The java call to the test function is:
System.setProperty("jna.library.path", "C:\\Itautec\\Central Biometrica\\C++\\LumidigmHelper\\Release");
Lumidigm lumi = Lumidigm.INSTANCE;
StringByReference str = new StringByReference(); lumi.teste(str);
System.out.println("Valor retornado: " + str.getValue());
However the console output for the execution of this program is:
Valor retornado: 3ûàú String recebida: Testando
As you can see the value returned by the StringByReference class is completly corrupted...
What am I doing wrong?
Also in the StringByReference constructor I call its superclass constructor using super(16), but I really don't know what does this value truly means, I think that it is the size of the input data that you are expecting to receive, so I setted it to 16 there because I am sending an 8 character string and each character occupies 2 bytes, but this is just a guess.
Finally please note that the value of the str variable in the C++ test function is being set to "Testando" as stated in the returned value "String recebida: Testando".
Thank you very much for your help,
Felipe
-----Mensagem original----- De: Timothy Wall [mailto:twal...@dev.java.net] Enviada em: quarta-feira, 20 de maio de 2009 15:56 Para: use...@jna.dev.java.net Assunto: Re: [jna-users] Using multiple libraries
JNA uses the property jna.library.path to search for libraries that it loads. On Windows, dependent libraries must be found either in the same directory as the original dll or in %PATH%.
Since your error indicates it can't find "\lib\Lumidigm \LumidigmHelper.dll", it seems you didn't provide simply the library name, "lumidigmhelper". The docs for Native.loadLibrary indicate that you should provide either the full, absolute pathname, or the simple library name without any prefix OR suffix.
On May 20, 2009, at 10:33 AM, Felipe Armoni, felipe.armoni wrote:
Hi,
I am developing a managed .dll in Visual C++ that has several other dlls as its dependencies. After I compiled it, I created a lib folder in my Java Eclipse project and put my dll and all the other dependencies inside it.
My first problem is that whenever I have to access my dll I need to provide the full system path, I cannot just write its name. Therefore the statement below works: public Lumidigm INSTANCE = (Lumidigm) Native.loadLibrary("C:\ \Itautec \\Central Biometrica\\Java\\LumidigmSensor\\lib\\Lumidigm\ \LumidigmHelper.dll", Lumidigm.class);
But this other statement throws the following exception: public Lumidigm INSTANCE = (Lumidigm) Native.loadLibrary("LumidigmHelper.dll", Lumidigm.class);
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library '\lib\Lumidigm\LumidigmHelper.dll': Não foi possível encontrar o módulo especificado.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
at com.sun.jna.Library$Handler.<init>(Library.java:123)
at com.sun.jna.Native.loadLibrary(Native.java:255)
at com.sun.jna.Native.loadLibrary(Native.java:241)
at br .com .itautec .centralbiometrica .nativeInterfaces.lumidigm.Lumidigm.<clinit>(Lumidigm.java:12)
at br.com.itautec.innovatricsEngine.Program.main(Program.java:34)
The dll's path is <project folder>\lib\Lumidigm. Do I have to include this path on the classpath for this to work? If so how can I do that with Eclipse?
My second problem is that I am trying to put some logging inside my dll and I am using the log4net api to do it. The thing is that I keep getting the error below:
# # An unexpected error has been detected by Java Runtime Environment: # # Internal Error (0xe0434f4d), pid=3772, tid=468 # # Java VM: Java HotSpot(TM) Client VM (1.6.0_02-b06 mixed mode, sharing) # Problematic frame: # C [kernel32.dll+0x12a5b] # # An error report file with more information is saved as hs_err_pid3772.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp #
I think that this is because the dll is not finding the log4net.xml or the log4net.dll, but I am not sure. I have tested this dll with another C++ program and it worked fine, plus all the required dlls and xmls are in the same folder as my dll.
Do any of you have a recommendation as what I should do? Does anyone uses logging in their dlls? Should I continue to use log4net or do you recommend another api?
I also thought about making all of my functions return a char* with the logging information, this way I could log everything in the java program using log4j, although this seems like a rather dirty solution to me...
Thank you all, Felipe







