0

I already reseached but didn't fount what I need. In Java you can load a .dll with System.load("path");. But anything beyond this is too confusing for me. So I need soneone who can explain me this. In C# I have the following class compiled into TestDll.dll:

namespace TestNamesapce
{
  public class TestClass
  {
    private int testInt;

    public TestClass(int pTestInt)
    {
      testInt = pTestInt;
    }

    public int AddToTestInt(int pToAdd)
    {
      return testInt + pToAdd;
    }
  }
}

How can I create a TestClass object and call the AddToTestInt method in Java? Atm Im at this point:

package testPackage;

public class JavaTestClass
{
  public static void main(String[] args)
  {
    try
    {
      System.Load("D:\\MyDLLs\\TestDll.dll")
    }
    catch(Exception ex)
    {
      ex.printStackStrace();
    }
  }
}

Please explain as simple as possible, thank you realy much :)

BDevGW
  • 347
  • 3
  • 15
  • Err: AddToMyInt ... isnt a method showing up in your C# code. – GhostCat Mar 13 '19 at 13:05
  • 2
    It doesn't matter what programming language you used to write the code that finally got compiled into that DLL. What matters is: the **content** of that DLL must adhere to the requirements of the JNI interface. In other words: you cant just call code from *any arbitrary* DLL from Java. The DLL needs to be "tuned" when you want it to be used from Java. Compiling arbitrary C# into a DLL ... simply isnt a valid starting point for calling the code from Java! – GhostCat Mar 13 '19 at 13:07
  • 1) The answerd question does not create an Object of a class (as far as I can see) 2) I don't understand the example there, I dont know why he uses new Memory(4) and so on so I need a better documentation to understand this :( – BDevGW Mar 13 '19 at 13:17
  • Ok if I can't use a simple .dll than I have to rewrite my code in Java again, thats easier. Thank you :) – BDevGW Mar 13 '19 at 13:28

0 Answers0