从Java调用C#DLL [英] Calling C# dll from Java

查看:1091
本文介绍了从Java调用C#DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Java开发人员。但是,由于某种原因,我不得不采取C#的帮助来完成我的任务。下面我所提到的,用于创建一个DLL C#代码。 。该DLL在我的Java程序做要紧要使用

I am a Java developer. But, for some reason I have to take the help of C# to accomplish my task. I have below mentioned C# code which is used to create a DLL. That DLL has to be used in my Java program to do the needful.

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方面的知识,请让我知道

I have checked this forum and other forums too, but most of them talk about using a C++ or C DLL file in a JNI call. If anyone is having knowledge of calling C# DLL from Java please let me know.

推荐答案

我们使用的 ICE 以.NET和Java应用程序之间的通信。这不正是你所需要的,但可能有助于

We use ICE to communicate between .NET and Java apps. It is not exactly what you need but might help.

另外,我建议你使用Google的NET Java的桥梁。的 - 有几个框架这个(jni4net,JNBridge的等)

Also I'd recommend googling ".NET Java bridge" - there are several frameworks for this (jni4net, JNBridge etc)

这篇关于从Java调用C#DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆