如何通过C语言实现调用Java Native Interface(JNI)的方法?

2026-04-16 17:563阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计276个文字,预计阅读时间需要2分钟。

如何通过C语言实现调用Java Native Interface(JNI)的方法?

我一直在学习JNI调用,因此可以与一些预先编写的C程序进行交互。虽然我不知道具体的C代码,但我正在尝试学习一些基础知识。我刚开始尝试对JNI方法之外的调用进行简单测试,但一开始就遇到了以下错误:

所以我一直在调查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; }

智慧的任何话语?

如何通过C语言实现调用Java Native Interface(JNI)的方法?

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

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

本文共计276个文字,预计阅读时间需要2分钟。

如何通过C语言实现调用Java Native Interface(JNI)的方法?

我一直在学习JNI调用,因此可以与一些预先编写的C程序进行交互。虽然我不知道具体的C代码,但我正在尝试学习一些基础知识。我刚开始尝试对JNI方法之外的调用进行简单测试,但一开始就遇到了以下错误:

所以我一直在调查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; }

智慧的任何话语?

如何通过C语言实现调用Java Native Interface(JNI)的方法?

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

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