tags:

views:

127

answers:

5

Hi, 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?

+1  A: 

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);
Sorantis
+1  A: 

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.

NickLarsen
+1  A: 

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.

sdg
A: 

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.

Mark
+3  A: 

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.

aviv
CSV would work, too.
R. Bemrose