Answer the question
In order to leave comments, you need to log in
How to pass data from a java class to a native block of code written in C++?
Good day, dear coders. I need to create a program where the graphical part will be written in java, where the user enters the value A and B (for example), then these values are passed to the native code written in c++. He, in turn, solves a complex equation with variables A and B and returns the value back. Separately, I can write both C ++ and java code, but I can’t make them make friends in any way. I found an article on Habrahabr, but nothing comes out even at the very beginning. Here is the error and below is the code.
"C:\Program Files\Java\jdk-9\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.3\lib\idea_rt.jar=57525:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\lenovo\IdeaProjects\lab_2-3\out\production\lab_2-3 my.mega.pack.main
Exception in thread "main" java.lang.UnsatisfiedLinkError: no NativeCallsClass in java.library.path
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2541)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:873)
at java.base/java.lang.System.loadLibrary(System.java:1857)
at my.mega.pack.NativeCallsClass.<clinit>(NativeCallsClass.java:5)
at my.mega.pack.main.main(main.java:6)
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
I can't help with the approach you used.
I tried only such a tool https://github.com/nativelibs4java/JNAerator generated a Java class to an already existing DLL (from Steam), in which it turned out like
public interface LibrarySteamAppTicket extends Library {
byte SteamEncryptedAppTicket_BDecryptTicket(uint8 rgubTicketEncrypted, int cubTicketEncrypted, uint8 rgubTicketDecrypted, IntByReference pcubTicketDecrypted, Pointer rgubKey, int cubKey);
...
}
and called
private static LibrarySteamAppTicket Library = (LibrarySteamAppTicket) Native.loadLibrary("sdkencryptedappticket64" , LibrarySteamAppTicket.class);
// moreover, sdkencryptedappticket64.dll lies next to the jar at release (or in the netBeans project at the root)
...
byte ret = Library.SteamEncryptedAppTicket_BDecryptTicket(..)
Moreover, the DLL was obviously created not for java, but an arbitrary one is possible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question