Help!BCB中如何调用一个Java Class且得到其返回值? JNI用dll作中介达成java与BCB或VC之间的调用,传值。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也不懂,但我在java 核心2中找到一些代码贴给你/** * @version 1.10 1997-07-01 * @author Cay Horstmann 这是printf3.c文件 */#include "Printf3.h"#include <string.h>#include <stdlib.h>#include <float.h>char* find_format(const char format[])/** * @param format a string containing a printf format specifier * (such as "%8.2f"). Substrings "%%" are skipped. * @return a pointer to the format specifier (skipping the '%') * or NULL if there wasn't a unique format specifier */{ char* p; char* q; p = strchr(format, '%'); while (p != NULL && *(p + 1) == '%') /* skip %% */ p = strchr(p + 2, '%'); if (p == NULL) return NULL; /* now check that % is unique */ p++; q = strchr(p, '%'); while (q != NULL && *(q + 1) == '%') /* skip %% */ q = strchr(q + 2, '%'); if (q != NULL) return NULL; /* % not unique */ q = p + strspn(p, " -0+#"); /* skip past flags */ q += strspn(q, "0123456789"); /* skip past field width */ if (*q == '.') { q++; q += strspn(q, "0123456789"); } /* skip past precision */ if (strchr("eEfFgG", *q) == NULL) return NULL; /* not a floating point format */ return p;}JNIEXPORT void JNICALL Java_Printf3_fprint (JNIEnv* env, jclass cl, jobject out, jstring format, jdouble x){ const char* cformat; char* fmt; jstring str; jclass class_PrintWriter; jmethodID id_print; cformat = (*env)->GetStringUTFChars(env, format, NULL); fmt = find_format(cformat); if (fmt == NULL) str = format; else { char* cstr; int width = atoi(fmt); if (width == 0) width = DBL_DIG + 10; cstr = (char*)malloc(strlen(cformat) + width); sprintf(cstr, cformat, x); str = (*env)->NewStringUTF(env, cstr); free(cstr); } (*env)->ReleaseStringUTFChars(env, format, cformat); /* now call ps.print(str) */ /* get the class */ class_PrintWriter = (*env)->GetObjectClass(env, out); /* get the method ID */ id_print = (*env)->GetMethodID(env, class_PrintWriter, "print", "(Ljava/lang/String;)V"); /* call the method */ (*env)->CallVoidMethod(env, out, id_print, str);}以下是printf3.h文件/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class Printf3 */#ifndef _Included_Printf3#define _Included_Printf3#ifdef __cplusplusextern "C" {#endif/* * Class: Printf3 * Method: fprint * Signature: (Ljava/io/PrintWriter;Ljava/lang/String;D)V */JNIEXPORT void JNICALL Java_Printf3_fprint (JNIEnv *, jclass, jobject, jstring, jdouble);#ifdef __cplusplus}#endif#endif以下是两个java文件Print3.java/** * @version 1.10 1997-07-01 * @author Cay Horstmann */import java.io.*;class Printf3{ public static native void fprint(PrintWriter out, String format, double x); static { System.loadLibrary("Printf3"); }}Print3Test.java/** * @version 1.10 1997-07-01 * @author Cay Horstmann */import java.io.*;class Printf3Test{ public static void main(String[] args) { double price = 44.95; double tax = 7.75; double amountDue = price * (1 + tax / 100); PrintWriter out = new PrintWriter(System.out); Printf3.fprint(out, "Amount due = %8.2f\n", amountDue); out.flush(); }} 你的e_mail我给你发以前作的例子。功能是:通过BCB捕捉鼠标的位置然后传给java程序 我的e-mail是[email protected]我更想知道“通过java捕捉鼠标的位置然后传给BCB程序”!!!JNI看了两天,还是搞不定呀! 通过java捕捉鼠标的位置然后传给BCB程序也可以实现,你自己去测试吧! 对不起,这段时间忙晕了。GJA106兄的Source对我了解JNI很有帮助,hanson_yi兄推荐了一本好书,多谢二位!给分 正规表达式求子字符串 分全给第一个正确答案的人 安装properties插件时,新建一个link文件,却不可用是怎么回事? java如何遍历一个盘下的所有文件?〉 jsp 如何,用正则表达式。获取<img src=0.gif>中的0.gif?????????? 再问包与javac 菜鸟请教高手这个小问题 如何更好的提高自己的技能?大家进来看看 tomcat的超简单问题,百分送上 servlat的显示问题? 关于库的引用问题 我要在转到Red Hat下面作Java开发,我该如何安装Jdk和Jbuilder呢? 我用JBuilder6.0写一段程序,检查那里都没错,就是不能执行,那里错了?
/**
* @version 1.10 1997-07-01
* @author Cay Horstmann
这是printf3.c文件
*/#include "Printf3.h"
#include <string.h>
#include <stdlib.h>
#include <float.h>char* find_format(const char format[])
/**
* @param format a string containing a printf format specifier
* (such as "%8.2f"). Substrings "%%" are skipped.
* @return a pointer to the format specifier (skipping the '%')
* or NULL if there wasn't a unique format specifier
*/
{ char* p;
char* q; p = strchr(format, '%');
while (p != NULL && *(p + 1) == '%') /* skip %% */
p = strchr(p + 2, '%');
if (p == NULL) return NULL;
/* now check that % is unique */
p++;
q = strchr(p, '%');
while (q != NULL && *(q + 1) == '%') /* skip %% */
q = strchr(q + 2, '%');
if (q != NULL) return NULL; /* % not unique */
q = p + strspn(p, " -0+#"); /* skip past flags */
q += strspn(q, "0123456789"); /* skip past field width */
if (*q == '.') { q++; q += strspn(q, "0123456789"); }
/* skip past precision */
if (strchr("eEfFgG", *q) == NULL) return NULL;
/* not a floating point format */
return p;
}JNIEXPORT void JNICALL Java_Printf3_fprint
(JNIEnv* env, jclass cl, jobject out, jstring format,
jdouble x)
{ const char* cformat;
char* fmt;
jstring str;
jclass class_PrintWriter;
jmethodID id_print; cformat = (*env)->GetStringUTFChars(env, format, NULL);
fmt = find_format(cformat);
if (fmt == NULL)
str = format;
else
{ char* cstr;
int width = atoi(fmt);
if (width == 0) width = DBL_DIG + 10;
cstr = (char*)malloc(strlen(cformat) + width);
sprintf(cstr, cformat, x);
str = (*env)->NewStringUTF(env, cstr);
free(cstr);
}
(*env)->ReleaseStringUTFChars(env, format, cformat); /* now call ps.print(str) */ /* get the class */
class_PrintWriter = (*env)->GetObjectClass(env, out); /* get the method ID */
id_print = (*env)->GetMethodID(env, class_PrintWriter,
"print", "(Ljava/lang/String;)V"); /* call the method */
(*env)->CallVoidMethod(env, out, id_print, str);
}以下是printf3.h文件
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Printf3 */#ifndef _Included_Printf3
#define _Included_Printf3
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Printf3
* Method: fprint
* Signature: (Ljava/io/PrintWriter;Ljava/lang/String;D)V
*/
JNIEXPORT void JNICALL Java_Printf3_fprint
(JNIEnv *, jclass, jobject, jstring, jdouble);#ifdef __cplusplus
}
#endif
#endif以下是两个java文件
Print3.java
/**
* @version 1.10 1997-07-01
* @author Cay Horstmann
*/import java.io.*;class Printf3
{ public static native void fprint(PrintWriter out,
String format, double x);
static
{ System.loadLibrary("Printf3");
}
}Print3Test.java
/**
* @version 1.10 1997-07-01
* @author Cay Horstmann
*/import java.io.*;class Printf3Test
{ public static void main(String[] args)
{ double price = 44.95;
double tax = 7.75;
double amountDue = price * (1 + tax / 100);
PrintWriter out = new PrintWriter(System.out);
Printf3.fprint(out,
"Amount due = %8.2f\n", amountDue);
out.flush();
}
}
功能是:通过BCB捕捉鼠标的位置然后传给java程序
我更想知道“通过java捕捉鼠标的位置然后传给BCB程序”!!!
JNI看了两天,还是搞不定呀!