从Java调用C#dll

我是一名Java开发人员。 但是,出于某种原因,我必须借助C#来完成我的任务。 我有下面提到的用于创建DLL的C#代码。 必须在我的Java程序中使用该DLL来完成所需的操作。

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; namespace Yrl.Tracingtool { public class DocxUtil { public Application Jump(string fileName) { object fileNameAsObject = (object)fileName; Application wordApplication; try { wordApplication = new Application(); object readnly = false; object missing = System.Reflection.Missing.Value; wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage; object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst; object count = 3; wordApplication.Selection.GoTo(ref what, ref which, ref count, ref missing); return wordApplication; } catch (Exception ex) { //LogEntry log = new LogEntry(); //log.Categories.Add("Trace"); //log.Message = ex.ToString(); //Logger.Write(log, "Trace"); throw new System.IO.FileLoadException("File cannot be opened"); } finally { wordApplication = null; } } } } 

我也检查了这个论坛和其他论坛,但大多数人都在谈论在JNI调用中使用C ++或C DLL文件。 如果有人知道从Java调用C#DLL,请告诉我。

我们使用ICE在.NET和Java应用程序之间进行通信。 这不完全是你需要的,但可能有所帮助。

另外我建议谷歌搜索“.NET Java桥” – 有几个框架(jni4net,JNBridge等)

你可能不得不使用JNI。

JNI是Java Native Interface的首字母缩写。 使用JNI,我们可以调用用Java编写的其他语言的函数

看看下面的内容

http://www.codeproject.com/Articles/2876/JNI-Basics-1