Zhao Wenqiang

Greenhorn
+ Follow
since Jul 18, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Zhao Wenqiang

I write a java class:
/***********************/
package Debug;
public class Client
{
public static void main(String[] args)
{
System.out.println("An aaaaaaaaaaa");
}
}
/************************/
I want to call it from Visual c++ with JNI.
for the "Package" problem, I can not call this
class. If i delete the line of "package Debug;",
i can call this class.
I Define USER_CLASSPATH "C:\\OpenORB-1.1.0\\zwq_tmp\\vc6++\\COMtest\\Debug\\" or define "C:\\OpenORB-1.1.0\\zwq_tmp\\vc6++\\COMtest\\" , they are both refuse to work.
Please help me. Thank you very much.
// Object1.cpp : CObject1
#include "stdafx.h"
#include "Object1.h"
#include <jni.h>
#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else /* UNIX */
#define PATH_SEPARATOR ':'
#endif
#define USER_CLASSPATH "C:\\OpenORB-1.1.0\\zwq_tmp\\vc6++\\COMtest\\Debug\\" /* where Prog.class is */
//#define USER_CLASSPATH "." /* where Prog.class is */
// CObject1

STDMETHODIMP CObject1::get_helloword(char ** pVal)
{
// TODO: 在此添加实现代码
*pVal=(char *)malloc(30);
//*pVal="Zhao Wenqiang Hello Word";

JNIEnv *env;
// void **env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
char classpath[1024];

/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = 0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
/* Append USER_CLASSPATH to the end of default system class path */
sprintf(classpath, "%s%c%s",
vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
vm_args.classpath = classpath;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
fprintf(stderr, vm_args.classpath);
//cls = env->FindClass("zwq_module.Client");
cls = env->FindClass("Client");
if (cls == 0) {
fprintf(stderr, "\nCan't find Client class\n");
exit(1);
}

mid = env->GetStaticMethodID(cls, "Hello", "([Ljava/lang/String V");
if (mid == 0) {
fprintf(stderr, "Can't find Prog.main\n");
exit(1);
}
jstr = env->NewStringUTF(" from C!");
if (jstr == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
args = env->NewObjectArray(1,
env->FindClass("java/lang/String"), jstr);
if (args == 0) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
// *HelloWordString=env->CallObjectMethod(cls, mid, args);
env->CallStaticVoidMethod(cls, mid, args);
jvm->DestroyJavaVM();

return S_OK;
}
STDMETHODIMP CObject1: ut_helloword(char * newVal)
{
// TODO: 在此添加实现代码
return S_OK;
}
zhaowq@sina.com
21 years ago