[1480] in java-interest

home help back first fref pref prev next nref lref last post

Invoking Java methods in C++

daemon@ATHENA.MIT.EDU (Imran Balkhi (NT))
Tue Sep 5 20:12:13 1995

Date: Tue, 5 Sep 1995 11:45:21 -0700
From: ibalkhi@dnt.dialog.com (Imran Balkhi (NT))
To: java-interest@java.sun.com

Hi everyone,

I am trying to invoke Java method from native C++ function. 



//start java code

class son { 
static	int y = 5;

	son() {
		y = y + 1;
		System.out.print("........in son constructor \n");
		}

	void print(){
		System.out.print("........in son print \n");
		}

	void finalize() {
		System.out.print ("......in son destructor \n");
		}
}

class parent {
	public native son mySon(son s);
    	parent () {
		System.out.print ("........in parent constructor \n");

	}
	
	public static void main(String args[]) {

		parent x1 = new parent();

		son s1 = new son();
		son s2;
	
		System.out.print ("........in parent main after call son constructor \n");
		System.out.println (s1);

		s2 =x1.mySon(s1);
		System.out.print ("........in parent main after call myson \n");
		System.out.println (s2);

		s1.finalize();
	}

}
//end java code


// start native function

struct Hson *parent_mySon(struct Hparent *obj, struct Hson *SonObject){
	
	ClassClass *sonClass = FindClass (0,"son",TRUE);

	Hjava_lang_Object *localson = execute_java_constructor(0,"son",sonClass,"()");

   	execute_java_dynamic_method  (0,
				(Hjava_lang_Object *) print,   // real_native.cc, line 161:
				"handle",
				"()",
				localson);
	return ((Hson *)localson);
}
//end native function





			// ERROR in native function 



"real_native.cc", line 161: Error: print is not defined.

// tried to replace print with finalize, but got the same error. 

"real_native.cc", line 161: Error: finalize is not defined.



NOTE:	1) If call to execute_java_dynamic_method(..) is commented out then it compiles and executes. Also in this case son constructor is called from native myson. 

	2) I tried to replace localson with SonObject in execute_java_dynamic_method(..) call, but got the same error.
	
	3) I am not very clear about method signatures. With no argument its easy to figure. Can somebody let me know how would I call a java method/constructor with arguments. Please give example.
	
	
	
	
Thank's
Imran
	
	
	 



-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post