jna

JNA调用c#的DLL

隐身守侯 提交于 2020-02-26 12:53:44
1:C#中代码:因为我的JDK是64位,所以vs2013中release也要用x64编译 namespace cSharpDLLforJNA { public class Main { public struct user { public int id; public string name; public int age; } public void sayuser(user user) { Console.WriteLine(user.name + ":id=" + user.id + " age=" + user.age); } } } 2:JnaDemo.java中 public class User extends Structure { public class ByReference extends User implements Structure.ByReference{} public class ByValue extends User implements Structure.ByValue{} public int id; public String name; public int age; } public interface CSharpDLLforJNA extends Library{ //总是出现找不到dll库文件异常,参考https:/

java语言下利用tess4j开源库进行图片中的文本提取

大城市里の小女人 提交于 2020-02-26 05:06:15
后来发现了一个帖子:# Java OCR tesseract 图像智能字符识别技术 Java代码实现 一,tess4j 简单介绍 Tess4J是对tesseract -OCR API.的Java JNA 封装,使java能够通过调用Tess4J的API来使用tesseract -OCR 我有一篇博客也介绍了tesseract -OCR如何使用tesseract -OCR进行图片识别 java代码实现DOS命令使用tesseract -OCR开源引擎实现图片文字识别 二,tess4j环境准备 官网下载tess4j的jar包 https://sourceforge.net/projects/tess4j 解压之后目录结构如下,tess4j的iar包在dist目录里面 如果要进行中文字符识别,需要下载中文字库,可自行百度,我也提供了百度网盘链接 https://pan.baidu.com/s/1dmpqQ8Cm7Cd5zaLC0ZOZaw 三,Eclipse IDE下的代码实现 新建一个java项目 2.导入tess4j的dist文件夹下的tess4j jar包和lib文件夹下的全部jar包,注意,lib下有一个后缀为.properties的文件别导进去了,把那个删除掉就行,你或许会问会用到那么多jar包吗,因为jar包可能依赖于其他iar包,所以最好全导入进去,我遇到过一个错误

jna调用以C内存异常

泪湿孤枕 提交于 2020-02-26 01:27:43
以下是手动释放内存的例子。 public String getHostName() throws LibvirtException { PointerByReference p = new PointerByReference(); Native.free(Pointer.nativeValue(p.getValue()));//手动释放内存 Pointer.nativeValue(p, 0);//避免Memory对象被GC时重复执行Nativ.free()方法 } 来源: oschina 链接: https://my.oschina.net/u/2963604/blog/3167216

JavaFX Minimizing & Maximing undecorated stage with animations

故事扮演 提交于 2020-02-20 04:50:06
问题 I am using the accepted answer in this question: JavaFX Minimizing Undecorated Stage to minimize my app properly. However, unfortunately the default Windows minimize & maximize animations are not shown at all (the window just appears and disappears). I know it is possible to make the animations display with undecorated windows, since I have one application that has this behavior (PotPlayer). How could I make the animations appear with JNA? EDIT: Here's a working Kotlin code piece to minimize

How to I access the data of a WMI Query (via JNA) SAFEARRAY result

五迷三道 提交于 2020-02-05 05:39:07
问题 I use jna to run WMI queries. The following code queries WMI SELECT Caption,Capabilities from Win32_DiskDrive . The Type of Win32_DiskDrive.Capabilities is uint16[] and result.getValue returns a SAFEARRAY Instance. System.out.println("Var Type(3 expected): " + value.getVarType().intValue()); returns randomly 0 or 3 if I start the process several times. System.out.println("Size (>0 expected): " + (value.getUBound(0) - value.getLBound(0))); is correct, but Object el = value.getElement(0); fails

Maximize process from java from taskbar

有些话、适合烂在心里 提交于 2020-02-01 05:31:29
问题 If I have a process minimized in my taskbar, is there any way to maximize it from java? I know the name of the process, but would it be possible? 回答1: Your best bet is probably using the Windows API. I've used Java Native Access before for tasks like this. I've found the library very handy. With JNA, what you do is you declare an interface with the exported functions of a shared library (DLL), then load the library which gets you proxy to that library. The WinAPI functions we're interested in

jna调用c编写的dll

故事扮演 提交于 2020-02-01 00:26:09
我们团队目前开发的产品是用java语言编写的,大家都知道,java编写的代码随便都可以被反编译,导致别人可能会看到你“裸奔”的样子。所以,为了避免这种安全隐患,团队最终商定,将部分核心代码改用c语言编写,封装为dll,再由java调用。 于是乎,我们就开始jna初探。今天通过各种百度,终于做了个例子出来,在此做个记录,以备后路之需。 1、构造一个dll 由于本机的vs2015没有安装c++模块,所以采用Dev-C++开发,具体步骤如下: 1.1、新建项目,选择DLL,C项目 1.2、删除自动生成的代码文件,编写一个简单的函数 1.3、编译项目,生成dll 2、通过jna调用dll 2.1、在java项目中加入jna依赖 <dependency> <groupId>com.sun.jna</groupId> <artifactId>jna</artifactId> <version>3.0.9</version> </dependency> 2.2、编写调用类 public class DllTest { public interface CLibrary extends Library { CLibrary INSTANCE = (CLibrary) Native.loadLibrary("cDll2", CLibrary.class); String hello(); }

JNA简单使用

可紊 提交于 2020-02-01 00:17:05
近期使用Java开发有关于摄像机接收到数据的上传,因为摄像机处理图像是用C语言实现的,所以开发需要用到JNA,实现JAVA对C语言的回调,因为具体的开发方式官方文档里面有示例,所以本文只是简单的把需要注意的点罗列出来。 一、 定义 JNA提供一些JAVA工具类,在运行期间访问本地库,如dll/so。 二、 数据类型对照表 官方提供的数据参考表完全够用,当使用数据参考时候,注意参考头文件宏定义。 1、常见数据类型对照 Java 类型 C 类型 原生表现 boolean int 32位整数 (可定制) byte char 8位整数 char wchar_t 平台依赖 short short 16位整数 int int 32位整数 long long long, __int64 64位整数 float float 32位浮点数 double double 64位浮点数 Buffer/ [Pointer] pointer 平台依赖(32或 64位指针) [] (基本类型的数组) Pointer/array 32或 64位指针(参数/返回值) 其他常用: Java 类型 C 类型 原生表现 String char* /0结束的数组 (native encoding or jna.encoding) WString wchar_t* /0结束的数组(unicode) String[] char

【翻译】JNA调用DLL

冷暖自知 提交于 2020-01-31 22:24:32
一、前言   Jna调用的示范,基本包括了Java->C基本类型的转换,指针的转换等。    不过文章是2011年的,可能后面要查看下有什么改变。 二、原文 http://www.viaboxxsystems.de/java-interoperation-with-a-native-dll-using-jna 推荐实例阅读: http://www.eshayne.com/jnaex/index.html 三、翻译 大体翻译。 从Java调用dll,你可以选择JNI和JNA。(还有其他了.......) 关于调用转换 首先定义接口,接口继承“ “com.sun.jna.Library” 或者 “com.sun.jna.win32.StdCallLibrary”. ”。   View Code   Java中调用如下:    View Code       基本数据转换   上述方法中,“returnDllVersion”方法返回一个char *(C语言),JNA框架将char *转换为Java String(Unicode)。JNA提供了大部分的JAVA/C数据类型的转换,可参见 “ Mapping between Java and Native “. 注:此段后为自己加的内容,可能有误。   由于我在数据转换时涉及到了很多unsigned,signed的问题,之前基础也不好

Sending Keystrokes to Hidden Window via JNA

我与影子孤独终老i 提交于 2020-01-25 10:03:27
问题 Background: I'm sending keystrokes to a program (Text Editor) that I hide and then Send the F7 Key and after that four keys of text (kind of a password). I'm using JNA Library and the SendMessage function of Win32API to send the messages, can't use sendInput() because I need to send to a specific window handle. Code: private static void sendInputToWindow(WinDef.HWND editorWindowHandle, char[] password) throws InterruptedException { User32.INSTANCE.ShowWindow(editorWindowHandle, WinUser.SW