「簡単」のJNIが見つからない場合は、IPC(プロセス間通信)メカニズムが必要です。だからあなたのC + +のプロセスからあなたのJavaと通信することができます。
コンソールリダイレクトで何をしているのかは、IPCの一種であり、本質的にはどのようなIPCですか。
あなたが送信しているものの性質は、あなたに良い答えを与えることは非常に難しいものではありません。しかし、簡単なプロトコルに簡単にシリアル化できる「シンプルな」オブジェクトまたは「コマンド」がある場合は、protocol buffers
などの通信プロトコルを使用できます。
#include <iostream>
#include <boost/interprocess/file_mapping.hpp>
// Create an IPC enabled file
const int FileSize = 1000;
std::filebuf fbuf;
fbuf.open("cpp.out", std::ios_base::in | std::ios_base::out
| std::ios_base::trunc | std::ios_base::binary);
// Set the size
fbuf.pubseekoff(FileSize-1, std::ios_base::beg);
fbuf.sputc(0);
// use boost IPC to use the file as a memory mapped region
namespace ipc = boost::interprocess;
ipc::file_mapping out("cpp.out", ipc::read_write);
// Map the whole file with read-write permissions in this process
ipc::mapped_region region(out, ipc::read_write);
// Get the address of the mapped region
void * addr = region.get_address();
std::size_t size = region.get_size();
// Write to the memory 0x01
std::memset(addr, 0x01, size);
out.flush();
ここで、javaファイルは「cpp.out」を開き、通常のファイルのように内容を読み取ることができます。
両方のプログラムを変更できますか?またはそれらの1つは修正されていますか? – templatetypedef
@templatetypedef、Yeh私は両方を編集することができました。彼らはどちらも私のものです。あなたはここでアプリを見ることができます(mimer.sourceforge.net)バージョン2.0です! – Auxiliary