Using JNIEnv In Native Method

C

cppaddict

I have a very simple JNI function that returns a jstring type, but I
can't get it to compile. My implementation file looks like this:

#include <jni.h>
#include "HelloWorld.h"
#include <iostream>
#include <string>

JNIEXPORT jstring JNICALL Java_HelloWorld_getHelloWorld
(JNIEnv *env, jobject obj)
{
std::string str = "Hello World";
return (*env)->NewStringUTF(env,str.c_str()); //COMPILER ERROR
}

The compiler error is:

Error E2288 HelloWorld.cpp 10: Pointer to structure required on left
side of -> or ->* in function __stdcall
Java_HelloWorld_getHelloWorld(JNIEnv_ *,_jobject *)

I followed the example at the bottom of this page:

http://java.sun.com/docs/books/tutorial/native1.1/implementing/string.html

so I don't know what's going wrong. Can anyone help?

Thanks,
cpp
 
G

Gordon Beaton

I have a very simple JNI function that returns a jstring type, but I
can't get it to compile.
[...]

return (*env)->NewStringUTF(env,str.c_str()); //COMPILER ERROR

In C it looks like this:

(*env)->(env,foo);

In C++, it's like this:

env->(foo);

/gordon
 
C

cppaddict

return (*env)->NewStringUTF(

this is CPP, so you just say env->NewStringUTF
You used the C form.[/QUOTE]

Gordon and Roedy,

Thank you both. I wasn't aware there were 2 forms.

cpp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top