[英]pass string parameter jni
I want to pass string as a parameter in with my jni. 我想用jni传递字符串作为参数。 but when I pass the string; 但是当我传递字符串时; the received string is just a meaning less characters. 接收到的字符串只是一个含义较少的字符。 In fact I cant pass my desired string from java to my C# function. 实际上,我无法将所需的字符串从Java传递给C#函数。
what should I do? 我该怎么办?
Edit : 编辑:
jin.java: jin.java:
public static native void myFunc( String name);
jin.cs: jin.cs:
public static void java_framewindow_myFunc(int env,int object,string name)
{
messagebox.show(name);
}
and I send string "Hi" from java, but the string shown in message box is meaningless. 并且我从Java发送了字符串“ Hi”,但是消息框中显示的字符串毫无意义。
Edit2: here is my complete c# code : Edit2:这是我完整的C#代码:
using System;
using ObjectOrientedJNI;
using System.Windows.Forms;
namespace CSharpInJava {
public class NativeJavaMethods {
static void Java_FrameWindow_myFunc(int env, int obj, string name){
messagebox.show(name);
}
}
}
and here is my complete java code: 这是我完整的Java代码:
import java.awt.Canvas;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
public class FrameWindow extends Canvas {
int ref = 0;
//Called by JVM to create Canvas' Peer
public void buttom_clicked() {
myFunc("hi");
}
native int myFunc(String name);
}
what am I missing? 我想念什么?
I have not used JNI with C#, but with C/C++ your native code should receive a jstring type, instead of string as follows: 我没有在C#中使用JNI,但是在C / C ++中,您的本机代码应接收的是jstring类型,而不是字符串,如下所示:
static void Java_FrameWindow_myFunc(int env, int obj,
jstring name)
Typically, JNI documentation is poor (even more so with C# it seems) so turning to the JNI Specification is a good idea. 通常,JNI文档很差(似乎在C#中更是如此),因此转向JNI规范是一个好主意。 Note that JNI uses modified UTF-8 strings. 请注意,JNI使用修改后的UTF-8字符串。
EJP is correct, your whole signature is incorrect. EJP是正确的,您的整个签名是不正确的。 See Native Method Arguments in the JNI Spec for more detail. 有关更多详细信息,请参见JNI规范中的本机方法参数 。
static void Java_FrameWindow_myFunc(
JNIEnv *env, /* interface pointer */
jobject obj, /* "this" pointer */
jstring s) /* argument #1 */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.