문제

I am using Unamanged dependencies (RGiesecke.DllExport.DllExport) and jna in a small C# function that should return a string consumed within another now java function.

Following the jna suggestions for mapping i crafted the code below:

My C# code:

[RGiesecke.DllExport.DllExport]
public static unsafe char* Test(string id)
{
  unsafe
  {
      fixed (char *s = "test passed")
          {
              return s;
           }
       }    
 }

Java side:

public interface ITest extends Library{

    public String Test(String id);
}

 public static void main(String[] args) {

 ITest nativeExample= (ITest)Native.loadLibrary("C:/native/JavaLib.dll", ITest.class);
  String s = nativeExample.Test("id");
  System.out.println(s);
 }

So, all that is printed, is 't', because I bet all is being transmitted is the address to s[0]. Has anyone had luck mapping strings from C# to java through jna?

Plain strings in the C# code throws errors.

도움이 되었습니까?

해결책

Have you tried returning a string instead of char? or changing char *s to char s[]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top