JNI problem(asking again)

H

hyena

Sorry for asking again, but till now I haven't solved it. :(

Just got a weird problem in JNI. I made a DLL in BCB and call it in Java,
the 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, and keep rerurning the same one which is supposed to change time by
time. whilst it gives me another value if I use debug mode in BCB and works
fine. I tried use another C++ exe to call this dll, everything works fine.

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 if I call more then one time in
Java, it sticks to the value and never change. Anyone has come across this
problem?

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);
}


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

Bjorn Abelli

...
Sorry for asking again, but till now I haven't solved it. :(

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

I must have missed something about how the JNI-mapping works, but I don't
see how your Java-side and C++-side even match?

Java-side:
public native static void displayValue();
C/C++:


JNIEXPORT void JNICALL Java_scheduler_DLLScheduler_displayHelloWorld
(JNIEnv *env, jclass clas)


?

Shouldn't it be more in the line of this:

JNIEXPORT void JNICALL Java_MyDLL_displayValue
(JNIEnv *env, jclass clas)


// Bjorn A
 
H

hyena

Sorry for miss typing the functionname.
JNIEXPORT void JNICALL Java_scheduler_DLLScheduler_displayHelloWorld
(JNIEnv *env, jclass clas)

this is the real function name used and displayValue is the one to
demostrate the problem.

should be like this:
java side,
public class MyDLL {
public native static void displayValue();


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

JNIEXPORT void JNICALL Java_displayValue
(JNIEnv *env, jclass clas)


anyway, I can call dll from java side and it looks working well except the
value shown wrong.
 

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

Similar Threads

weird problem with JNI 3
JNI return jobjectArray 7
Void problem 1
JNI Invocation API example 4
Problem with JNI 7
Problem with JNI and Tomcat 6
COM, again 0
Logic Problem with BigInteger Method 2

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top