是否想用VC ++ dll集成JAVA,有没有快速简便的方法? [英] Want to integarte JAVA with VC++ dlls is there any fast and easy way?
本文介绍了是否想用VC ++ dll集成JAVA,有没有快速简便的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JAVA中有一个应用程序,在VC ++中有一个具有很多DLL的应用程序.
我想要它们之间的进程间通信.
我想用VC ++ dll将JAVA集成在一起,有没有快速简便的方法.
在此先感谢
Nilesh
I have an application in JAVA and another in VC++ with lot of DLLs.
I want interprocess communication between them.
I Want to integarte JAVA with VC++ dlls is there any fast and easy way.
Thanks in advance
Nilesh
推荐答案
如果您有dll的代码,那么这里是一个解决方案...
1)在要使用的ur dll项目中创建头文件"abc.h".
2)在此头文件中,粘贴以下代码.
#include"jni.h"
/* abc类的标题*/
#ifndef _Included_abc
#define _Included_abc
#ifdef __cplusplus
extern"C" {
#endif
/*
*类别:abc
*方法:ConvertFile
*签名:(Ljava/lang/String; Ljava/lang/String; Ljava/lang/String; J)Z
*/
JNIEXPORT jboolean JNICALL Java_ttslmcci_ConvertXML_ConvertFile
(JNIEnv *,jobject,jstring,jstring,jstring,jlong);
#ifdef __cplusplus
}
#endif
#endif
3)现在在dll项目cpp文件中#include"abc.h"
4)将以下代码粘贴到c#文件中,其中u #included abc.h文件
JNIEXPORT jboolean JNICALL Java_abc_ConvertFile
(JNIEnv * env,jobject,jstring jstrInputFile,jstring jstrOutputFile,jstring,jlong)
{
jboolean bRet = true; //检查
//将Java字符串转换为MFC字符串..
BSTR bstrInputFile;
BSTR bstrOutputFile;
//将jstring转换为C ++常量字符串
const unsigned short * strA =(env)-> GetStringChars(jstrInputFile,&bRet);
const unsigned short * strB =(env)-> GetStringChars(jstrOutputFile,&bRet);
//将C ++字符串转换为BSTR
bstrInputFile =(BSTR)strA;
bstrOutputFile =(BSTR)strB;
CXMLSL objXMLSL; //这是包含开始使用dll功能的方法的类
objXMLSL.ConvertFile(bstrInputFile,bstrOutputFile);
//ConvertFile是dll中的启动方法,需要调用
(env)-> ReleaseStringChars(jstrInputFile,strA); //释放jstring
(env)-> ReleaseStringChars(jstrOutputFile,strB); //释放jstring
return bRet;
}
If u have the code for the dlls then here is a solution......
1) Create a header file "abc.h" in the project of ur dll which u want to use.
2) In this header file, paste the following code.
#include "jni.h"
/* Header for class abc */
#ifndef _Included_abc
#define _Included_abc
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: abc
* Method: ConvertFile
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)Z
*/
JNIEXPORT jboolean JNICALL Java_ttslmcci_ConvertXML_ConvertFile
(JNIEnv *, jobject, jstring, jstring, jstring, jlong);
#ifdef __cplusplus
}
#endif
#endif
3) Now #include "abc.h" in the dll project cpp file
4) Paste the following code in the cpp file where u #included abc.h file
JNIEXPORT jboolean JNICALL Java_abc_ConvertFile
(JNIEnv *env, jobject, jstring jstrInputFile, jstring jstrOutputFile, jstring, jlong)
{
jboolean bRet = true; //check
// Convert Java string into MFC string ..
BSTR bstrInputFile;
BSTR bstrOutputFile;
// convert jstring to a C++ constant string
const unsigned short* strA = (env)->GetStringChars(jstrInputFile, &bRet);
const unsigned short* strB = (env)->GetStringChars(jstrOutputFile, &bRet);
// convert the C++ string to BSTR
bstrInputFile = (BSTR) strA;
bstrOutputFile = (BSTR) strB;
CXMLSL objXMLSL; // This is the class that contains the method to start using the functionality of the dll
objXMLSL.ConvertFile( bstrInputFile, bstrOutputFile);
// ConvertFile is the starting method that is in the dll, that needs to be called
(env)->ReleaseStringChars(jstrInputFile, strA); // release jstring
(env)->ReleaseStringChars(jstrOutputFile, strB); // release jstring
return bRet;
}
这篇关于是否想用VC ++ dll集成JAVA,有没有快速简便的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文