tags:

views:

393

answers:

3

Hey Folks,

So i have been looking into JNI calls so i can interact with some pre written C++ programs, i dont know any C++ but am trying to learn some basics. I have just been trying to do a simple call to a method outside my JNI method but always get the following error:

error c3861 'myMethod': identifier not found

#include <stdio.h>
#include <string.h>
#include "StringFuncs.h"    

JNIEXPORT jstring JNICALL Java_StringFuncs_changeWord(JNIEnv *env, jobject obj, jstring inStr, jint inLen) 
{
    const char *inString;

    inString = env->GetStringUTFChars(inStr, NULL);


    char otherString[40];
    strcpy_s(otherString,inString);

    if(myMethod())
    {
     memset(otherString, '-', inLen);
    }

    jstring newString = env->NewStringUTF((const char*)otherString);
    return newString;
}

bool myMethod()
{
    return true;
}

int main()
{
    return 0;
}

Any words of wisdome?

+2  A: 

You have to declare your methods before you call them. So in your header type bool myMethod();

Or you can move the code above your _changeWord function, then the declaration/definition is in one.

Budric
thanks! silly me, forgot about that header business
Petey B
+1  A: 

Move myMethod() above Java_StringFuncs_changeWord() in the source file.

Paul Mitchell
+1  A: 

In C++ you generally have to declare a symbol before you use it. So, somewhere before Java_StringFuncs_changeWord you need to declare myMethod:

bool myMethod();

If this is going to be a shared function (other cpp modules will call it) then you most likely want to put it in a header file which can be #included by other files. If the function only makes sense to be called by this module, you want to put the declaration at the top of the file, after the other #includes.

You can also declare and define the function in one go by moving the whole function above the function that calls it, but this wont always work (if you have two functions which reference eachother you have to have a separate declaration).

Dolphin