将现有的 c# 移植到 java(大量 pinvoke/user32.dll) - 陷阱?
正如所述,我们正在考虑移植一个广泛使用 user32.dll
的现有应用程序。主要用于屏幕截图和移动鼠标之类的事情。
使用 JNA 之类的东西我们应该能够做同样的事情,但是有限制吗?我们应该注意的事情
谢谢
As states we are in the process of considering porting an existing app which uses the user32.dll
quite extensively. Mainly for stuff like taking screenshots of the screen and moving the mouse around.
Using something like JNA we should be able to do the same thing, but are there limitations? Things we should be aware of
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先我必须问为什么?如果您使用 JNA,无论如何您都会失去 Java 的所有跨平台特性,并且失去 C# 为您提供的与 Windows 的紧密集成。没有任何限制可以阻止您这样做,但如果您只是将自己束缚于使用本机代码,那么我会说没有多大意义。
另一方面,如果您希望获得跨平台功能并且正在考虑移植,那么您可以使用 Java Robot 类很容易,不需要本机代码。如果您用 Java 重写,这是我目前推荐的方法。
As a first point I'd have to ask why? If you're using JNA you're losing all the cross platform nature of Java anyway, and losing the tight integration with Windows that C# gives you. There's no limitations that'd stop you doing it, but if you are just tying yourself to using native code anyway then I'd say there's not much point.
If on the other hand you're looking to gain cross platform capability and you're looking at porting, then you can take screenshots and move the mouse around using the Java Robot class easily, no native code required. If you are rewriting in Java, that's by far the approach I'd recommend.