在Java项目中使用C#编写的dll
我正在开发一个 Java 项目,但我对使用 Java 不太熟悉 我通常在我的计算机视觉项目中使用 C# 和 aforge 现在我必须使用 Java,并且我想使用用 C# 编写的 aforge DLL 有办法做到这一点吗?
谢谢
I'm working on a Java project and I'm not very familiar with using Java
I usually use C# with aforge for my computer vision projects
now I have to use Java and I want to use the aforge DLLs which are written in C#
is there a way to do this ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是可能的,但您需要做一些工作才能让他们正确调用。我自己从来没有这样做过,但在有更好的人来回答这个问题之前,这里有几个地方可以开始。
看一下 JNI(Java Native Interface,谷歌或维基百科可以告诉你更多),它可以让你从 Java 调用其他语言。似乎有一个名为 jni4net 的项目( http://jni4net.sourceforge.net ),其目的正是你想要什么,但它目前处于 alpha 阶段,可能不够稳定。尽管如此,它还是值得一看的。
您也可以自己完成,通过 JNI 作为 C 调用进行调用,然后最终会到达 CLR,但这看起来需要付出很大的努力。我知道这不是一个快速且简单的解决方案,但它可能为您提供了一些开始的地方。还有http://www.codeproject.com/KB/cross-platform/javacsharp。 aspx 似乎是一个很好的了解如何去做的方法。
正如到目前为止所有其他答案所说的那样,这既麻烦又痛苦。如果你可以做点别的事情,那可能是值得的。
It is possible, but you'll need to do some work to get them calling properly. I've never done it myself, but until someone better equipped to answer the question comes along here's a few places to start.
Take a look at the JNI (Java Native Interface, google or wikipedia can tell you more), which lets you call out from Java to other languages. There seems to be a project called jni4net ( http://jni4net.sourceforge.net ) which is intended to do exactly what you want, but it's in alpha at the moment and might not be stable enough. Still it could be worth having a look.
You can also do it yourself, calling through the JNI as a C call which will then get through to the CLR eventually, but it looks like a lot of effort. I know this isn't a quick and easy solution, but it might give you a couple of places to get started. also http://www.codeproject.com/KB/cross-platform/javacsharp.aspx seemed to be a fairly good look at how to go about it.
As all of the other answers so far have said though, it's fiddly and a pain. If you can do something else instead, it will probably be worth it.
看看 Jni4Net 和这个堆栈溢出问题:有没有一个有效的工具可以将c#转换为java?
Have a look at Jni4Net and this stack overflow question: is there an effective tool to convert c# to java?
您将不得不使用本机调用,这将a)保持最新状态非常令人恼火,并且B)破坏了java跨平台的巨大优势。
您最好的选择可能是尝试找到可以将 C# 转换为 java 的东西,或者更好地将 C# 代码重新编码为 java。
从长远来看,它会为你减轻很多压力。
You would have to use native calls which would a) be really irritating to keep up to date and B) defeat the huge advantage of java being cross-platform.
Your best bet might be to try to find something that can convert C# to java--or better yet recode your C# code into java.
In the long run it will save you a lot of stress.
不确定这种可能性,但你的想法不太好。
您仍然可以使用 COM 或 hook 或尝试 ngen,但这种方式都很奇怪。
Java 与 C# 非常相似。尝试用 Java 或类似 stab 进行编码,我认为这样更容易编码使用一些基于 JVM 的 jvm 语言。
No sure about this possibility but your idea is not so good.
You still can use COM or hook or try ngen but this ways all are weird.
Java is very similar C# . Try to code in Java or something like stab , I think that is much easer to code in some JVM-based langue for jvm.
不同的编译器无效,这是不可能的。除非您在 Visual Studio 中使用 java Sharp 语言,否则编译器将是 mach。
Diferent compilers dud, it's not possible. Unless You use java sharp language in visual studio, then the compilers mach.