raj*_*har 5 c# java dll java-native-interface
我是一名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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也检查过这个论坛和其他论坛,但大多数人都在谈论在JNI调用中使用C++或C DLL文件.如果有人知道从Java调用C#DLL,请告诉我.
您可能必须使用 JNI。
JNI 是 Java 本机接口的缩写。使用JNI,我们可以从Java中调用其他语言编写的函数
看看下面的
http://www.codeproject.com/Articles/2876/JNI-Basics-1