开发者

Using Java JAR libraries with C++

I'm developing a win32 C++ application that needs to export data to excel spreadsheets. There isn't a mature C++ library for this, but exists for Java. How I can integrate a C++ application with Java开发者_如何转开发 code, in such way that I can call Java functions from my C++ application?


You can also generate a simple html file, save it as .xls and excel will know to read it. e.g: <table><tr><td>cell a</td><td>cell b</td></table>

And then no need for executing Java and external programs.


See this and this

First is Creating a Child Process with Redirected Input and Output article

Second is How to spawn console processes with redirected standard handles.

Good reading in general, might solve your problem.

Example

HINSTANCE hInst = ShellExecute(NULL, "open", "path\\to\\java.exe", "-jar path\to\lib.jar WORLD", NULL, SW_SHOWMAXIMIZED);


Another solution might be to create a client in C++ and a server in Java. I have done the opposite of this (java client, c++ server) for a solution once, but we only sent along small amounts data each request, so I am not sure how this would adapt to your problem, but just for the sake of thought.


If you are merely exporting data, you might find it simpler to just emit CSV or other files that Excel can ingest, instead of a full-blown Excel file.


How To Call Java Functions From C Using JNI might get you started.

However I would agree with NickLarsen that having separate processes would be a lot cleaner and simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜