P
pcarr01
I have a servlet which makes some JNI calls on a Win32 DLL Like so
Java bits
*******************************
public native RiposteNode getRiposteNode(long GroupId, long
NodeId)throws RiposteException;
......
......
try{
R1 = new RiposteInstance(Frank);
out.println("<br>Frank Riposte is OK");
RiposteNode N = R1.getRiposteNode(123456,32);
out.println("<br>Frank Riposte Marker =
"+N.getMarker());
}catch(RiposteException e)
{
out.println("<br> Exception: Frank
Riposte="+e.toString());
}
It works in that I can pass one argument (123456) to the function and
it will throw exceptions back into the servlet but the second argument
(32) is reported as zero by the DLL, see output at the end.
The DLL relevant DLL code is as follows, it includes some fprintfs for
diagnostic reasons because I am having trouble getting MS VC++ 6.0
(SP5) to do the debug thing.
Any ideas appreciated.
********************************
C++
********************************
include file declaration ( from the javah output )
JNIEXPORT jobject JNICALL
Java_Riposte_RiposteInstance_getRiposteNode
(JNIEnv *, jobject, jlong, jlong);
cpp file
JNIEXPORT jobject JNICALL
Java_Riposte_RiposteInstance_getRiposteNode
(JNIEnv *env, jobject jobj, jlong GroupId, jlong NodeId)
{
FILE* f = fopen("c:\\temp\\getRiposteNode.log","w");
fprintf(f,"%s %d %d \n", "Start of getRiposteNode " ,GroupId ,
NodeId );
fflush(f);
unsigned long RipErrCode;
unsigned char RipErr[1024];
MARKER Mark;
unsigned long dwMarkerDelta;
unsigned long fOnline;
unsigned long fConnected;
// unsigned long dwMarkerGroupId;
unsigned long *pfOnline=&fOnline;
unsigned long *pfConnected=&fConnected;
unsigned long *pdwMarkerDelta=&dwMarkerDelta;
PMARKER pMarker =(unsigned long *) &Mark;
// get node object class
jclass NodeClass = env->FindClass("Riposte/RiposteNode");
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// get method id for ctor using "<init>" in GetMethodID
jmethodID ctor = env->GetMethodID(NodeClass,"<init>","(L,L)V");
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// create new object
jobject Node=env->NewObject(NodeClass, ctor, GroupId,NodeId);
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// make the call & handle the exception
fprintf(f,"%s\n", "before RiposteGetNodeStatus\n");
fflush(f);
if (RipErrCode=RiposteGetNodeStatus(GroupId, NodeId, pfOnline,
pfConnected,
GroupId, pMarker, pdwMarkerDelta))
{
fprintf(f,"%s %d %d \n", "after RiposteGetNodeStatus \n"
,GroupId,NodeId );
fflush(f);
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("Riposte/RiposteException");
if (newExcCls == 0)
{
/* Unable to find the new exception class,
give up.
*/
return Node;
}
if(0!=(RiposteErrorString(RipErrCode,RipErr,1024)))
{
env->ThrowNew(newExcCls, (char*)RipErr);
fprintf(f,"%s\n", "Exception Thrown\n");
fflush(f);
return Node;
}
}
jmethodID sMarker =
env->GetMethodID(NodeClass,"setMarker","([J)V");
fprintf(f,"%s\n", "sMarker\n");
fflush(f);
env->CallVoidMethod(NodeClass,sMarker,Mark);
fprintf(f,"%s\n", "CallVoidMethod\n");
fflush(f);
return Node;
}
************************************
output
************************************
Start of getRiposteNode 123456 0
jclass
jclass
jclass
before RiposteGetNodeStatus
after RiposteGetNodeStatus
123456 0
Exception Thrown
Java bits
*******************************
public native RiposteNode getRiposteNode(long GroupId, long
NodeId)throws RiposteException;
......
......
try{
R1 = new RiposteInstance(Frank);
out.println("<br>Frank Riposte is OK");
RiposteNode N = R1.getRiposteNode(123456,32);
out.println("<br>Frank Riposte Marker =
"+N.getMarker());
}catch(RiposteException e)
{
out.println("<br> Exception: Frank
Riposte="+e.toString());
}
It works in that I can pass one argument (123456) to the function and
it will throw exceptions back into the servlet but the second argument
(32) is reported as zero by the DLL, see output at the end.
The DLL relevant DLL code is as follows, it includes some fprintfs for
diagnostic reasons because I am having trouble getting MS VC++ 6.0
(SP5) to do the debug thing.
Any ideas appreciated.
********************************
C++
********************************
include file declaration ( from the javah output )
JNIEXPORT jobject JNICALL
Java_Riposte_RiposteInstance_getRiposteNode
(JNIEnv *, jobject, jlong, jlong);
cpp file
JNIEXPORT jobject JNICALL
Java_Riposte_RiposteInstance_getRiposteNode
(JNIEnv *env, jobject jobj, jlong GroupId, jlong NodeId)
{
FILE* f = fopen("c:\\temp\\getRiposteNode.log","w");
fprintf(f,"%s %d %d \n", "Start of getRiposteNode " ,GroupId ,
NodeId );
fflush(f);
unsigned long RipErrCode;
unsigned char RipErr[1024];
MARKER Mark;
unsigned long dwMarkerDelta;
unsigned long fOnline;
unsigned long fConnected;
// unsigned long dwMarkerGroupId;
unsigned long *pfOnline=&fOnline;
unsigned long *pfConnected=&fConnected;
unsigned long *pdwMarkerDelta=&dwMarkerDelta;
PMARKER pMarker =(unsigned long *) &Mark;
// get node object class
jclass NodeClass = env->FindClass("Riposte/RiposteNode");
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// get method id for ctor using "<init>" in GetMethodID
jmethodID ctor = env->GetMethodID(NodeClass,"<init>","(L,L)V");
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// create new object
jobject Node=env->NewObject(NodeClass, ctor, GroupId,NodeId);
fprintf(f,"%s\n", "jclass\n");
fflush(f);
// make the call & handle the exception
fprintf(f,"%s\n", "before RiposteGetNodeStatus\n");
fflush(f);
if (RipErrCode=RiposteGetNodeStatus(GroupId, NodeId, pfOnline,
pfConnected,
GroupId, pMarker, pdwMarkerDelta))
{
fprintf(f,"%s %d %d \n", "after RiposteGetNodeStatus \n"
,GroupId,NodeId );
fflush(f);
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("Riposte/RiposteException");
if (newExcCls == 0)
{
/* Unable to find the new exception class,
give up.
*/
return Node;
}
if(0!=(RiposteErrorString(RipErrCode,RipErr,1024)))
{
env->ThrowNew(newExcCls, (char*)RipErr);
fprintf(f,"%s\n", "Exception Thrown\n");
fflush(f);
return Node;
}
}
jmethodID sMarker =
env->GetMethodID(NodeClass,"setMarker","([J)V");
fprintf(f,"%s\n", "sMarker\n");
fflush(f);
env->CallVoidMethod(NodeClass,sMarker,Mark);
fprintf(f,"%s\n", "CallVoidMethod\n");
fflush(f);
return Node;
}
************************************
output
************************************
Start of getRiposteNode 123456 0
jclass
jclass
jclass
before RiposteGetNodeStatus
after RiposteGetNodeStatus
123456 0
Exception Thrown