Reputation:
I've created a c# dll in visual studio 2008
the content of the c# dll is as given below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace hello
{
public class Class1
{
public static double addUp(double number, double Number)
{
return number + Number;
}
public static double minus(double number, double Number)
{
return number - Number;
}
}
}
and through java i've loaded the hello.dll using
System.loadLibrary("hello");
The java code is as given below:
package pkgnew;
import javax.swing.JOptionPane;
public class check
{
public static native double addUp(double number,double Number);
static
{
try
{
System.loadLibrary("hello");
System.out.println("SUCCESS");
}catch(Exception ex){ JOptionPane.showMessageDialog(null,"Required DLLs Not Found\n"+ex.getCause(),"Error Loading Libraries", JOptionPane.ERROR_MESSAGE);}
}
public static void main(String[] args)
{
new check().getval();
}
public void getval() {
try
{
double g=this.addUp(52.2, 51.3);
}catch(Exception y){System.out.println("ERROR IS:"+y);}
}
}
but the problem is that i'm getting output as:
OUTPUT
SUCCESS
Exception in thread "main" java.lang.UnsatisfiedLinkError: pkgnew.check.addUp(DD)D
at pkgnew.check.addUp(Native Method)
at pkgnew.check.getval(check.java:35)
at pkgnew.check.main(check.java:29)
Java Result: 1
Can anyone tell me why i'm getting this error....and why i'm not able to call the dll methods
Upvotes: 1
Views: 2094
Reputation: 3833
You cannot directly call C# dll in Java. There is a workaround. You'll have to first write a C++ managed class for C# code then create a of C++ dll and use it in java.
Upvotes: 0
Reputation: 23208
I don't think you can call native extensions in Java without using JNI wrappers (or at least some library which translates to JNI under the hood). Have you tried out the frameworks/suggestions mentioned in this thread?
Upvotes: 1