IKVM C#与Java互操作使用IKVM回调 [英] IKVM C# to Java Interop with Callback using IKVM

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

问题描述

我已经开始使用IKVM翻译的Java库为.NET CIL。我可以成功地编写C#程序,在拉(INPROC)翻译后的Java组件作参考,并调用翻译的Java code。

I've started using IKVM to translate Java libs into .NET CIL. I can successfully write a C# program that pulls in (inproc) a translated Java assembly as a reference and make calls to the translated Java code.

我的问题是,是任何人都熟悉瓦特/如何拨打电话(回调)从Java到C#中使用IKVM?我一直在寻找一个好的教程或解释,但还没有看到一个。

My question is, is anyone familiar w/ how to make calls (callbacks) from Java to C# using IKVM? I've been looking for a good tutorial or explanation but haven't seen one yet.

任何帮助是AP preciated。谢谢你,

Any help is appreciated. Thanks,

MJ

推荐答案

女士们,先生们,我想通了,我自己的问题。 code首先随后的步骤。

Ladies and Gentlemen, I figured out my own question. Code first followed by steps.

Java的类

public class TestClass {
private cli.CSharpLibrary.Library m_lib = null;

public void AddDelegate( cli.CSharpLibrary.Library lib )
{
    m_lib = lib;
}

public void FireDelegate()
{
    if( m_lib != null )
    {
        m_lib.ExecuteRunnableDelegate();
    }
}

public void PrintInt()
{
    System.out.print(23);
}
}

C#类

using ikvm.runtime;
using CSharpLibrary;

namespace CSharp
{
  class Program
  {
public static void DelegateTarget()
{
  Console.WriteLine("DelegateTarget Executed!");
}

static void Main(string[] args)
{
  Library lib = new Library();
  lib.m_runnableDelegate = new Delegates.RunnableDelegate(DelegateTarget);

  TestClass tc = new TestClass();
  tc.AddDelegate(lib);
  tc.FireDelegate();

}
}
}

1)编写Java应用程序

1) Write your Java app

2)转换的* .class文件到一个JAR文件(JAR -CF myjar.jar的* .class)

2) Convert your *.class files into a jar file (jar -cf myjar.jar *.class)

3)转换的jar文件转换成.NET程序集(ikvmc -reference:csharpassembly.dll myjar.jar)

3) Convert the jar file into a .NET assembly (ikvmc -reference:csharpassembly.dll myjar.jar)

如果在这一点上工作。你可以运行你的C#程序,使用它调用转换的Java程序,反之亦然。当心在ikvmc呼叫-reference标志。这告诉IKVM时,它的转换的Java code表示csharpassembly.dll有它需要注意的一些类定义。

Should work at this point. You can run your C# program, have it call the converted Java program and vice versa. Watch out for the "-reference" flag on the ikvmc call. This tells IKVM when it's converting the Java code that csharpassembly.dll has some class definitions that it needs to watch out for.

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

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