Calimero79 Calimero79 - 1 year ago 132
C++ Question

Invalid Arguments C++ cygwin

I have for work to modify an old dll written in 2005 in c++.
I have installed Eclipse Oxygen, cygwin with gcc, gdb and make.

I have searched in many places, made many changes in my project properties but my problem is here anyway : I have 5 errors "Invalid Arguments".

my code :

#include <jni.h>
#include "core_dll_ModDriver.h"
#include <stdio.h>
#include <iostream>

JNIEXPORT jobjectArray JNICALL Java_core_dll_ModDriver_EtatSupport(JNIEnv * env, jobject o)
{
const int nbFen = 4;
const char FAR* name = "EtatSupport";
char* fen1 = NULL;
char* fen2 = NULL;
char* fen3 = NULL;
char* fen4 = NULL;
loadDll();
if ( isDllLoaded() )
{
typedef unsigned char ( __stdcall * Function)( char*, char*, char*, char* );
Function function = (Function)getDllFunction( name );
if ( function != NULL )
{
char error = function ( fen1, fen2, fen3, fen4 );
}
else
std::cout << "echec" << name;
closeDll();
}
jobjectArray result = env->NewObjectArray( nbFen, env->FindClass("java/lang/String"), NULL );
jstring jfen1 = env->NewStringUTF( fen1 );
jstring jfen2 = env->NewStringUTF( fen2 );
jstring jfen3 = env->NewStringUTF( fen3 );
jstring jfen4 = env->NewStringUTF( fen4 );

env->SetObjectArrayElement( result, 0, jfen1 );
env->SetObjectArrayElement( result, 1, jfen2 );
env->SetObjectArrayElement( result, 2, jfen3 );
env->SetObjectArrayElement( result, 3, jfen4 );
return result;
}


And I have "Invalid Arguments" with NewObjectArray, and all SetObjectArray.

Line 27 Invalid arguments'
Candidates are : _jobjectArray * NewObjectArray(?,_jclass *,_jobject *)'
Line 33,34,35,36 Invalid arguements'
Candidates are : void SetObjectArrayElement(_jobjectArray *,?,_jobject *)'

Answer Source

The first thing to realize is that the "Invalid arguments" error you're getting is coming from Eclipse's own code analysis, not from the compiler. It shouldn't actually be blocking you from building or running your code, it's just an annoyance.

Having established that, the cause of this error is usually a problem with the project configuration, and may be specific to the platform, Java version, etc. (I, for example, do not get such errors on this code on Linux, with GCC 6 and Java 8).

As @Msalters already pointed out in a comment, the errors seem to be caused by Eclipse not being able to resolve the type jsize. To investigate this, I would open up the header jni.h (you can do via "Open Declaration" on the #include for it), find the definition of jsize, and see if there's anything there that might indicate why it doesn't resolve. To rectify the problem, you may need to make adjustments to your project configuration such as specifying additional include paths or defining additional macros.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download