1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| /* tu es toujours mieux de placer tes define hors fonction */
#define ARCVALUEBEFORE 1
/* Ceci dit, il est préférable de créer une constante:
* const long ARCVALUEBEFORE = 1
*/
JNIEXPORT jfloat JNICALL Java_appli_InterfacePI_piar_1value
(JNIEnv *env, jobject obj, jint numpt, jint date)
{
/* On crée une variable de stockage pour la dll */
HINSTANCE PIAPI32;
/* On charge la dll */
PIAPI32 = LoadLibrary("piapi32.dll");
if (PIAPI32 != NULL)
{
/* la déclaration d'une variable suffit pour que C++ prévoie
* l'espace mémoire suffisant pour la stocker
*/
char type;
long int iStat; // au fait: long iStat va très bien aussi :D
float rval;
long int mode;
/* On a besoin du type du point pour connaitre la valeur à retourner */
typedef long int (*_pipt_pointtype)(long int,char&);
_pipt_pointtype pipt_pointtype;
pipt_pointtype = (_pipt_pointtype)GetProcAddress(PIAPI32, "pipt_pointtype");
pipt_pointtype(numpt,*type);
typedef long int (*_piar_value)(long int,long int&,long int,float&,long int&);
_piar_value piar_value;
*mode=ARCVALUEBEFORE;
/* On interface la fonction C++ avec la fonction de la dll */
piar_value = (_piar_value)GetProcAddress(PIAPI32, "piar_value");
/* On applique la fonction */
piar_value(numpt,date,mode,rval,iStat);
/* On libère la dll */
FreeLibrary(PIAPI32);
if (type=='R')
{
return rval;
}
else if (type=='D')
{
/* On convertit l'entier en float */
return reinterpret_cast<float&>(iStat);
}
}
} |
Partager