We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Call Aspose Total methods for java with JNI in C++

Hello guys
Can we use JNI for calling Aspose for java methods in C++?

Hi,

Generally, you can call Java methods from JNI code as per http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniref.html#call

Please let us know which products' code you planned to invoke and product team will comment if such work has been tested.

Hi
For example, we want to use Aspose.word for java in C++.
Is it possible for us to call Aspose methods from C++.
Thanks

Check this article http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/utilize-aspose-words-in-other-programming-languages.html

We don't have examples for C++ yet, but let us know if you can figure things out from there.

Hello again
for calling Java method with JNI from C++.
public Methods need to be a native.
Are methods in Aspose.total for java be a native?

Hi,

Here is sample code that creates an instance of Document class and calls its Save method from native C++ code with the help of JNI:

JNIEXPORT jint JNICALL Java_com_test_JNI_native_test(JNIEnv *pEnv, jobject obj, jint value){
jclass words_doc = pEnv->FindClass("com/aspose/words/Document");
if (words_doc) {
jmethodID method = pEnv->GetMethodID(words_doc,"","()V");
if (method) {
jobject docInstance = pEnv->NewObject(words_doc, method);
if (docInstance) {
jmethodID savemethod = pEnv->GetMethodID(words_doc,"save","(Ljava/lang/String;)V");
if (savemethod) {
jstring data = pEnv->NewStringUTF("C:\\out.doc");
pEnv->CallVoidMethod(docInstance, savemethod, data);
pEnv->DeleteLocalRef(data);
}else {
printf( "No save method\n" );
}
}else {
printf( "No docs instance\n" );
}else {
printf( "No words method\n" );
}else {
printf( "No words_doc\n" );
}

if (pEnv->ExceptionOccurred()) return 0;

.....

}

PS As you know, if you want to call Java methods from JNI, you might need to use javap tool to discover method signatures. For example, if you want to know what to pass to Document class methods or how to invoke class constructor, the command line would be

javap -classpath Aspose.Words.jdk16.jar -s com.aspose.words.Document

PPS Be sure to have aspose.words.jar in your CLASSPATH before running the sample, otherwise you'll get 'No words_doc' and NoClassDefFound exception after that