package com.ldq.d_string;
public class D_string {
static {
System.loadLibrary("Case");
}
public native String getCase(String string);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
D_string d = new D_string();
String s = "heLLo";
System.out.println("before change: " + s);
System.out.println("after change: " + d.getCase(s));
}
}
- javah -jni com.ldq.d_string.D_string 生成文件 com_ldq_d_string_D_string.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_ldq_d_string_D_string */
#ifndef _Included_com_ldq_d_string_D_string
#define _Included_com_ldq_d_string_D_string
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_ldq_d_string_D_string
* Method: getCase
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_ldq_d_1string_D_1string_getCase
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
#include <string.h>
#include "com_ldq_d_string_D_string.h"
JNIEXPORT jstring JNICALL Java_com_ldq_d_1string_D_1string_getCase (JNIEnv *env, jobject obj, jstring string)
{
const char *s=env->GetStringUTFChars(string,0);
char s1[16],s2[16];
strcpy(s1,s);
strcpy(s2,s);
strupr(s1);
strlwr(s2);
strcat(s1,"_");
strcat(s1,s2);
env->ReleaseStringUTFChars(string,s);
return env->NewStringUTF(s1);
}
- cl /LD Case.cpp 编译生成 Case.dll 文件
- 拷贝 Case.dll 文件到工程目录,运行 Java 程序
运行结果
before change: heLLo
after change: HELLO_hello
分享到:
相关推荐
JNI传递中文字符串资料
jni编写的一个示例,示例中包含一带参数的有返回值的函数。
jni数据类型转换例程 1. java向native传递常用基本数据类型 和字符串类型 2. java向native传递数组类型 3. java向native传递自定义java对象 4. java向native传递任意java对象(以向native传递ArrayList为例) 5....
Android Java代码与JNI交互字符串转换(四)
这是我自己写的android jni中构造字符串的例子,
jni基本数据类型,数组及对象的传递demo,此demo可推出c,c++调用java方法的实现原理
通过JNI调用本地DLL,并传递中文字符串, Visual C++ 6.0 开发DLL 原创作品,随意转载,提前请说明!
可在jni层返回应用层一个对象数组,包括字符串、整数、小数的成员变量
一个C++(Ubuntu16.04+QT5.9.1)通过JNI,调用JAVA类及方法的示例。通过JNI传递和返回多种类型的参数,boolean ,int,String,ArrayList,ArrayList嵌套ArrayList<ArrayList<String>>等。
jni获取内部类对象,多层结构体嵌套,jni层按位接收解析数据很方便
android jni 中文字符传递demo,实现了C语言与java端之间互相传递汉字的功能。例程开发环境为eclipse。详细说明,见相关博客。
文档里描述了如何通过jni方法在java与c++代码之间传递非基本类型数据
JNI传递数据
【Android NDK 开发】JNI 方法解析 ( 字符串数组参数传递 | 字符串遍历 | 类型强转 | Java 字符串与 C 字符串转换 | 字符串释放 ) 博客地址 : https://hanshuliang.blog.csdn.net/article/details/104103097 I...
JNI 各种参数传递,基本数据类型,自定义对象,系统对象
java中ndk开发,用java调用c,传递参数类型为字符串,字符串数组,整型数组,需要的朋友可以看一下,也可以给我留言。
我写的例子中还是使用默认的ucs4来处理unicode字符串的。见文件as_base_fun.cpp. 在Android NDK中还没有现成的函数来处理字符串的相互转换,但是Android底层有个libicuuc.so库文件,在目录/system/lib/下可以找到这...
通过Jcom调用JNI将Office文档转换Pdf
JNI中C和Java参数传递详细例子,各种数据类型,基本类型,数据,结构体,DEMO,非常适合初学者,一看就明,详细例子