Passing a pointer value from C++ to Java using JNI
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mario_Mari
Posted On:   Thursday, October 4, 2001 04:44 AM

body> How can I pass the "ftValue" from C++ to Java if the ftValue a float pointer is ? The following way doesn't works, please help me! //************** //the Java Class //************** public class X extends Y{ private int m_statusStart; private int m_status; private int m_timeout; public float m_weight; /** Native's function declarations*/ public native int XBalGetWeight(int nMode, int nTimeout,float ftvalue, int nStatus); /** require the Weight and return the code*/ public int Start(){ int nMode = 2; int nTimeout = m_timeout; int nStatus = m_status;    More>>

body>



			
How can I pass the "ftValue" from C++ to Java if the ftValue a float pointer is ?
The following way doesn't works, please help me!



			
//**************
//the Java Class
//**************
public class X extends Y{

private int m_statusStart;
private int m_status;
private int m_timeout;
public float m_weight;

/** Native's function declarations*/
public native int XBalGetWeight(int nMode, int nTimeout,float ftvalue, int nStatus);

/** require the Weight and return the code*/
public int Start(){
int nMode = 2;
int nTimeout = m_timeout;
int nStatus = m_status;
float ftvalue = 0.0f;

m_statusStart = XBalGetWeight(nMode, nTimeout, ftvalue, nStatus);
System.out.println("ReturnVal: " + m_statusStart + " ftValue: " + ftvalue + " " + m_weight);
return m_statusStart;
};

}



			
//**********************
//the JNI-Wrapper in C++
//**********************

JNIEXPORT jint JNICALL Java_device_Waage_XBalGetWeight (JNIEnv *env, jobject thisObj, jint nMode, jint nTimeout, jfloat ftValue, jint numStat){

int iRet = -1;

jclass clazz;
clazz = env->GetObjectClass(thisObj);

iRet = myDll.XBalGetWeight(nMode, nTimeout, &ftValue, numStat);

printf("XBalGetWeight, ftValue: %f iRet: %d
", ftValue, iRet);

jfieldID fid1 = env->GetFieldID(clazz, "m_weight", "F");
env->GetFloatField(clazz, fid1);

env->SetFloatField(clazz, fid1, ftValue);

return (jint)iRet;
}



			
//**************
// myDll
//**************


extern int __stdcall XBalGetWeight(int nMode, int nTimeout,float* ftValue, int nStatus){

*ftValue = 1.1f;
return 1;
}



			
Thanks, Mario.



   <<Less
About | Sitemap | Contact