LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW DLL call from java with jni

Hello, 

 

I am struggling to understand how to call a LabVIEW DLL that was created with the following:

String is a control (input terminal)

String2 is a control (input terminal)

CombineString is an indicator (output terminal)

 

With this I created a DLL. 

void __cdecl StringDLL(char String[], char String2[], char CombineString[],
int32_t len); This is from the header file. 

 

In my java code:

 

import com.sun.jna.Library;
import com.sun.jna.Native;

public class StringDLLMain {

		
	public interface StringDLLOne extends Library{
		String StringDLL(String String, String String2, String CombineString, 
				int len);	
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		@SuppressWarnings("deprecation")
		StringDLLOne DLL = (StringDLLOne) Native.loadLibrary("SharedLib",StringDLLOne.class);
		String one = "Hi";
		String two = "There!";
		String printout = "";
		int len = 1000;
		
		System.out.println(DLL.StringDLL(one, two, printout, len));
	}
}

The desired output should be: Hi There!

 

Note that I used JNA

I am not sure how to go about this function.

Please, help. 

Thank you in advance. 

0 Kudos
Message 1 of 4
(2,119 Views)

You need to somehow make sure that the printout string is actually allocated with the 100 characters you tell the function in the len parameter that it can at most fill into that buffer. Otherwise the function will write into invalid memory. It may be easier to declare this parameter as byte[] type and pass in a byte array with at least the same number of elements preallcated as you tell it in the len parameter and on return of the function you can then decode it back into a Java string with:

 

byte[] outBytes = new byte[100];

stringDLL(string1, string2, outBytes, outBytes.length);

String outString = new String(outBytes, StandardCharset.ISO_8859_1);
Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 4
(2,066 Views)

This gives me some idea. I am not sure if this will work. 

I will keep updating. 

 

Thanks!

0 Kudos
Message 3 of 4
(2,036 Views)

Hello BArtzon,

Did it finally work? I've got the same task soon and the customer will provide the DLL compiled in Java.

Perhaps I need to request some parameter handling?

Thank you, Peter

0 Kudos
Message 4 of 4
(1,938 Views)