Suso
Suso

Reputation: 41

Is there a way to read a value from a Java process using C++?

I'm working on a C++ application that needs to get some info from a Java process.

I'm already using pointers to get data from the memory of a certain module that doesn't run on java. I figured out this wasn't possible with java because of the way it switches memory addresses around, so I was wondering if I could do something similar to get the value of a java variable.

I can access the source code of the java application, but my code should be able to get values from the original one.

Everything I've done so far is based on a 64bit windows console application.

Upvotes: 4

Views: 361

Answers (2)

mrjoltcola
mrjoltcola

Reputation: 20842

Traditionally any interaction between C/C++ and Java makes me look to JNI. Java JNI has options for integration in either direction, depending if you can modify code or not.

If you can't modify the Java app, but you can invoke Java app in order to create the process, then you may consider the invocation API to embed a JVM into your C++ app. Once you do that, you can use the API to access various things in the Java app.

A good example already exists: https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/invocation.html

Upvotes: 2

Steen Machine
Steen Machine

Reputation: 46

I don't know how to share random access memory across applications, however file I/O would probably work just fine. There are good tutorials for file I/O in both of those languages if you haven't done it before.

Write to the file in java: https://www.tutorialspoint.com/java/java_files_io

Read from the file in C++: http://www.cplusplus.com/doc/tutorial/files/

Upvotes: 3

Related Questions