使用JNI在C ++中进行方法调用? [英] Method Calls in C++ with JNI?

查看:76
本文介绍了使用JNI在C ++中进行方法调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在研究JNI调用,以便可以与一些预先编写的C ++程序进行交互,我不知道任何C ++,但正在尝试学习一些基础知识.我一直在尝试对JNI方法之外的方法进行简单调用,但始终会收到以下错误:

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:

错误c3861'myMethod':找不到标识符

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

有智慧的话吗?

推荐答案

在调用它们之前,必须先声明您的方法.所以在您的标题类型中 bool myMethod();

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

或者您可以将代码移到_changeWord函数上方,然后将声明/定义放在其中.

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

这篇关于使用JNI在C ++中进行方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆