15.2.2.3 传递字符串

来源:互联网 发布:剑三正太脸型喵太数据 编辑:程序博客网 时间:2024/05/18 20:34
public class Sample1{     public native String stringMethod(String text);     public static void main(String[] args)     {         System.loadLibrary("Sample1");          Sample1 sample = new Sample1();          String text   = sample.stringMethod("Thinking In Java");         System.out.println("stringMethod: " + text);     }}/*// Sample1.cpp : 定义 DLL 应用程序的导出函数。//#include "stdafx.h"#include "..\Sample1.h"#include <string.h>    JNIEXPORT jstring JNICALL Java_Sample1_stringMethod  (JNIEnv *env, jobject, jstring string){         const char *str = env->GetStringUTFChars(string, 0);         char cap[128];         strcpy(cap, str);         env->ReleaseStringUTFChars( string, str);       int i=0;       for(i=0;i<strlen(cap);i++)         *(cap+i)=(char)toupper(*(cap+i));       return env->NewStringUTF( cap);}*//*stringMethod: THINKING IN JAVA请按任意键继续. . .*/

原创粉丝点击