jna

How to check if a file is readable?

 ̄綄美尐妖づ 提交于 2019-11-29 02:24:00
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 complicated for me in connection with JNA/JNI. Any ideas how to deal with this problem? Roman C Try to use the

JNA调用DLL函数遇到的几个问题

梦想与她 提交于 2019-11-28 16:34:15
最近一个JSP项目需要用到分词模块,而分词模块实用C++写成的DLL库。于是上网搜各种方法,最后选择了JNA作为JSP调用DLL的工具。 JNA(Java Native Access )提供一组Java工具类用于在运行期动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。开发人员只要在一个java接口中描述目标native library的函数与结构,JNA将自动实现Java接口到native function的映射。 JNA的使用方法有很多,这里只总结下我遇到的问题: DLL放置的路径问题 JSP本身分为bean的src目录和WebRoot的脚本目录,而我们的DLL需要在src下的类中调用,于是遇到了将DLL和资源文件放置到什么地方的问题。 最后解决方法: 将调用的DLL和LIB文件拷贝到C:/Windows/System32目录下 可以访问。 解决过程:我试过将这些文件放到Src目录下,然后用Class.class.getResource("/").getPath()这种方法得到类的class路径,再得到资源文件的路径,结果没有成功。 DLL调用资源的路径问题 DLL可能会调用其他资源文件,比如我这里需要用到词典,路径也是个问题,不过这个较为简单,很容易解决: 将资源文件目录, 拷贝到Src目录下面

Implementing Workstation lock listener using Java

与世无争的帅哥 提交于 2019-11-28 14:01:56
Window get locked when we press WIN_HOME+L key together. We can find lot good example to listen to window lock event in VB. But I am doing window lock listener for Java. I've done some research and made a listener program that listen to window lock event. It has two interface and one main program with JFrame and uses JNA library. WindowUser32.java public interface WindowUser32 extends User32 { public static final WindowUser32 MYINSTANCE = (WindowUser32) Native.loadLibrary("user32", WindowUser32.class, W32APIOptions.UNICODE_OPTIONS); public int SetWindowLong(WinDef.HWND hWnd, int nIndex,

Unable to open the port by calling Native method from ITLSSPProc.dll

余生长醉 提交于 2019-11-28 13:11:22
This is native method from ITLSSPProc.dll NOMANGLE int CCONV OpenSSPComPort (SSP_COMMAND * cmd); Here, SSP_COMMAND is structure in ITLSSPProc.dll which is in C++ Language. struct SSP_COMMAND { unsigned long BaudRate; unsigned char PortNumber; }; So, I have to access OpenSSPComPort (SSP_COMMAND * cmd) in java using JNI. Here is a code i have written, public class Main { public interface ITLSSPProc extends Library { ITLSSPProc INSTANCE = (ITLSSPProc) Native.loadLibrary( (Platform.isWindows() ? "ITLSSPProc" : "simpleDLLWindowsPort"), ITLSSPProc.class); int OpenSSPComPort(Pointer param); int

How to use fingerprint sdk in java? Is there universal sdk for all fingerprint devices?

会有一股神秘感。 提交于 2019-11-28 13:04:15
I`m developing human resources software. I need to check attendence of employees. We have ZKSoftware F702-s fingerprint device. And I need get information from it in java project. I searched for sdk and documentation how to use this sdk but I did not find anything. Help me whith my project. What can I do? I found dynamic libraries of my fingerprint device which activex component and I resolved my problem with JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java. I call functions and handle events from library with Jacob. Here is link to JACOB - Java COM Bridge

JNA: Pass Pointer to Structure to SendMessage function of User32.dll as the LPARAM

一笑奈何 提交于 2019-11-28 12:43:39
问题 I need to perform a simple task : Print out the names of the list view items inside an explorer window. Suppose, I open "C:\Documents and Settings" on my desktop, then what I want to do is that write a java program using JNA to print out all the names of the folders / files within the opened explorer window. What I have been able to do: Get the handle of the opened explorer window and the handle to the listview inside it. What I have found out: I need to call the SendMessage function of

How can I read the window title with JNI or JNA?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 11:27:29
Looking to get back into the development space; primarily using Java to call some native win32 functions (I don't desire to build in .NET).... Can someone point me to a place where I can read the title from a differnt running window using Java (JNI/JNA/SWIG). Assume you would know where in the memory space the application you are attempting to hook into is. In JNA: public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount); } To use it: byte[] windowText = new byte

JNA Event Log Reader

懵懂的女人 提交于 2019-11-28 10:33:30
I am using the below code to read through the Windows Application Event Log using JNA. I want to be able to specify which event to start at instead of always starting with the first event. Does anyone have any suggestions? import java.io.IOException; import com.sun.jna.*; import com.sun.jna.platform.win32.*; import com.sun.jna.platform.win32.WinNT.*; import com.sun.jna.ptr.IntByReference; public class test { public static void main(String[] args) throws NumberFormatException, IOException { HANDLE h = Advapi32.INSTANCE.OpenEventLog("ServerName", "Application"); IntByReference pnBytesRead = new

Using JNA to get GetForegroundWindow();

有些话、适合烂在心里 提交于 2019-11-28 10:05:17
I asked a similar question on a previous thread ( https://stackoverflow.com/questions/5206633/java-find-out-what-application-window-is-in-focus) but I was guided to use JNI, and I'm not having much success with it... I've read some tutorials and while some work fine, others don't I still can't get the information I need, which is the title of the window on the foreground. Now I'm looking into JNA but I can't figure out how to access GetForegroundWindow() ... I think I can print the text once I get the handle to the window using this code (found on another thread): import com.sun.jna.*; import

JNA UnsatisfiedLinkError - works when I set java.library.path to a bogus value

谁说我不能喝 提交于 2019-11-28 08:12:49
问题 Using JNA 4.0.0, on Linux, I am trying to load a native library ( libmean.so ), which is in the lib subdirectory (the library is just a trivial example that calculates the mean of two numbers). I run the following code (within Eclipse), with -Djna.library.path=lib set in the run configuration. import com.sun.jna.Library; import com.sun.jna.Native; public class Mean { public interface MeanLib extends Library { MeanLib INSTANCE = (MeanLib) Native.loadLibrary("mean", MeanLib.class); double mean