Brett McCoy wrote:
> On Sun, Apr 5, 2009 at 6:01 AM, Snit Roy <[email protected]> wrote:
>   
>> i want to know is there any way to use java packages and function in C++???i 
>> am using MSVC++ 2008 sp 1.how will i do this please help..................
>>     
>
> It's easier to do it the other way around, create native methods in
> C++ and call from Java. But you can call Java methods from C++ also.
>
> Here's an article on integrating the two languages:
>
> http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
>   

That article is 13 years old and references JDK 1.0.2: the native 
interface has undergone improvements, and several issues it mentions 
(garbage collection, weak references) are not issues anymore due to 
those improvements. Regardless, using the JDK tools for writing native 
code is still tedious and there is a better alternative.

I would look at using GCC for the integration, starting at the GCJ home 
page:
http://gcc.gnu.org/java/

G++ and GCJ play very nicely together. Basically how it works is you 
link the GNU JVM and your Java byte code into your C++ program, where 
you can instantiate a C++ object that encapsulates the JVM itself. You 
can then instruct it to perform tasks such as creating Java objects, 
which you manipulate via proxy. This language binding layer handles 
translating low level objects between languages automatically, mainly, 
primitives and strings (remember Java strings are always Unicode and not 
null-terminated).

If the OP must use Visual C++ 2008 then this may still be possible, but 
I have never tried it that way and it would probably take more work.

-- 
John Gaughan
http://www.jtgprogramming.org/

Reply via email to