JNI开发之HelloWorldImpl.c

2008-02-23 09:27:22来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

HelloWorldImpl.c

==============

#include <jni.h>
#include "demo_HelloWorld.h"
#include <stdio.h>
#include <string.h>

int j = 0;

JNIEXPORT void JNICALL
Java_demo_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj, jstring i)
{
char s[]={'a', 'b', 'c'};
char *c = (*env)->GetStringUTFChars(env, i, 0);
char cc [128];
strcpy(cc, c);
(*env)->ReleaseStringUTFChars(env, i, c);

printf("from java;;;%s", cc);
/**
printf(i);

char *str = (*env)->GetStringUTFChars(env, string, 0);
char cap[128];
strcpy(cap, str);
(*env)->ReleaseStringUTFChars(env, string, str);
printf(str);
*/


return;
}


JNIEXPORT jstring JNICALL Java_demo_HelloWorld_c2java
(JNIEnv * env, jobject obj, jbyteArray mobileno, jbyteArray smscontent, jstring str0)
{

jstring jstr;
char str[]={'a', 'b', 'c'};
char cap[128];
const char *str1 = (*env)->GetStringUTFChars(env, str0, 0);

char * pSmscontent ;
//jsize theArrayLengthJ = (*env)->GetArrayLength(env,mobileno);
jbyte * arrayBody = (*env)->GetByteArrayElements(env,mobileno,0);
char * pMobileNo = (char *)arrayBody;
printf("[%s]\n ", pMobileNo);
//jsize size = (*env)->GetArrayLength(env,smscontent);
arrayBody = (*env)->GetByteArrayElements(env,smscontent,0);
pSmscontent = (char *)arrayBody;
printf("<%s>\n", pSmscontent);
// return SmsSend(pMobileNo,pSmscontent);

jstr=(*env)->NewStringUTF(env, str);

strcpy(cap, str1);
printf("from java ==%s", cap);

return jstr;


}


JNIEXPORT jint JNICALL Java_demo_HelloWorld_get
(JNIEnv * env, jobject obj)
{
return j;
}

/*
* Class: demo_HelloWorld
* Method: set
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_demo_HelloWorld_set
(JNIEnv * env, jobject obj, jint i)
{
j = i;
}

JNIEXPORT jint JNICALL Java_demo_HelloWorld_getIntLength
(JNIEnv * env, jobject obj, jintArray iarr)
{
jsize len = (*env)->GetArrayLength(env, iarr);


int i;

int *ielement = (*env)->GetIntArrayElements(env, iarr, 0);

printf("Int array length is %d", len);

for (i=0; i<len; i )
printf("\nAt pos %d is %d.", i, ielement[i]);

(*env)->ReleaseIntArrayElements(env, iarr, ielement, 0);

return len*2;
}


JNIEXPORT void JNICALL Java_demo_HelloWorld_getException
(JNIEnv * env, jobject obj)
{
/* Create the Throwable object. */
jclass cls = (*env)->FindClass(env, "java/io/IOException");
jmethodID mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
jthrowable e = (*env)->NewObject(env, cls, mid);

/* Now throw the exception */
(*env)->Throw(env, e);

return;
}

上一篇: OJB和Hibernate框架的评议一
下一篇: 用MIDP2使用HTTPS(本地服务器)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JNI开发之Ant的build.xml

下一篇:java Logging API 使用