设置字符串属性(SWIG、Java)时终止JRE
我正在使用SWIG访问Java中的DLL。除了将字符串值设置为char*,大多数事情都可以正常工作。然后,JRE将被终止 例h:设置字符串属性(SWIG、Java)时终止JRE,java,visual-studio,swig,Java,Visual Studio,Swig,我正在使用SWIG访问Java中的DLL。除了将字符串值设置为char*,大多数事情都可以正常工作。然后,JRE将被终止 例h: typedef struct { char* name; int number; } MyStruct; 例一: %module example %{ #include "example.h" %} %include "example.h" 爪哇: 我还尝试使用字节数组: 示例一(新增): Java文件的生成工作正常,但构建崩溃: "jstring
typedef struct {
char* name;
int number;
} MyStruct;
例一:
%module example
%{
#include "example.h"
%}
%include "example.h"
爪哇:
我还尝试使用字节数组:
示例一(新增):
Java文件的生成工作正常,但构建崩溃:
"jstring cannot convert to jbyteArray"
的包装代码表示:
SWIGEXPORT jbyteArray JNICALL Java_bla_VERSION_1DLL_1get(JNIEnv *jenv, jclass jcls) {
...
if (result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
那有点像虫子吗?使用“variable.i”应该可以,为什么它会生成带有“string”而不是“NewCharArray”的东西呢
我正在使用VS Express 2015、SWIG 3.0.10、Java 7以及x86中的所有内容。我放弃了,并在包装器dll中添加了一些设置程序 这些二传手表演“弦乐魔术”: 这很难看,但目前还有效
"jstring cannot convert to jbyteArray"
SWIGEXPORT jbyteArray JNICALL Java_bla_VERSION_1DLL_1get(JNIEnv *jenv, jclass jcls) {
...
if (result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
void SetMyStructName(Object* obj, char* newString)
{
char *b = new char[strlen(newString) + 1]{};
std::copy(newString, newString + strlen(newString), b);
obj->mystruct.name = b;
}