使用 JNI 在 C++ 中调用方法?

2023-12-31

所以我一直在研究 JNI 调用,以便我可以与一些预先编写的 C++ 程序进行交互,我不了解任何 C++,但我正在尝试学习一些基础知识。我刚刚尝试对 JNI 方法之外的方法进行简单调用,但总是收到以下错误:

错误 c3861“myMethod”:找不到标识符

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

有什么至理名言吗?


您必须在调用方法之前声明它们。所以在你的标题类型中 布尔 myMethod();

或者您可以将代码移至 _changeWord 函数上方,然后声明/定义合二为一。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 JNI 在 C++ 中调用方法? 的相关文章

随机推荐