java本地化代码,在vs 2010 中编译的时候出现函数不接受2个参数
如题,自己是找的是网上的java本地化的例子,本地方法的源代码如下:#include<stdio.h>#include<math.h>#include"MyNative....
如题,自己是找的是网上的java本地化的例子,本地方法的源代码如下:
#include <stdio.h>
#include <math.h>
#include "MyNative.h"
JNIEXPORT void JNICALL Java_MyNative_showParms0
(JNIEnv *env, jobject obj, jstring s, jint i, jboolean b)
{
const char* szStr = (*env).GetStringUTFChars( env, s, 0 );
printf( "String = [%s]\n", szStr );
printf( "int = %d\n", i );
printf( "boolean = %s\n", (b==JNI_TRUE ? "true" : "false") );
(*env).ReleaseStringUTFChars( env, s, szStr );
}
JNIEXPORT jint JNICALL Java_MyNative_hypotenuse0
(JNIEnv *env, jobject obj, jint a, jint b)
{
int rtn = (int)sqrt( (double)( (a*a) + (b*b) ) );
return (jint)rtn;
}
JNIEXPORT void JNICALL Java_MyNative_setArray0
(JNIEnv *env, jclass cls, jbooleanArray ba)
{
jboolean* pba = (*env).GetBooleanArrayElements( env, ba, 0 );
jsize len = (*env).GetArrayLength(env, ba);
int i=0;
// 更改偶数数组元素
for( i=0; i < len; i+=2 )
pba[i] = JNI_FALSE;
(*env).ReleaseBooleanArrayElements( env, ba, pba, 0 );
}
JNIEXPORT void JNICALL Java_MyNative_showStrings0
(JNIEnv *env, jclass cls, jobjectArray sa)
{
int len = (*env).GetArrayLength( env, sa );
int i=0;
for( i=0; i < len; i++ )
{
jobject obj = (*env).GetObjectArrayElement(env, sa, i);
jstring str = (jstring)obj;
const char* szStr = (*env).GetStringUTFChars( env, str, 0 );
printf( "%s ", szStr );
(*env).ReleaseStringUTFChars( env, str, szStr );
}
printf( "\n" );
}
JNIEXPORT jobjectArray JNICALL Java_MyNative_getStrings0
(JNIEnv *env, jclass cls)
{
jstring str;
jobjectArray args = 0;
jsize len = 5;
char* sa[] = { "Hello,", "world!", "JNI", "is", "fun" };
int i=0;
args = (*env).NewObjectArray(env, len, (*env).FindClass(env, "java/lang/String"), 0);
for( i=0; i < len; i++ )
{
str = (*env).NewStringUTF( env, sa[i] );
(*env).SetObjectArrayElement(env, args, i, str);
}
return args;
} 展开
#include <stdio.h>
#include <math.h>
#include "MyNative.h"
JNIEXPORT void JNICALL Java_MyNative_showParms0
(JNIEnv *env, jobject obj, jstring s, jint i, jboolean b)
{
const char* szStr = (*env).GetStringUTFChars( env, s, 0 );
printf( "String = [%s]\n", szStr );
printf( "int = %d\n", i );
printf( "boolean = %s\n", (b==JNI_TRUE ? "true" : "false") );
(*env).ReleaseStringUTFChars( env, s, szStr );
}
JNIEXPORT jint JNICALL Java_MyNative_hypotenuse0
(JNIEnv *env, jobject obj, jint a, jint b)
{
int rtn = (int)sqrt( (double)( (a*a) + (b*b) ) );
return (jint)rtn;
}
JNIEXPORT void JNICALL Java_MyNative_setArray0
(JNIEnv *env, jclass cls, jbooleanArray ba)
{
jboolean* pba = (*env).GetBooleanArrayElements( env, ba, 0 );
jsize len = (*env).GetArrayLength(env, ba);
int i=0;
// 更改偶数数组元素
for( i=0; i < len; i+=2 )
pba[i] = JNI_FALSE;
(*env).ReleaseBooleanArrayElements( env, ba, pba, 0 );
}
JNIEXPORT void JNICALL Java_MyNative_showStrings0
(JNIEnv *env, jclass cls, jobjectArray sa)
{
int len = (*env).GetArrayLength( env, sa );
int i=0;
for( i=0; i < len; i++ )
{
jobject obj = (*env).GetObjectArrayElement(env, sa, i);
jstring str = (jstring)obj;
const char* szStr = (*env).GetStringUTFChars( env, str, 0 );
printf( "%s ", szStr );
(*env).ReleaseStringUTFChars( env, str, szStr );
}
printf( "\n" );
}
JNIEXPORT jobjectArray JNICALL Java_MyNative_getStrings0
(JNIEnv *env, jclass cls)
{
jstring str;
jobjectArray args = 0;
jsize len = 5;
char* sa[] = { "Hello,", "world!", "JNI", "is", "fun" };
int i=0;
args = (*env).NewObjectArray(env, len, (*env).FindClass(env, "java/lang/String"), 0);
for( i=0; i < len; i++ )
{
str = (*env).NewStringUTF( env, sa[i] );
(*env).SetObjectArrayElement(env, args, i, str);
}
return args;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询