jna

Java - Windows taskbar using JNA - How do I convert window icons (HICON) to java images?

 ̄綄美尐妖づ 提交于 2019-12-04 12:22:42
I'm trying to add an application-switcher to a bigger project I'm working on. It needs to work on Windows XP/Vista/7/8. I'm using Java 1.7. Below is a sample application I created to demonstrate some of the problems I'm having. I'm very new to JNA. Thanks very much to 'Hovercraft Full of Eels' for this answer (and many others!) which forms the basis for the test application. Here are my questions: Image drawing - The images that I get from the window icons are being drawn in black and white. I modified the code in getImageForWindow from this answer by McDowell (Thanks!). Is there a better way

JNA中级篇 回调函数详解

萝らか妹 提交于 2019-12-04 11:13:06
JNI 技术是双向的,既可以从Java 代码中调用原生函数,也可以从原生函数中直接创建 Java 虚拟机,并调用Java 代码。但是在原生函数中调用java代码要写大量C代码,这对大多数java程序员来说是很头疼的。 使用JNA,我们不用编写C代码就能在原生代码中调用java代码。JNA 可以模拟函数指针,通过函数指针,就可以实现在原生代码中调用Java 函数。 下面直接用代码进行说明: 原生代码定义: //方法定义 LONG StartListenServer(const Alarm_Listen_Param *param); //Alarm_Listen_Param结构体 struct{ IpAddress struIPAdress; MessageCallBack fnMsgCb; void *pUserData; BYTE byProtocolType; BYTE byRes[31]; }Alarm_Listen_Param, *Alarm_Listen_Param; //ip结构体 struct{ char szIP[128]; WORD wPort; BYTE byRes[2]; }IpAddress, *IpAddress; //回调函数声明 typedef BOOL (CALLBACK *MessageCallBack)( LONG iHandle,

problem using JNA and EnumWindows

半腔热情 提交于 2019-12-04 09:48:21
I'm experimenting with JNA, and this is the first program I try to run. I copied it from the reference, but, when i run it, he finds 412 windows ... and I'm quite sure I've not that many window opened right now :) Can please someone explain me the behaviour of the program? import com.sun.jna.Pointer; import com.sun.jna.win32.StdCallLibrary.StdCallCallback; import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary; public class Main { // Equivalent JNA mappings public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);

java JNA - find partial window title

♀尐吖头ヾ 提交于 2019-12-04 05:20:22
问题 I want to get a window by its title and then activate it. The problem is that the FoundWindow method searches on the all title. I would like to get a window by its partial title. import com.sun.jna.platform.win32.User32; import com.sun.jna.platform.win32.WinDef.HWND; public class IsRunning { public static void main(String[] args) { HWND hwnd = User32.INSTANCE.FindWindow (null, "Untitled - Notepad"); // window title if (hwnd == null) { System.out.println("Notepad window is not running"); }

Java: load shared libraries with dependencies

偶尔善良 提交于 2019-12-04 04:05:51
I am wrapping a shared library (written in C) with Java using JNA. The shared library is written internally, but that library uses functions from another external library, which again depends another external library. So the situation is something like this: ext1 <- ext2 <- internal I.e. the internal uses external library ext2 which again uses external library ext1. What I have tried is: System.loadLibrary("ext1"); System.loadLibrary("ext2"); NativeLIbrary.loadLibrary("internal",xxx.class); This approach fails with "UnresolvedException" when loading the library "ext2"; the linker complains

Determine whether a file is a junction (in Windows) or not?

China☆狼群 提交于 2019-12-04 01:39:20
I've been searching around trying to find a way to determine if a file is a junction or not, and have not found any satisfactory answers. First thing I tried was: Files.isSymbolicLink(aPath) It detects only symbolic links not the files referred to as junctions in Windows. Also tried the solution proposed here (using JNA library): Stackoverflow question (3249117) , but it never returned true on any of the files I know to be junctions. The only way I've found to determine which files are junctions is the following command run in windows command prompt: DIR /S /A:L On my computer it returns 66

Getting JNA to work with Java => C#?

情到浓时终转凉″ 提交于 2019-12-03 18:08:13
问题 I've written a lot of code in a C# library, which I now need to call from Java. I saw it recommended on SO to use JNA, but I'm having trouble even getting out of the starting blocks; the documentation there is very sketchy. Firstly, it only appears to show you how to connect to the Native C library, which is no good to me; I want to connect to my own library. The code sample there shows: // This is the standard, stable way of mapping, which supports extensive // customization and mapping of

How to check if a file is readable?

大兔子大兔子 提交于 2019-12-03 17:59:59
问题 I'm writing Java 6 application and I have to check if a file is readable. However, on Windows canRead() always returns true . So I see that probably, the only solution could be some native solution based on WINAPI and written in JNA/JNI. But, there is another problem, because it's difficult to find a simple function in WINAPI which would return information about access to a file. I found GetNamedSecurityInfo or GetSecurityInfo but I'm not an advanced WINAPI programmer and they are too

JNI vs. JNA performance

*爱你&永不变心* 提交于 2019-12-03 10:37:29
问题 We have a native c/asm application utilizing GPU(OpenCL) for a big encrypt/decrypt data with a specific method, and it just works perfect, no problem. A part of the project (web and distribution) is been developing by JEE , and we just need to call native application/library. We have tried to call it as a separated-external process using Process class. The problem is that we cannot control the application(event, handlers, threads, etc...). We also tried to just switch the C code into Java

JNA:com.sun.jna.platform.win32.Win32Exception- access denied

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use following code to control a windows service from java program public class PostgresService2 { public static void main(String[] args) { try { W32ServiceManager serviceManager = new W32ServiceManager(); serviceManager.open(Winsvc.SERVICE_STOP); W32Service service = serviceManager.openService("DBService", Winsvc.SERVICE_ACCEPT_STOP); service.stopService(); service.close(); } catch (Exception ex) { ex.printStackTrace(); } } } This gives error on windows7 (64bit) machine com.sun.jna.platform.win32.Win32Exception: Access is denied. at com