Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / Java / Java SE

Example of using Object-Oriented Java Native Interface in C++

Rate me:
Please Sign up or sign in to vote.
3.73/5 (10 votes)
3 Feb 2006CPOL4 min read 78.4K   1.8K   39  
Demonstrates an easy way of creating and embedding Java objects into C++ code, with Object-Oriented JNI.
/**************************************************************************
 *
 * The code is generated for Microsoft VC++ 6.0
 *
 * with OOJNI Demo Tool developed by Vitaly Shelest (Javain Ltd.)
 *
 * You may use the code generated with OOJNI Demo only
 *
 * for evaluation and any use other than evaluation
 *
 * requiers a purchase of a license.
 *
 * Do not change the content of this file.
 *
 * You can order the latest version of OOJNI Add-in at http://www.javain.com
 * 
 **************************************************************************/

#include "stdafx.h"
#include "defproxies.h"


const JNINativeMethod CPP_Java_Bridge::java::lang::RunnableJNIImpl::methods[] = {
    {"native0run", "(J)V", 
     CPP_Java_Bridge::java::lang::RunnableJNIImpl_Native::run},
};

namespace CPP_Java_Bridge{
    namespace java{
        namespace lang{
const char* RunnableJNIImpl::_clazzName = "java/lang/JNIImplementationOfRunnable";
const jbyte RunnableJNIImpl::bytes[] = {
0xca,0xfe,0xba,0xbe,0x00,0x03,0x00,0x2d,0x00,0x16,0x07,0x00,0x05,0x07,0x00,
0x06,0x01,0x00,0x03,0x72,0x75,0x6e,0x01,0x00,0x03,0x28,0x29,0x56,0x01,0x00,
0x12,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x52,0x75,0x6e,0x6e,
0x61,0x62,0x6c,0x65,0x01,0x00,0x10,0x6a,0x61,0x76,0x61,0x2f,0x6c,0x61,0x6e,
0x67,0x2f,0x4f,0x62,0x6a,0x65,0x63,0x74,0x01,0x00,0x25,0x6a,0x61,0x76,0x61,
0x2f,0x6c,0x61,0x6e,0x67,0x2f,0x4a,0x4e,0x49,0x49,0x6d,0x70,0x6c,0x65,0x6d,
0x65,0x6e,0x74,0x61,0x74,0x69,0x6f,0x6e,0x4f,0x66,0x52,0x75,0x6e,0x6e,0x61,
0x62,0x6c,0x65,0x07,0x00,0x07,0x01,0x00,0x06,0x3c,0x69,0x6e,0x69,0x74,0x3e,
0x01,0x00,0x03,0x28,0x29,0x56,0x01,0x00,0x0a,0x6e,0x61,0x74,0x69,0x76,0x65,
0x30,0x72,0x75,0x6e,0x01,0x00,0x04,0x28,0x4a,0x29,0x56,0x01,0x00,0x04,0x43,
0x6f,0x64,0x65,0x01,0x00,0x04,0x70,0x65,0x65,0x72,0x01,0x00,0x01,0x4a,0x0c,
0x00,0x0e,0x00,0x0f,0x09,0x00,0x08,0x00,0x10,0x0c,0x00,0x0b,0x00,0x0c,0x0a,
0x00,0x08,0x00,0x12,0x0c,0x00,0x09,0x00,0x0a,0x0a,0x00,0x02,0x00,0x14,0x00,
0x21,0x00,0x08,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x0e,
0x00,0x0f,0x00,0x00,0x00,0x03,0x00,0x01,0x00,0x09,0x00,0x0a,0x00,0x01,0x00,
0x0d,0x00,0x00,0x00,0x11,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x05,0x2a,0xb7,
0x00,0x15,0xb1,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x03,0x00,0x04,0x00,0x01,
0x00,0x0d,0x00,0x00,0x00,0x15,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x09,0x2a,
0x2a,0xb4,0x00,0x11,0xb6,0x00,0x13,0xb1,0x00,0x00,0x00,0x00,0x01,0x01,0x00,
0x0b,0x00,0x0c,0x00,0x00,0x00,0x00};
RunnableJNIImpl::RunnableJNIImpl(){
    try{
        init(_clazzName, methods, sizeof(methods)/sizeof(JNINativeMethod), bytes, sizeof(bytes));
    }catch(::jni_helpers::JVMException e){
        throw ::jni_helpers::JVMException(e.getMessage());
    }catch(...){
        throw ::jni_helpers::JVMException("System Error");
    }
}
void JNICALL RunnableJNIImpl_Native::run
(
    JNIEnv* env, jobject, jlong peer
)
{
    if(!JNIEnvHelper::isInitialized())
        JNIEnvHelper::init(env);
    try{
        ((CPP_Java_Bridge::java::lang::RunnableJNIImpl*)peer)->run();
    }catch(...){
    }
}
}}}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Javain Ltd
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions