jna

Using JNA or similar to shutdown and restart computer in linux and mac

狂风中的少年 提交于 2019-12-24 19:25:55
问题 I am trying to write a function in java that will shutdown, force shutdown, restart and force restart the computer and it should work on Windows, Linux and Mac. Windows is not a problem, but I am unable to run commands to shutdown on Linux due to the sudo privileges. I was therefore thinking of using JNA to shut down the computer (i know you can use JNA to do this on windows), but I can't find any examples online for linux or mac. Can anyone help me out? It will be much appreciated! Even if

Invoke WinInet Functions Used Java + JNA

大憨熊 提交于 2019-12-24 15:48:45
问题 sorry for my English. I try invoke WinInet InternetSetOptionW method for setting up IE proxy. InternetSetOptionW returns me "true", but IE proxy doesn't change. What i do wrong? import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.ptr.LongByReference; import com.sun.jna.win32.StdCallLibrary; public interface WinInet extends StdCallLibrary { public WinInet INSTANCE = (WinInet) Native.loadLibrary("Wininet", WinInet.class); public boolean InternetSetOptionW(int unused, int

JNA and Winscard: Reading attributes (SCardGetAttrib) without card

房东的猫 提交于 2019-12-24 14:22:08
问题 I have problems to read out reader attributes (like SCARD_ATTR_VENDOR_IFD_SERIAL_NO), without a card present on the reader though setting the parameter dwShareMode of the function SCardConnect to SCARD_SHARE_DIRECT. What is going wrong? This is the Code: NativeLong res; IntBuffer b = IntBuffer.allocate(1024); NativeLongByReference phContext = new NativeLongByReference(); LongByReference phCard = new LongByReference(); res = Winscard.INSTANCE.SCardEstablishContext(SCARD_SCOPE_USER, null, null,

jna Pointer in 32 bit JRE

笑着哭i 提交于 2019-12-24 13:30:35
问题 I am using jna to call Magnification api functions in Java. MagImageScalingCallback.java package jna.extra; import com.sun.jna.Callback; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.WinDef.HRGN; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.platform.win32.WinDef.RECT; public interface MagImageScalingCallback extends Callback{ public Boolean MagImageScalingCallback(HWND hwnd, Pointer srcdata,MAGIMAGEHEADER srcheader, Pointer destdata,MAGIMAGEHEADER

Pragma Pack used C library causing the jvm to crash

我是研究僧i 提交于 2019-12-24 12:27:50
问题 I used a C library in my Java code using JNA. I have these C structures of whose members I need to print in Java. Because of the memory alignment and padding the size was differing from what I was actually expecting. Therefore I used pragma pack and this is how the structures look like now. #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) PACK( typedef struct { size_t size; uint8_t bytes[48]; } ipj_tid_t); PACK( typedef struct { bool has_epc; //1

NoSuchMethodError using JNA User32 platform map

折月煮酒 提交于 2019-12-24 10:24:58
问题 I received the following error on the first attempt of using the User32.Instance: Exception in thread "main" java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library; at com.sun.jna.platform.win32.User32.(User32.java:48) whilst trying to run a JNA pre-defined mapping of the Windows User32 class functions. I tried running the following code: HWND hwnd = User32.INSTANCE.FindWindow(null,"new 2 - Notepad++"); User32.INSTANCE

Is there any way that I can free up memory in the java code that is generated to bind C code via JNI/JNA?

偶尔善良 提交于 2019-12-24 09:39:39
问题 I am using a java library that use JNA to bind to the original C library (That library is called Leptonica). I encountered a situation where free(data) has to be called in the C code to free up the memory. But, is there any function in java that I can free up the memory? In the C code void ImageData::SetPixInternal(Pix* pix, GenericVector<char>* image_data) { l_uint8* data; size_t size; pixWriteMem(&data, &size, pix, IFF_PNG); pixDestroy(&pix); image_data->init_to_size(size, 0); memcpy(&(

JNA structure mapping with no alignment and padding

一个人想着一个人 提交于 2019-12-24 01:48:14
问题 I have the below structures in JNA. I want to remove the padding and alignment in C using pragma pack. When I run it from C it runs fine. I'm using this DLL to be called from Java. When I call it the JVM is crashing. Would my settings I did in my DLLs apply when its called from Java? I tried adding setAlignment type to None. Still no help. In C this structure is weighing 405. It adds up perfectly meaning there is no padding or alignment. In java when I hover over the _report value while

Concurrency issue while calling a native library via JNA

我是研究僧i 提交于 2019-12-23 17:33:56
问题 For an existing java application (which I do not have the source code) I am developing a plug-in which is calls a shared library. Unfortunately this shared library ( written in C ) is not thread safe. The application is calling my plugin within several concurrent threads hence the shared library is called by these concurrent threads and naturally it gives many errors due to concurrency ( e.g: already open files are prevented from being opened etc) I am accessing the shared library via JNA . I