Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can write a Java class as a wrapper of a C++ class ?

843829Apr 7 2005
Hi Guys,

I have an urgent question to ask for help. I am planning to write some Java objects as the wrappers for some C++ objects. For
example:

I have C++ objects:
class A
{
     public: void print( )
	{
	     printf("%s\n", "Hello World !");
	}
};

class B
{
     public: A* get_instance( )
	{
            return new A( );
	}
};
and I have Java classes as the wrappers:
public class JA
{
	public native void print();
	
        static 
        {
	    System.loadLibrary("ABshared");
	}
}

public class JB
{
	
	public native JA get_instance();
	
	static 
        {
	    System.loadLibrary("ABshared");
	}
}
but how can I implement my native methods in C++ so that JA and JB can hold pointers to A and B respectively ?
JNIEXPORT void JNICALL Java_JA_print
  (JNIEnv *env, jobject obj)
{
   //implement me
}

JNIEXPORT jobject JNICALL Java_JB_get_1instance
  (JNIEnv *env, jobject obj)
{
    
   //implement me	
}
thank you very much !
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2005
Added on Apr 7 2005
0 comments
73 views