H
H
hHup2018-04-01 15:59:54
Java
hHup, 2018-04-01 15:59:54

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

5ac0d74aa66e4879471897.png5ac0d75424732575968027.png5ac0d759901b2297540065.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexHell, 2018-04-07
@AlexHell

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 question

Ask a Question

731 491 924 answers to any question