Getting JNA to work with Java => C#?

前端 未结 3 1027
我寻月下人不归
我寻月下人不归 2020-12-20 19:52

I\'ve written a lot of code in a C# library, which I now need to call from Java.

I saw it recommended on SO to use JNA, but I\'m having trouble even getting out of t

3条回答
  •  粉色の甜心
    2020-12-20 20:33

    You won't be able to call directly into your C# code from Java. JNA will only be able to access a native library (C or C++). However you could enable COM Interop in your library and link the 2 together with a native wrapper. I.e. it would look some thing like:

    Java --(JNA)--> C/C++ --(COM Interop)--> C#

    There are a couple of alternatives:

    • Make the C# a stand alone command line app and have the Java code send/receive data from it using stdin/stdout (ProcessBuilder can help you here).
    • Run the C# as a stand alone app with some form of platform neutral messaging protocol to communicate between the 2 of them, e.g. HTTP, AMQP.

提交回复
热议问题