aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes not able to access java variables after calling native functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "not able to access java variables after calling native functions" Watch "not able to access java variables after calling native functions" New topic
Author

not able to access java variables after calling native functions

chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
Hi,

I am running a java program which calls a native C function and returns back. The native code is getting executed but after returning back to the java program, the variables are not identified.
Let me explain,

My java program is like,

psvm(String args[]){
int n=10;
System.out.println("n value is:"+n);
//code for calling the C-Function
System.out.println("back to java program");
System.out.println("n value is:"+n);
//other code
}

When I run this program, the output is,
n value is:10
back to java program


The problem is that the program is not identifying "n" after returning back and the "//other code" is not executed. Also no error or exception is shown.
Can anyone help me.


Chandana.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Can you us the actual full code of this method? Without those comment place holders.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
public class testingC {

native void testingcores(int int1,int int2);
static {
System.load("C:\\Microsoft Visual Studio 9.0\\VC\\Cprogram.dll");
}
public static void main(String[] args) {
int n=Integer.parseInt(args[1]);
System.out.println("jobs to be created is:"+n);
testingC tc=new testingC();
for(int i=1;i<=n;i++){
tc.testingcores(i,i+(i*100));
}
System.out.println("All jobs are started ");
System.out.println("jobs"+n+"started);
}


java testingC 5 5

then OUTPUT is,
jobs to be created is 5.
All jobs started.

The problem is that when it encounters a variable("n" in this case), it is not recognizing it. So,the last statement is not printed.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

This code should never cause any problems. All I can think of is some bug in your native code. Can you show the native code for testingcores?
And while you're at it, please Use Code Tags.
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
The following is the C code,


I don't think there is a problem with the C code,
the file is created and data is written correctly.">
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not able to access java variables after calling native functions