0

let's suppose that I have created and added a new entry to the Windows explorer right-click menu (context menu) by adding a registry entry that points to a .exe written in C++ that just reads and returns the filename of the clicked file.

Is it possible to get this filename to an already running Java app?

I thought of using JNI but is it possible to call a method of an already running Java app from a native C++ program?

Does anybody have another idea how to solve this? Is it possible to have a pure Java solution?

Many thanks.

Edit: Is it possible to call an existing method of an already running JVM? Then I could create a C++ program that listen for right-clicks and register that .exe with a registry entry for the contextmenu. Inside the C++ program, I could call a dll that injects into an already running JVM. The dll could call a Java method and commits the clicked filepath to Java. Would that be a possibility?

user3422749
  • 62
  • 1
  • 9
  • Ok, I've achieved the following: I've created a C++ program that is linked with a regsitry entry (contextmenu / right-click menu). If a user clicks a file, the filepath is transfered (command line arguments) to the program. Inside the program, a dll is loaded and the filepath is tranferred to a defined method inside the dll that just prints the filepath. What I would like to achieve now is to call a method of an already running Java program (inside the dll) and transfer the filepath to the Java method instead of printing it. Do you have any advice? Thanks. – user3422749 Apr 10 '14 at 17:50

1 Answers1

1

You could connect to an already running Java program through a socket connection, or store values to a database of some kind that both your C++ application and Java application can access.

Besides my suggestions, here's a stackoverflow post that talks about communicating to a Java program already running without the Java program making the initial communication.

Community
  • 1
  • 1
NESPowerGlove
  • 5,496
  • 17
  • 28
  • Hi, thanks for the response. It is a local Java program therefore I think that a socket connection is not the best possibility to solve that. Isn't there another way to detect a right-click on a file and get the clicked filename to Java (Windows 7 64bit)? Is the injection method the only possibility? – user3422749 Apr 09 '14 at 18:16
  • Sorry I don't know. I don't know the API's Microsoft made available for Windows Explorer but I'd imagine that any solution has to start in native code, even a Java solution would technically have part of the solution still using JNI or some other native code means I would think. – NESPowerGlove Apr 09 '14 at 18:30