And again I ve got a big problem with this native code...
Well I 'm using a method which takes a string as argument (actually the path of a file here : C:\\Number.tiff)
I call a wrapper dll which calls a method of another dll.
this method is defined like this: IMG LoadImg(const char filename)
So it takes a const char and not a string...the problem is that when I launch my application without converting the string I have a message written : cannot open tiff.That means I succeeded accessing the method of the dll but failed openig the file.
So I decided to convert the string into a char and then java crashes...
here is the piece of code :
JNIEXPORT void JNICALL Java_OCR_OCRlaunch
(JNIEnv *env, jobject cls, jstring str)
{
//const char *str1 = (*env)->GetStringUTFChars(env, str, 0); // this is the conversion part that makes it crash I guess
HMODULE hLib;
long int IMG;
hLib = LoadLibrary("OCRDLL.dll");
if(hLib)
{
FARPROC func = GetProcAddress(hLib,"LoadImg");
if ( func != NULL )
IMG = func(str);
FreeLibrary(hLib);
}
}
If anyone had an idea I'm really getting lost into this native stuff...thanks
1. Remove the const. It cannot be const, because you are assigning it a value.
2. Since you are doing thigs with DLLs, I assume you have VC++. You can debug your wrapper using the VC++ IDE. Just make the "launching program" java.exe, and supply parameters that start your java program.
Actually the code looks fine, since "const char * " means "non-const pointer to const char" rather than "const pointer to non-const char" -- gotta love C!
So, we need more details. Can you debug down to the exact line that fails? Is that an exact copy of your code? It looks like it should not compile, without some casts that are not shown. In fact I'd suggest switching to C++ compilation to make the type checking stricter.
Well thanks for your answers. I compiled it as C++ which avoided me lots of errors.
I changed lots of stuff one hour ago and now it works...Don't really know where the problem was...anyway it works that's the most important and I finally understood a little more about C++.
Thanks men!
Did you succeed into using the ocrdll.dll lirbary in Java? Could you give me the steps or files to achieve this? I am interested into embedding ocr in a Java app...