vb调用 java函数,从Java调用VB.NET函数的最佳方法?

一名软件实习生面临将Java与C# DLL交互的任务,探讨了Java Native Access (JNA)和UnmanagedExports作为解决方案。文章讲述了各自优缺点,强调了避免使用复杂中间层的重要性,以及JNA的C#和VB.NET支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm interning as a software developer for a company. There is a client-installed software program written in C# that has dll's in VB - both on the .NET framework. Our entire cloud-based server is written in Java, so for now, my task is simply to call a function in Java that gets/sets a private(? sorry, not really familiar with VB so I might be using this term inappropriately) variable located within the dll. Ultimately, though, my task will be to collect data from the client program and put it in our server. I've been researching how to go about doing this for the past few days and have found a few options:

Java Native Access (JNA)

Java Native Interface (JNI)

COM/ActiveX bridges (though I can't entirely say for sure that I know what these are/how to use them_

JNBridge

Now as far as I know, these are the issues I've found with each, respectively:

Using this option requires an intermediary from Java to .NET using either C or C++, and given that I only really know Java, I'd not really like to get tangled in this mess.

Seems a tad bit more complicated than JNA, and I think it has no real advantages over JNA anyways. They both appear to have the need of a C/C++ intermediary.

... can't really say much aside from the fact that I'm not really sure how I can go about implementing this method.

This and other similar bridges has to be a last resort. The developer license for this product is quite pricey, and I'm sure they we don't have the resource to use this product. I could try asking, but I don't really think it's in the place of an intern to ask that a company invest so much.

To add to the fact that I'm not really that adept in programming, I've been left to mostly do this on my own so thanks so much in advance for reading my question. If there's something I haven't fully explained that necessitates further explanation, please let me know! Any other tips/pointers would be immensely appreciated.

解决方案

I can recommand JNA together with UnmanagedExports since it requires only C#, VB.NET or F# .dll with the following Header

C#:

[RGiesecke.DllExport.DllExport]

public static String yourFunction(String yourParameter)

{

return "CSharp String";

}

after that you can consume it with JNA like any other C or C++ .dll in Java. You can find an example and some restrictions I couldn't come around in my answer at this similar question: Call DLL from Java using JNA

I only tried it with C#, but as stated in the docu it should work with C#, F# and VB.NET.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值