java调用labview,Java call LabView compiled DLL by JNI

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

a4c26d1e5885305701be709a3d33442f.png

l

Define “add” method in labview

a4c26d1e5885305701be709a3d33442f.png

l

Define the function name with “labview_add” and

build the dll

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

l

Dll file generated under folder:

labviewPrjBuilds

a4c26d1e5885305701be709a3d33442f.png

2.

Write Native method in java file

l

You can find my java file: AddFun.java

a4c26d1e5885305701be709a3d33442f.png

l

Define a native method in AddFun.java

file

a4c26d1e5885305701be709a3d33442f.png

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

a4c26d1e5885305701be709a3d33442f.png

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

a4c26d1e5885305701be709a3d33442f.png

l

.h file will be generated under bin

folder

a4c26d1e5885305701be709a3d33442f.png

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”

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

l

Open the

wrapperAdd solution with VS

l

Right click

“wrapperAdd” and select “Properties” . Add “..\..\otherinclude”

into “Additional Include Directories”

value.

a4c26d1e5885305701be709a3d33442f.png

l

Open file:

wrapperAdd.cpp and add below content base on zz_AddFun.h

file

a4c26d1e5885305701be709a3d33442f.png

l

Now, we add

Labview compiled dll/function into this wrapper file. Need include

the labview_add.lib which under  other include

folder

a4c26d1e5885305701be709a3d33442f.png

l

Although now

error in code, but when you compile, it may show some error like

below

a4c26d1e5885305701be709a3d33442f.png

Solution is:

add a macro to support this.

l

Add C++ to C

macro

a4c26d1e5885305701be709a3d33442f.png

l

Now, you can

compile successful

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

l

Make a java file

to use the wrapperAdd.dll

a4c26d1e5885305701be709a3d33442f.png

l

Use

compileJAVATest.bat to compile the java file

a4c26d1e5885305701be709a3d33442f.png

l

Use

runJAVATest.bat to run the java compiled class file

a4c26d1e5885305701be709a3d33442f.png

l

The test result

is:

a4c26d1e5885305701be709a3d33442f.png

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:

a4c26d1e5885305701be709a3d33442f.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值