weird problem with JNI

H

hyena

hi,

Just got a weird problem in JNI. I made a DLL in BCB and call it in Java,
and I set the BCB debug environment using the class in java . The BCB dll
shows one float value using a messagebox.

The problem is: when I call the DLL in java, it gives me a value in the
msgBox, whilst it gives me another value if I use debug mode in BCB. Only
sometimes the two values are identical. Anyone has come across this problem?


thanks!
 
S

Stefan Schulz

hi,

Just got a weird problem in JNI. I made a DLL in BCB and call it in Java,
and I set the BCB debug environment using the class in java . The BCB dll
shows one float value using a messagebox.

The problem is: when I call the DLL in java, it gives me a value in the
msgBox, whilst it gives me another value if I use debug mode in BCB. Only
sometimes the two values are identical. Anyone has come across this problem?

Yes! (Which is about as helpful as your problem description).

If you want help solving your problem, please tell us what exactly it is.
A SSCCE¹ would be ideal.

¹ www.physci.org/codes/sscce.jsp
 
H

hyena

Sorry for the confusing description of my question.

In java side, I have a class:

public class MyDLL {
public native static void displayValue();

static {
System.load("D:\\Mywork\\mydll.dll");
}
...

public static void main(String[] args) {

displayValue();
}
...

}

and in C++ side,
in MyDLL.cpp which compiled into myDLL, The function is defined as:

JNIEXPORT void JNICALL Java_scheduler_DLLScheduler_displayHelloWorld
(JNIEnv *env, jclass clas)
{
TSys* myS = new TSys();
exTPe* myTPe;

initialize(myS); //read the parameter files
myS->Execute();

myTPe = (exTPe*)(myS->Pe[0]);
rt = myTPe->showValue(); //here a msgBox shows the value calculated in
myTPe class

delete myS;

return ;
}

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
return 1;
}


the defination of showValue(),

double exTPe::showValue(){

this->CalcdU();
this->CalcU();

.....

sprintf(s,"Value is %4.3f",U);
Application->MessageBoxA(s,"value",MB_OK);
}

the problem is, for example,if I run this in in BCB(setting the parameters
using javaw with classpath etc.), I got a value showed as, say, 47.2. And I
got a value of maybe 52.4 if I run this from java part. And sometimes the
two result are same.

I hope this explains somehow the problem, and hope somebody has experienced
this error before:)
 
C

Chris Uppal

hyena said:
the problem is, for example,if I run this in in BCB(setting the parameters
using javaw with classpath etc.), I got a value showed as, say, 47.2. And
I got a value of maybe 52.4 if I run this from java part. And sometimes
the two result are same.

Uninitialised variable in your C/C++ code somewhere ?

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top