jna

C callback with JNA makes JRE crash

大城市里の小女人 提交于 2019-11-29 19:21:22
问题 I'm having problems handling callbacks in JNA. I'm trying to use a C API that uses callbacks to handle several session events (logged in, logged out, connection problem...). The session object (called sp_session ) is an opaque struct. All the callbacks are registered in a sp_session_callbacks structure. According to the API, I am supposed to declare the callbacks object, and put it into a Config object that I will provide when creating the sp_session object. If I don't want to use certain

“global” KeyListener using JNA

自作多情 提交于 2019-11-29 16:28:32
I have in plan making of program in Java running under Windows that can map diffenrent "macros" on different keys runnig at background. Problem is - how to make Java listen to keys pressed when the application is not being focused. I have found lot of opinions that this is not possible. But I have also found this written by Stefano here on SO. This solution is, well, not good enough for me, at least there is not one impotant information. The function MsgWaitForMultipleObjects() returns one value if the key is not pressed...that's ok. After key press, it returns different value...that would be

JNA工作笔记一

允我心安 提交于 2019-11-29 16:21:51
JNA是什么? JNA(Java Native Access )提供一组Java工具类用于在运行期动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。开发人员只要在一个 java接口 中描述目标native library的函数与结构,JNA将自动实现Java接口到native function的映射。 说直白点就是能让你调用底层的dll类库,诸如(C++,C,VC++)写的dll类库。具体详细的帮助文档大家也可以参考JNA的托管地址:https://github.com/java-native-access/jna JNA的简单例子: C代码大致定义: 接下来,我们新建一个maven项目,加入jna的依赖: <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>4.2.1</version> </dependency> 接下来,我们要定义和C一样的数据结构体,函数,首先先看一下官方给的对应的数据类型: 这是JNA官方给出的一份,C类型映射成java类型的一个列表。我们首先将test.dll放入maven项目的resouces目录下面,接着定义一个C里面的结构体映射成java的结构体代码: /** *

JNA, Java Native开发利器

痞子三分冷 提交于 2019-11-29 16:21:43
下面的文章由转载而来,java与c++的调用 基本思路是这样子,但是结合我的使用经验,在使用jna和jnative的时候需要考虑到jdk的版本,jnative跟jdk1.4的结合可能会有点问题,因为我之前选的是jnative,而我们的jdk版本是1.4,我们下载的jnative jar不支持1.4版本,这样才换了jna,庆幸jna支持jdk1.4,特作此说明。 -------------------------------------------------------------------------------------------------- 简单的来说,这篇文章就是介绍一个十分好用的Java Native开发工具, JNA。 在Java编程中,大部分时间都不需要理会JNI,但是当你需要调用一个本地的C/C++库的时候,你就不得不考虑如果在Java中调用C库中的接口(dll, so)。这样的情况有很多,比如当你需要访问一个硬件时,而硬件厂商只提供C语言写的驱动和库文件。 刚开始,或许像我一样,大部分人知道Java有一个叫JNI的东西可以做到这一点,还不坏不是么,至少可以实现它。但是JNI的编写相当复杂和拙劣,关键的一点是需要编写C代码,要知道这对于相当一部分Java程序员来说可不是一个容易的事情。除了你要精通C语言,还要熟悉JNI的知识

Converting String to Pointer for JNA

那年仲夏 提交于 2019-11-29 14:24:39
I'm trying to use JNA to query the effective permissions for a file in Windows. Eventually, I plan on using the GetEffectiveRightsFromAcl function , but to do so, I need to provide a pointer to a populated TRUSTEE structure . The JNA Platform (platform.jar) doesn't appear define this struct, so I'm trying to define it myself instead. Here's what I have so far: public static class TRUSTEE extends Structure { public TRUSTEE() { super(); } public TRUSTEE(Pointer p) { super(p); read(); } public Pointer pMultipleTrustee; public int MultipleTrusteeOperation; public int TrusteeForm; public int

How can i get a printer's make and model in Java?

爷,独闯天下 提交于 2019-11-29 13:22:22
I'm actually working on a Java application that shares printers to a server, and I need this application to get the make and model of the printers it shares. I know this question has been asked three or four times but nobody seems to have found an answer. I've tried this code : PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService printer : printServices){ System.out.println(printer.getDefaultAttributeValue(PrinterMakeAndModel.class)); System.out.println(printer.getAttribute(PrinterURI.class)); } the first print always returns a null string and

Porting C library to Java for Blackberry application

社会主义新天地 提交于 2019-11-29 11:54:39
I need to port a C library to Java so it can run on the Blackberry platform (mobile, native application). The options I am considering are: bytecode conversion (cibyl, etc) Complete port Wrap C code around Java using JNA (would this even work for Blackberry?) Please let me know which option is best. thanks Aha. Some quick googling says "No, JNI does not work for blackberry" source: http://supportforums.blackberry.com/t5/Java-Development/Can-we-use-JNI-Java-Native-Interface-approach-in-Blackberry/m-p/365362 http://supportforums.blackberry.com/t5/Java-Development/JNI/m-p/41140 . So you're stuck

renaming DLL functions in JNA using StdCallFunctionMapper

半世苍凉 提交于 2019-11-29 10:23:24
问题 I'm trying to use JNA with a DLL in Windows, so far I was able to successfully call a function called c_aa_find_devices() . But all the functions start with c_aa and I would like to rename it to find_devices() . From what I gather the way to do this is with StdCallFunctionMapper but I can't find the documentation of how to use it in an example (i.e. how to map a DLL function by name or by ordinal to a desired name in the wrapped Java library interface). Any suggestions on where the docs are?

How can I get the window handle (hWnd) for a Stage in JavaFX?

浪子不回头ぞ 提交于 2019-11-29 05:06:12
We're building a JavaFX application in Windows, and we want to be able to do some things to manipulate how our application appears in the Windows 7/8 taskbar. This requires modifying a Windows variable called the " Application User Model ID ". We've already managed to do exactly what we want in Swing by using JNA , and we'd like to repeat our solution in JavaFX. Unfortunately, to do this, we need to be able to retrieve the hWnd (window handle) for each window in our application. This can be done in Swing/AWT via the JNA Native.getWindowPointer() method, which works with java.awt.Window , but I

How to map enum in JNA

怎甘沉沦 提交于 2019-11-29 04:13:12
I have the following enum how do i map in jna ?? This enum is further referenced in structure. typedef enum { eFtUsbDeviceNotShared, eFtUsbDeviceSharedActive, eFtUsbDeviceSharedNotActive, eFtUsbDeviceSharedNotPlugged, eFtUsbDeviceSharedProblem } eFtUsbDeviceStatus; Abdul Khaliq If you're using JNA you probably want to explicitly specify the values of the enumeration in Java. By default, Java's basic enum type doesn't really give you that functionality, you have to add a constructor for an EnumSet (see this and this ). A simple way to encode C enumerations is to use public static final const