This discussion is archived
1 Reply Latest reply: Mar 19, 2013 3:24 PM by jschellSomeoneStoleMyAlias RSS

code behaves differently in c and c++

996648 Newbie
Currently Being Moderated
I have a function which calls java code.
The function is working fine when placed in c file, but when placed in c++ (cpp) file the return value from the java function is wrong and looks like garbage.

Does anybody know why ?

Here is the code

unsigned char pKey[] = {'0','1','2','3','4','5','6','7','8','9','1','2','3','4','5','6'};
unsigned char pIv[] = {'0','1','2','3','4','5','6','7','8','9','1','2','3','4','5','6'};
     
size_t nBufInLen = 1000;
size_t nKeyLen = sizeof(pKey);
size_t nIvLen = sizeof(pIv);

jbyteArray jKey = env->NewByteArray(nKeyLen);
jbyteArray jIv = env->NewByteArray(nIvLen);

jclass cls = env->GetObjectClass(obj);
     
jmethodID midGetCryptSize = env->GetStaticMethodID(cls, "GetBufSize", "(I[B[B)I");

jint nBufOutSize = env->CallStaticIntMethod(cls, midGetCryptSize, nBufInLen, jKey, jIv);

return nBufOutS

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points