I recently found the UnmanagedExports library , which allowed me to access C # methods directly from Java using JNA .
Does anyone know what is wrong with my attempt to return an array of bytes from C # to Java?
Here is my example:
C # code:
using System;
using RGiesecke.DllExport;
namespace JnaTestLibrary
{
public class JnaTest
{
[DllExport]
public static byte[] returnT1()
{
byte[] t1 = {1,2,3,4,5};
return t1;
}
}
}
Java Code:
package me.mt.test;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class JnaTest {
public interface JnaTestInterface extends Library{
byte[] returnT1();
}
static JnaTestInterface jnaTest = null;
static{
if(Platform.is64Bit()){
jnaTest = (JnaTestInterface)Native.loadLibrary("JnaTestLibrary64", JnaTestInterface.class);
}
else{
jnaTest = (JnaTestInterface)Native.loadLibrary("JnaTestLibrary86", JnaTestInterface.class);
}
}
public byte[] returnT1(){
return jnaTest.returnT1();
}
}
Java exception:
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported return type class [I in function returnT1
source
share