calling main(int argc, char **argv) function from Java

306 views
Skip to first unread message

Abhi

unread,
Apr 12, 2010, 10:24:56 AM4/12/10
to android-ndk
Hi

Can we call the 'main' function in C from Java? How will I pass
parameters to the main function? I basically want to pass a filename
in 'argv' which will be used in the C code for further processing.
Also, where will I locally store this file? When I run only the C
code, I have to save the file in the Project directory itself. How
different would it be when run through Java?

thanks,

Abi

mic _

unread,
Apr 12, 2010, 10:39:01 AM4/12/10
to andro...@googlegroups.com
JNIEXPORT jint JNICALL Java_com_foo_bar_Bar_main(JNIEnv *ioEnv,
jobject ioThis, jstring filename)
{
const char *str;
str = ioEnv->GetStringUTFChars(fileName, NULL);
if (str == NULL)
{
return -1; /* OutOfMemoryError already thrown */
}

// Use str here...
// ...

ioEnv->ReleaseStringUTFChars(fileName, str);


return 0;
}

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages