Consuming a .Net library via COM or direct integra

2019-02-25 03:43发布

I have to admit the last time I programmed in Java was a data structures class in high school. So please be kind to this Java noob.

I have spent a good deal of time putting together a C# COM library at work. This library relies heavily on some new .Net technologies (WPF being the big one) so translating it into another language is not really an option. I have tested consuming this library from C++ through the COM interface and that was simple enough. I wanted to also prove that this same library could be used from a Java program.

So the problem that I have run into is that I can not find a free or even inexpensive way to use COM objects from Java. I guess the other solution would be to find a way to directly integrate the library. Does anyone have any input on what might be the best way to accomplish this? I am using Eclipse for my java environment. Below is an example of what my C# codes exposure looks like. Thanks for any direction you can provide.

//Example C# Object Code

[Serializable,
ComVisibleAttribute(true),
Guid("Long Guid String"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IFooBarStructure)),
ProgID("My Application")]

public class MyFooBarObject
{

   public MyFooBarObject(){}

   public string DotNetMethod(){ return String.Empty; }

}

标签: c# java com
5条回答
Bombasti
2楼-- · 2019-02-25 04:11

If you can access your library through C++, you can access it through JNI. JNI is pretty easy to do, just read the guide carefully especially section 8.6 where it talks about the differences between C and C++

查看更多
对你真心纯属浪费
3楼-- · 2019-02-25 04:13

You can use JACOB

From the site:

JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java. It uses JNI to make native calls into the COM and Win32 libraries.

Sound like the kind of thing you're looking for.

查看更多
爷的心禁止访问
4楼-- · 2019-02-25 04:23

I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.

查看更多
相关推荐>>
5楼-- · 2019-02-25 04:24

If you have a little bit of money to spend on a commercial product, I recommend that you take a look at Intrinsyc's J-Integra for COM or J-Integra for .NET products. I used their COM product to access a 3rd party ActiveX control (the Bloomberg data access library) from Java code for a project I worked on a few years ago, and it worked very well. They have a reasonable trial / demo policy, and they are quite responsive to support requests.

查看更多
小情绪 Triste *
6楼-- · 2019-02-25 04:32

The direct Java/.NET integration can be done with OOJNI. Google "Object-Oriented JNI for .NET".

查看更多
登录 后发表回答