C#DLL与Java的兼容性 [英] c# dll compatability with java

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

问题描述

如何使c#dll与Java兼容?

How to make c# dll compatible with java??

推荐答案

这取决于您所谓的"Java".如果Java仅是语言,则有些产品可以使您将Java用作.NET语言.请参阅:
http://en.wikipedia.org/wiki/.NET_language [ http://en.wikipedia.org/wiki/JVM [ ^ ]),粗略地说,没有兼容性.

从理论上讲,有可能建立一些互操作性的桥梁,但是这是一条漫长的路,我不愿对其进行详细讨论.我认为这没有任何实际意义.我不知道这样的项目是否存在.简而言之,您可以自动重新构建.NET程序集,使其可以将某些静态方法导出为非托管方法.在纯C#中这是不可能的,但是CIL标准允许这样做.很少有CodeProject文章解释如何做到这一点,并且完整地介绍了使用ILDASM和ILASM(IL Assember和Disassembler)的代码.这本身就是一个非常有趣的主题(许多开发人员声称这是不可能的,但事实并非如此),但这只是必需的步骤之一.另一种方法是对COM使用另一种变通状态.结果,您可能具有混合模式的程序集(托管+非托管)或COM DLL,并通过JNI( http://en.wikipedia.org/wiki/JNI [^ ], http://electrofriends.com/articles/jni/jni-part1 -java-native-interface/ [ ^ ]).

我无法想象一个完全清醒的开发人员会自愿参与到所有这些混乱之中. CLR和Java是两个不同的词;它们有很多共同点,但是彼此之间的距离比Java或CLR在完全不同的平台上要远得多.



但是,请参阅以下最新答案:我们可以在Java项目中重用C#开发的DLL吗? [
It depends on what you call "Java". If Java is just the language, there are products which would enable you to use Java as a .NET language. Please see:
http://en.wikipedia.org/wiki/.NET_languages[^].

If by "Java" you mean something which works with Java Virtual Machine (http://en.wikipedia.org/wiki/JVM[^]), roughly speaking, there is no compatibility.

Theoretically speaking, it''s possible to make some interoperability bridge, but this is such a long way that I would hate to discuss it in detail. I don''t think it can make any practical sense. I don''t know if such projects exist. In brief, you can automatically re-build a .NET assembly the way that it can export some static methods as unmanaged. In pure C# this is not possible, but CIL standard allows it. There are few CodeProject articles explaining how to do it, complete with the code which uses ILDASM and ILASM (IL Assember and Disassembler) under the hood. This is itself a very interesting topic (many developers claim this is not possible, but this is not true), but this is only one of the required steps. The alternative way would be using one more work-around state with COM. As a result, you could have either a mixed-mode assembly (managed+unmanaged) or a COM DLL and use it with Java through JNI (http://en.wikipedia.org/wiki/JNI[^], http://electrofriends.com/articles/jni/jni-part1-java-native-interface/[^]).

I cannot imagine a fully sober developer who would volunteer to go into all this mess. CLR and Java are two different words; they have a lot of in common but are much more distant from each other than either Java or CLR on very different platforms.



However, please see this recent answer: can we reuse DLL developed in C# in java projects[^].

—SA


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

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