jna

JNA Invalid memory access when writing to stdout

杀马特。学长 韩版系。学妹 提交于 2019-12-11 12:41:24
问题 I am writing a jna wrapper for a c library, compiled using gcc under cygwin. Depending on how I execute the jna wrapper the java application either just hangs (if executed as unit test under eclipse) or terminates with an Invalid memory exception. The problem seems to occur only the the c library writes something to either stdout or stderr. Here is my minimal (not) working example: add.c #include <stdio.h> int add (int x, int y) { fprintf(stdout, "hello world\n" ); return x + y; } jna wrapper

Non-deterministic return values (string type) from calling native C++ functions through JNA

给你一囗甜甜゛ 提交于 2019-12-11 11:24:25
问题 problem description: My project is JAVA but I want to call a C++ function, which takes a string as input and output another string after process. I apply JNA to do this work, and String and char* are mapping types from JAVA to C++.(During the processing, I need std::string as intermediate type, the simplyfied code is given out in detail.) The program runs well, when the input string is not long. However, when I increase the length of the string(here, I duplicate "test sentence..." for 6 times

How to use unsigned int to be able to use a function for JNA (Java Native Interface)?

天涯浪子 提交于 2019-12-11 09:59:42
问题 I'm using JNA in order to use a C++ library in my Java application. I am using an interface in Java to use these functions. The function uses three arguments in C++: an unsigned int, a const char*, and a long*. JNA implements Strings (according to their documents) in Java to pass in a char*. Likewise, it uses a long[] to pass in a long*. I'm confused, however, about the type that I should pass in for the unsigned int. The char* that is passed in represents the name of the file, and no matter

How to return HWND in JAVA

霸气de小男生 提交于 2019-12-11 09:38:22
问题 The attached code search for a window according to its title and activate it if exist. public static void ActivateWindow() { User32.INSTANCE.EnumWindows(new WNDENUMPROC() { @Override public boolean callback(HWND hWnd, Pointer arg1) { char[] windowText = new char[512]; User32.INSTANCE.GetWindowText(hWnd, windowText, 512); String wText = Native.toString(windowText); String title = "Chrome"; if (wText.contains(title)) { User32.INSTANCE.ShowWindow(hWnd, 9); //activeWindow() User32.INSTANCE

Retrieving item text with JNA and SendMessage()

五迷三道 提交于 2019-12-11 09:29:54
问题 I am attempting to retrieve the item text from a Win32 ListView-like control. I am using JNA and SendMessageW() to send LVM_GETITEMTEXTW to the control. I have been successful at retrieving the item count (via LVM_GETITEMCOUNT) but am stumped at this point. My User32 class is setup like so: public interface MyUser32 extends User32 { MyUser32 INSTANCE = (MyUser32)Native.loadLibrary("user32", MyUser32.class); LRESULT SendMessageW(HWND hWnd, int msg, WPARAM wParam, LVITEM lParam); } My LVITEM

UnsatisfiedLinkError in Processing

强颜欢笑 提交于 2019-12-11 09:24:48
问题 I have recently overcome this problem using eclipse and would like to use the same .dll in the Processing.org environment. Here is my recent post on Stackoverflow. The .dll I want to use is in the C:\Windows\SysWOW64\\ folder, but I am still getting an UnsatisfiedLinkError . I have tried the following solutions with no success: Adding the .dll to the 'code' folder of the sketch Adding C:\\Windows\\SysWOW64\\foo.dll to the Path environment variable Changing the Native.loadLobrary parameter in

How to get a process id of exe running through java program

强颜欢笑 提交于 2019-12-11 08:56:20
问题 I am running a exe through java runtime api Process process = runTime.exec("cmd.exe /c start abc.exe "+Id, null, new File("D:/My")); and retrieving the process id using jna like this - Kernel32.INSTANCE.GetProcessId((Long) f.get(process)); but the process id return is not of abc.exe but of cmd.exe ..... i need the process id of abc.exe . Do not know how to get that can anyone help. 回答1: The process is an object of type java.lang.Process . You can get the process id of abc.exe by using the

(Converting c# to Java JNA) - GetModuleFileName from hwnd

让人想犯罪 __ 提交于 2019-12-11 08:43:24
问题 I am trying to do exactly what is being done over here: How do I GetModuleFileName() if I only have a window handle (hWnd)? But in java instead of C#. So far I have managed to this: public static final int PROCESS_QUERY_INFORMATION = 0x0400; public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); int GetWindowThreadProcessId(HWND hwnd, IntByReference pid); }; public interface Kernel32 extends StdCallLibrary { Kernel32 INSTANCE =

How to launch an interactive process in Windows on Java?

馋奶兔 提交于 2019-12-11 08:07:42
问题 I need to run application in Windows with administrator rights on another user desktop. I could do it with PsExec -i https://docs.microsoft.com/en-us/sysinternals/downloads/psexec but I want to do it in my Java application without additional exe files. I run my code as administrator with elevated rights. I found this article (it describes how to do it on .net): https://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite I translated code from article to Java

JNA initialization of empty node structures

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:42:23
问题 I have node structure (it contain value on next same structure). struct Node { Node *nextElem; Element thisValue; }; I want to pass empty (null) node.ByReference in function that fills it. // C++ Element element = ...; //fills in another function; Node *list = NULL; AddElementToList(element, &list); // which declered as void AddElementToList (Element element, Node * list) {...} // Java Element.ByValue element = ...; //fills great in another function in the same way ByReference (and