Actually, you can call Java from C++ using JNI. It isn't pretty, JNI was ment to be from Java to C++, but it does work. Sadly there isn't a lot of documentation on this.
As for why the first code fragment didn't work, I'm not sure. I'm about 99% sure I have done this very thing operation...