Call FindExecutable in Java - java

I need to find out which default windows program is executed when opening a text (.txt) file. For this purpose I want to call the FindExecutable function from windows.
How can this be achieved from Java?
I hope I do not have to make a JNI-implementation to call Windows via C for this purpose.

You will have to use JNI. If you don't to code it yourself, you can use JNA - I believe that JNA has moved to GitHub, but the documentation at the previous link is the best I could find. Note that you will be using JNI no matter what (and deploying a native dll), but JNA does make it a lot easier.

Related

How to call a function in a c++ object file from java?

I have existing cpp files from a project which I would like to use it for my application which is in Java. I cannot change the cpp files. How can I call the functions from Java?
I'm working in Windows 10 using JavaFX for my application. I've seen some articles about JNI but none seem to solve my issue.
If JNI or swig is not desired or seems too low level,
A really blunt approach is to wrap the .cpp in c/c++ program and built an .exe that dumps to stdout/file. Then execute that in java via an external shell command.
Another good alternative is
Apache thrift
This basicly handles everything and goes everywhere so to speak (works by auto-generating code to target languages) and it is one I usually recommend in RPC situations. However there could be more setup cost involved (in the end, depends on your actual needs) - also since you need to host the .cpp in a service, in your case, locally.
If you package your library inside a shared object or a dll, you can also use JNA: https://github.com/java-native-access/jna or https://github.com/java-native-access/jna/blob/master/www/GettingStarted.md
For example, you already have mapping to Windows API.
Another example is a mapping of mediainfo in Java: https://github.com/andersonkyle/mediainfo-java-api/blob/master/src/main/java/org/apothem/mediainfo/api/MediaInfo.java
Note that, as far as I understand it, this is based on JNI: it simplify the process since you mostly have to only declare interface on Java side and call appropriate method.

How to get control of Windows of WindowXP using Java

I need to get control over Windows of WindowsXP using Java code,
I need to click/type on particular button/textfield of given window of windowsXP,
How to do this any idea?
Approaches I tried are:
(1) I Tried AutoIT framework, but its Java Wrapper is buggy.. not stable.
(2) JNA can be used for native interfacing, by using some .dll file
to achieve the same. But I don't know which .dll file is used by windowsXP.
Can anybody elaborate on this?
I've not much idea which is much better solution.
Is there any better framework available for such thing.
Thanks.
WindowsXP uses multiple dll files, not one, and studying its API will tell you which one has which functions, and then you can use this information in your JNA interaction code. BTW, I have use AutoIt by itself to help do what you're trying to do and it works fine, and is easier than Java with JNA since it's built for this sort of thing. I've also used AutoIt with Java by having Java call small AutoIt programs and get some simple interaction via standard input and output streams taking care though of the tips and traps in this great article: When Runtime.exec() won't

using functions in dll, in java

I have some dll files(not custom and not written by me) and I need to use the functions, that are c/c++ written, in these files in my java project. I googled and read many examples about JNI but they were all about writing your own program and dll and then reaching them. Also I don't think dllexport exists in these dlls, so dllimport/dllexport method is not available I guess.
How can I reach these functions?
Thanks in advance..
I'm sure, you looked at the JNI Tutorial at oracle already. I had a quick look at the part, where a native function is implemented and a dll is compiled and I don't think, that special conditions have to be met.
I'd give it a try with a single, easy function from that dll:
Write a simple class with just main method that uses one of the native methods (with easy parameters to have an easy start)
Generate the header file and
run the test application
If the dll is not 'jni compliant' (whatever that means), you'll know by then and then you probably know that you have to recompile the native code.

Howto make Java JNI KeyListener with C++

I'm trying to make a program like AutoHotKey, but with a graphical interface.
I'm using java.awt.Robot
Now I want to make the code for checking the state from a key (In AHK: getKeyState)
Of course somthing like a KeyListener without having focus.
I read already something with JNI and C++, but....
I can't find some information.
Can somebody help me??
There are lot of good JNI resources for starting out with JNI Programming like the Sun JNI Tutorial. Almost all Tutorials assume a good knowledge of C/C++ because the Java Native Interface (JNI) is the bridge between native C/C++ code, the Java Virtual Machine and everything running in there (meaning your Java Bytecode).
What you may want to do first is to find a key capturing library for your operating system of choice (you didn't mention anything specific here) in C++ and try that out as well as checking if there are already some Java bindings (libraries that use JNI and offer Java classes) to interact with. I didn't find any promising on a quick search unfortunately.
works perfect for windows 32/64 Bit. It's not necessary to integrate the dll files into the (eclipse)workspace / deployment process. Amazing Lib:
Hot stuff!
http://ksquared.de/blog/2011/07/java-global-system-hook/

issuing hard drive commands with java

Does anyone know of a way to issue commands to a hard drive within Java? Does Java even support this kind of hardware interaction?
For example, if I have a SCSI hard drive that I would like to inquiry, is there a pre-existing Java method to do this, or would I have to write my own?
http://en.wikipedia.org/wiki/SCSI has some general information on SCSI commands in case you aren't familiar.
Java doesn't support talking directly to hardware like that. However, you can use JNI to call a C/C++ function from Java that can.
Three words "JNI or JNA". I strongly recommend taking a look at the latter to see if it suits your situation, instead of just opting for JNI.
No, since Java runs in a "virtual" machine rather than a real one. But it could be used as a bridge as dj mentioned earlier using JNI.
According to Wikipedia JNI can also call assembly directly. JNI could be used to call complete programs written in C or C++
you need to write the HDD interface code in C/C++ and then call that from Java using JNI

Categories

Resources