Article View: borland.public.jbuilder.java.language
Article #19868Re: Native Methods and Borland C++
From: Gail Schultz
Date: Mon, 01 Dec 1997 00:00
Date: Mon, 01 Dec 1997 00:00
75 lines
2463 bytes
2463 bytes
Hi,
I don't know about all of your problems, but I do know that if you are using
C++, this is how you use env:
const char *str = (env->GetStringUTFChars(prompt,0));
return (env->NewStringUTF(buf));
env->ReleaseStringUTFChars(prompt, str);
There is some documentation on JNI and C++ in
sun\docs\books\tutorial\native1.1\implementing
-Gail
Philippe Thiran wrote:
> Hi,
>
> I have a problem with native methods. I use Borland C++ version 4.52 to
> compile my .c++ file into a .dll file. The problem is the probem
> presented in the SUN JAVA tutorial (the Prompt.java problem).
> In the header, I include the jni.h file and prompt.h (like in the SUN
> tutorial). When I compile my C++ project, I have compilation errors in
> my Prompt.h and also in my Prompt.c like this :
>
> Prompt.h :
> *********
>
> /* DO NOT EDIT THIS FILE - it is machine generated */
> #include <jni.h>
> /* Header for class Prompt */
>
> #ifndef _Included_Prompt
> #define _Included_Prompt
> #ifdef __cplusplus
> extern "C" {
> #endif
> /*
> * Class: Prompt
> * Method: getLine
> * Signature: (Ljava/lang/String;)Ljava/lang/String;
> */
> JNIEXPORT jstring JNICALL Java_Prompt_getLine
> (JNIEnv *, jobject,
> jstring);
> <------------- Erreur Prompt.H : 'Java_Prompt_getLine' is not a
> parameter in function __declspec
>
> #ifdef __cplusplus
> }
> #endif
> #endif
>
> Prompt.c
> *******
>
> #include <stdio.h>
> #include <jni.h>
> #include "Prompt.h"
>
> JNIEXPORT jstring JNICALL
> Java_Prompt_getLine(JNIEnv *env, jobject obj, jstring prompt)
> <-------------Errors : Declaration was expected in function __declspec;
> Undefined symbol 'env' in function __declspec; Undefined symbol 'prompt'
> in function __declspec
>
> {
> char buf[128];
> const char *str = (*env)->GetStringUTFChars(env, prompt, 0);
> printf("%s", str);
> (*env)->ReleaseStringUTFChars(env, prompt, str);
> scanf("%s", buf);
> return (*env)->NewStringUTF(env, buf);
> }
>
> What is the error ????
>
> Thanks.
Technical Details
Message-ID:
<3482C9FC.D9F28E8D@optinfo.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<347ADB55.7DFE8579@info.fundp.ac.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,bf469ddf9833b941 X-Google-Attributes: gidf74b3,public From: Gail Schultz <gails@optinfo.com> Subject: Re: Native Methods and Borland C++ Date: 1997/12/01 Message-ID: <3482C9FC.D9F28E8D@optinfo.com> X-Deja-AN: 294203537 References: <347ADB55.7DFE8579@info.fundp.ac.be> Organization: None Newsgroups: borland.public.jbuilder.java.language