I've tried cutting and pasting the code example from the java tutorial
but it did not work. Does anyone know how to do this.
PS. I don't know very much about C.
Here is a copy of the dll I am trying to make to.
------------------------------------------------------------------------------------------------------
#ifndef _execCom_H
#define _execCom_H
#include <iostream.h>
#include "setDir.h"
#include <jni.h>
#include <stdlib.h>
#include <dir.h>
JNIEXPORT void JNICALL Java_setDir_execute
(JNIEnv *env, jclass, jstring wd, jstring com)
{
char buf[128];
const char *WD = (*env)->GetStringUTFChars(env, wd, 0);
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, wd, str);
chdir(WD);
//system(com);
}
#endif _execCom_H
JNIEXPORT jlong JNICALL Java_rtjc_CMisc_cdNative
(JNIEnv* env, jobject this_obj, jstring dir)
{
char *newDir;
newDir = (*env)->GetStringUTFChars(env, dir, 0);
if(_chdir(newDir)!=0)
printf("Failed to change directory to %s\n",newDir);
else
printf("Directory changed to: %s\n",newDir);
(*env)->ReleaseStringUTFChars(env, dir, newDir);
}
Tim Bosley wrote in message <36F134B0...@hotmail.com>...
You almost have it right. But you need to copy from the character
pointer into a character string. Also, your code snippet is a bit
mixed up in the variables names used: you were referencing "str"
instead of "WD".
JNIEXPORT void JNICALL Java_setDir_execute
JNIEnv *env, jclass, jstring wd, jstring com)
{
char buf[128];
const char *WD = (*env)->GetStringUTFChars(env, wd, 0);
strcpy( buf, WD );
printf("%s", buf);
(*env)->ReleaseStringUTFChars(env, wd, WD);
chdir(buf);
...
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
This is C not C++ form of call -- to transform just take off a level of
indirection and remove the first parm:
(*env)->INTERFACENAME(env,PARMS);
becomes
env->INTERFACENAME(PARMS);
--
___ _ Blair Wyman bwy...@home.com
( /_) / _ ' _ Systems Programmer
_/__)_/_<_/_/_/_' In continuous operation since 1957.