This document will show you how to call LabView
compiled DLL by Java with JNI.
JAVA Version: jdk1.7.0_79 32bit
LabView Version: 2014
Visual Studio Version: 2015
Notice:
You need change the file/folder path if necessary
1.
Write Native method in java file
2.
Compile java file with javac command
3.
Use javah compiled class file to
generate .h file
4.
Use C++ implements native method defined in java
file and need include .h file generated by javah
5.
Compile C++ source to DLL
6.
Use the DLL
1.
Define method in labview and compile to
DLL
2.
Write Native method in java file
3.
Compile java file with javac command
4.
Use javah compiled class file to
generate .h file
5.
Use C++ implements native method defined in java
file and need include .h file generated by javah. At the same time,
need wrap/call labview compiled DLL
6.
Compile C++ source to DLL
7.
Use the two DLL(Labview compiled and C++ compiled)
together
1.
Define method in labview and compile to
DLL
l
You can load my project: test.lvproj
l
Define “add” method in labview
l
Define the function name with “labview_add” and
build the dll
l
Dll file generated under folder:
labviewPrjBuilds
2.
Write Native method in java file
l
You can find my java file: AddFun.java
l
Define a native method in AddFun.java
file
3.
Compile java file with javac command
l
You can find my compile script file:
runJavaC.bat
l
Compile the .java file to .class file by javac
command
l
.class file will be generated under bin
folder
4.
Use javah compiled class file to
generate .h file
l
You can find my compile script file:
runJavaH.bat
l
Generate .h file base on .class
file
l
.h file will be generated under bin
folder
5.
Use C++ implements native method defined in java
file and need include .h file generated by javah. At the same time,
need wrap labview compiled DLL
l
Create a win32 project with VS under folder vsPrj.
And remember select application type
“DLL”
l
Create
otherinclude folder under vsPrj folder. Use to
save third party h/lib file. Copy Labview 2014
supplied extcode.h, JDK supplied jawt_md.h, jni.h,
jni_md.h into this
folder. And also copy javah compiled zz_AddFun.h,
LabView project build labview_add.lib, labview_add.dll into this
folder.
l
Open the
wrapperAdd solution with VS
l
Right click
“wrapperAdd” and select “Properties” . Add “..\..\otherinclude”
into “Additional Include Directories”
value.
l
Open file:
wrapperAdd.cpp and add below content base on zz_AddFun.h
file
l
Now, we add
Labview compiled dll/function into this wrapper file. Need include
the labview_add.lib which under other include
folder
l
Although now
error in code, but when you compile, it may show some error like
below
Solution is:
add a macro to support this.
l
Add C++ to C
macro
l
Now, you can
compile successful
6.
Use the two DLL(Labview compiled and C++ compiled)
together in Java
l
Copy labview
generated labview_add.dll and vs generated wrapperAdd.dll into
javatest folder.
l
Make a java file
to use the wrapperAdd.dll
l
Use
compileJAVATest.bat to compile the java file
l
Use
runJAVATest.bat to run the java compiled class file
l
The test result
is:
l
Copy the whole
labviewPrj folder/project to labviewPrj_multi . Also change build
file destination folder to
C:\Users\zz\case\labviewPrjBuilds_multi
l
change + to x and
build again
l
copy the file
labviewPrjBuilds_multi\labview_add.dll to javatest folder.
l
The test result
is:
l
So now, when you
change Labview code, you don’t need to change C/Java
part
file download
path: http://pan.baidu.com/s/1pLNVZDp