0

I am trying to use C# dll function in java. I got the error that function cannot be found, however, the dll was found and successfully loaded.

While I was searching for a problem I found that sometimes a compiler mangle the symbols and the whole function name to something like 'myFunction@32' instead of 'myFunction'. Unfortunately that wasn't my issue.

public interface IConectorT extends Library {
boolean DeleteCustomObjectRecord(String company, String username, String password, int cdoId, 
String cdoName, int[] cdoRecordIds);


IConectorT INSTANCE = (IConectorT) Native.loadLibrary("C:\\Windows\\System32\\Eloqua API", 
IConectorT.class, new HashMap() {
    {
        put("DeleteCustomObjectRecord","_DeleteCustomObjectRecord@32");
    }
});
}

I have tried @64, @32, @16 etc. Also tried adding "_" as prefix. I have also tried absolute path with ".dll" and without, relative path the same. (But loading is not a problem)

I tried a little update and now it returns this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
Main.Main.DeleteCustomObjectRecord(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava
/lang/String;[I)Z
at Main.Main.DeleteCustomObjectRecord(Native Method)
at Main.Main.main(Main.java:15)
Ondrej Tokar
  • 4,898
  • 8
  • 53
  • 103

1 Answers1

1

As far as I know, JNA is for native library only. You will need to write a C/C++ wrapper for your C# library before accessing it from Java.

Check this answer

Community
  • 1
  • 1
ortis
  • 2,203
  • 2
  • 15
  • 18
  • Are you using a C/C++ dll ? – ortis Sep 01 '14 at 09:39
  • C# so maybe you are right, can you advice me how to do that? Thanks. – Ondrej Tokar Sep 01 '14 at 10:08
  • Check out http://www.codeproject.com/Articles/13093/C-method-calls-within-a-Java-program and http://www.codeproject.com/Articles/378826/How-to-wrap-a-Csharp-library-for-use-in-Java . You could also use standalone command line C# program and access it with `ProcessBuilder` or HTTP server like proposed by Michael Barker@ in the post I linked in my first response. – ortis Sep 01 '14 at 10:24