Attached is an example DLL Maker project that calls a Java function using the Java Native Interface (JNI) from C++. The steps for how this works are outlined below:
1. Install the Java Development Kit (JDK).
2. Write a Java program.
3. Compile the .java file into a .class file. I did this using the Command Prompt and executing the following command:
javac Hello.java
4. Configure the DLL Maker project to include the JNI library:
5. Include jni.h in your code. (Line 51 of mydll.cpp)
6. Create a JVM in your code. (Lines 61-102 of mydll.cpp)
7. Get a handle to the method you want to call and then call it. (Lines 118-126 of mydll.cpp)
8. Connect a User Command in FlexSim to fire that C++ code that executes Java code. See the dll_maker_test_model.fsm included in the attached zipped directory.
* Note: this example was built with 32-bit FlexSim because the JDK I installed was 32-bit. Using a 64-bit JVM is beyond the scope of this simple example and is left as an exercise for the user.