how to call methods from a c# dll in java?
-
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
-
Answer:
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 http://stackoverflow.com/questions/50398/calling-c-sharp-code-from-java?
user995074 at Stack Overflow Visit the source
Other answers
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. http://www.codeproject.com/KB/cross-platform/javacsharp.aspx
HashimR
Related Q & A:
- How to call java from c#?Best solution by Stack Overflow
- Is it unsafe to call methods from a thread?Best solution by stackoverflow.com
- How to call functions inside a function in Python?Best solution by Stack Overflow
- How to call delegate methods from other class in Swift?Best solution by stackoverflow.com
- How to call a GOOGLE API in C#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.