jna

Function scanf with JNA

半世苍凉 提交于 2019-12-08 14:08:54
问题 I'm trying to use the scanf function with JNA: package importDLLs; import com.sun.jna.Library; import com.sun.jna.Native; public class JNATest { public interface CLibrary extends Library { CLibrary clib = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class); void printf(String format, Object... args); int sprintf(byte[] speicher, String format, Object...args); int scanf (String format, Object... args1); } public static void main(String[] args) { CLibrary.clib.printf("Hello World"); String

Use JNA to get Local machine Certificate

时光怂恿深爱的人放手 提交于 2019-12-08 09:23:38
问题 I'm trying to get a certificate from local machine Windows store. What a want to get is a certificate in the patth "Certificates(Local Computer) --> Personal --> Certificates". I used this code to access certificate in the path "Certificates - Current User --> Personal --> Certificates NativeLibrary crypt32 = NativeLibrary.getInstance("Crypt32"); Function functionCertOpenSystemStore = crypt32.getFunction("CertOpenSystemStoreA"); Object[] argsCertOpenSystemStore = new Object[] { 0, "MY"};

Turn a Callback into a Pointer in JNA

时光总嘲笑我的痴心妄想 提交于 2019-12-08 08:03:35
问题 I must be missing something. Given an instance of a class that implements com.sun.jna.Callback , how do I get a function pointer address as a Pointer , so that I can pass it to a function that takes a void* parameter (I’m using Pointer ). Specifically, I want to create a CFNumber (aka NSNumber* ) using CFNumberCreate(Pointer, int, Pointer) with the address of the function, so that I can call SetSpeechProperty to register a SpeechDoneProcPtr. 回答1: You don't. You pass the callback instance and

Why does my call to winapi GetWindowPlacement fail (using JNA)?

限于喜欢 提交于 2019-12-08 07:24:33
问题 These are the winapi methods BOOL WINAPI SetWindowPlacement( _In_ HWND hWnd, _In_ const WINDOWPLACEMENT *lpwndpl ); typedef struct tagWINDOWPLACEMENT { UINT length; UINT flags; UINT showCmd; POINT ptMinPosition; POINT ptMaxPosition; RECT rcNormalPosition; } WINDOWPLACEMENT, *PWINDOWPLACEMENT, *LPWINDOWPLACEMENT; My Java code:- class WINDOWPLACEMENT{ public int length; public int flags; public int showCmd; public POINT ptMinPosition; public POINT ptMaxPosition; public RECT rcNormalPosition; }

Finding exposed methods in native libraries to access over JNA / JNI?

老子叫甜甜 提交于 2019-12-08 05:52:20
问题 Hi : I wanted to use JNA to access some functions in a native library. 1) How can i introspect the native library files (.so files, for example) to see what methods are available ? 2) Is there a one-one mapping between the methods accessible in .so files and the C code built to compile those files? 3) Is JNA gauranteed to work in all cases where the only java/native interop involves calling native libraries from Java (I assume this is the classic use case for JNA) -- or is JNI sometimes

Mapping const char** to Java type with JNA

泪湿孤枕 提交于 2019-12-08 05:27:10
问题 I am trying to use a C++ library in Java with JNA. In the header file of the library I have the following method declaration: extern "C" void foo(const char** bar); The paramterer bar should be passed to foo empty, and foo vill assign it a value that I want to retreive in Java. How should the corresponding Java method declaration be set up (e.g. what Java type should I map bar to), and how can I use it? I have tried the following Java declarations: void foo(String bar); void foo(String[] bar)

C struct to Java JNA Structure (pointer to struct)

浪尽此生 提交于 2019-12-08 04:50:34
问题 I have problem with JNA Structure based on C/C++ struct. Fields nScreenIndex, uVendorID, uProductID, uVersionNumber looks OK, but after them I see odd bytes. My main and only goal is to "extract" pMonitor fields. Are pMonitor declaration and MONITOR implementation correct? C/C++ origin: SCREEN* EloGetScreenByIndex (int nScreenIndex); typedef struct SCREEN_TAG { int nScreenIndex; USHORT uVendorID; USHORT uProductID; USHORT uVersionNumber; wchar_t szDevicePath [MAX_PATH]; HANDLE hCalTouchThread

Invalid memory access of location with Rococoa

对着背影说爱祢 提交于 2019-12-08 03:56:10
问题 I've been trying to code a simple screenshot application using rococoa (java to osx cocoa api library), and managed to get as far as actually taking the screenshot, and then saving it to a file. Unfortunately, once in a while, the application fails with an 'Invalid memory access of location...' error. I'm assuming this is due to something being garbage collected, because I'm failing to keep a reference alive. The line that is causing the crash is: int[] data = pointer.getIntArray(0,

JNA in Windows: auto terminate child processes using Windows Jobs

北战南征 提交于 2019-12-07 23:20:25
问题 I need to launch a child process in my java application in Windows, and eventually my java app can be killed/terminated via task manager. So I need to "link" this child process with the parent process, to both be terminated if the parent process terminate. In windows API we have the CreateJobObject and also the: SetInformationJobObject JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure JOBOBJECT_BASIC_LIMIT_INFORMATION structure And the LimitFlag JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE Based on the

Java JNA sendMessage() not found

[亡魂溺海] 提交于 2019-12-07 18:10:39
问题 I'm trying to use JNA (Overview) to send messages to an application when minimized or not on top (mouse click for example), and the I found that people are using com.sun.jna.platform.win32.User32.SendMessageA( hW, 0x0201, 0, 0); But i can't found this function in this class. Can someone give me an example of how to implement it if I'm doing it wrong? CODE: User32 user32; Pointer hW = user32.GetForegroundWindow().getPointer(); user32.SendMessageA( hW, 0x0201, 0, 0 ); 回答1: public interface