Search code examples
javac#java-native-interfacenative

JNI: Call C# method from Java


I want to call C# method from Java using JNI. I have the DLL as well as the exe with me. Hello world program in C# looks like:

using Test;


    {
            clsMain tst = new clsMain;
            clsInput input = new clsInput;
            clsOutput output = new clsOutput;
            input.strTekstInput = "John";
            output = tst.funMain(input);
            MsgBox(output.strTekstOutput);
        }

I want to call this method and print the output using JNI. But I am not sure how to achieve this as I have never used JNI. Can someone help with What I need to do here? Appreciate response.

regards, Venky


Solution

  • Actually, you cannot directly call the C# method from Java code but you can write C++ wrapper. This C++ wrapper can be get called from Java code and eventually this C++ wrapper can call C# method.

    So it would be like this: Java --> C++ Wrapper --> C#