Bonjour,
je souhaite passer des informations via une Structure jna.
J'ai déja utiliser cette structure pour faire des appel java du c.
Maintenant je souhaiterai en plus passer un certain nombre de donnée...
voici ma Structure:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| package jna.structure;
import jna.interfaceJna.HubOptLibrary;
import jna.interfaceJna.RunSimul;
import jna.interfaceJna.WriteResult;
import com.sun.jna.IntegerType;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
/**
*
* Structur permettant d'envoyer vers le C des pointeurs de fonctions.
*
* @author binot
*
*/
public class StructureCondor extends Structure {
/**
* variable global permettant de contenir le chargement de la lib dll
*/
private HubOptLibrary lib;
private StructureCondor moi = this;
public StructureCondor(HubOptLibrary lib){
this.lib = lib;
}
/******************
*
* pointeur de données
*
* ********************/
public int scanBDO = 1;
/*
public int maxIter = 10;
//public String method = "Test methode";
public double epscon = 0.0;
public double minVar = 0.0;
public double maxVar = 100;
public int npar = 5;*/
//public String[] par_name = {"yann","florent","emilie","clement","mickael"};
/********************
*
* Pointeurs de fonctions
*
* **************************/
public RunSimul runSimul = new RunSimul() {
@Override
public void invoke(int nbIteration) {
for(int i = 0 ; i < nbIteration; i++){
System.out.println("Simulation : "+ i+" commence");
try {
// ici on devrait trouver l'appel pour le lancement des simulations coté java.
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Simulation : "+ i+" termine");
}
lib.envoirResultSimulation(nbIteration, moi);
}
};
public WriteResult writeResult = new WriteResult() {
@Override
public void invoke(Pointer tabp, int taille) {
System.out.println("Je suis dans runSimul \n la table envoye est : ");
int[]tab = tabp.getIntArray(0, taille);
for (int i = 0 ; i < tab.length; i++){
System.out.println("index "+i+" : "+ tab[i]);
}
}
};
} |
le public de public int scanDBO a l'air de causer une erreur ACCES_VIOLATION tels que ceci:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000001, pid=1236, tid=5152
#
# Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing windows-x86)
# Problematic frame:
# C 0x00000001
#
# An error report file with more information is saved as:
# C:\Users\binot\Desktop\HubOptLiaison\testJNI_JNA\worspace\CondorInterfaceJNA4Hubopt\hs_err_pid1236.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
# |
de plus au niveau du c (le code est si dessous), les printf n'indique pas la bonne valeur comme si elles ne trouvaient rien... elles indiquent :
les datas 5636136je suis rentrer dans le mainj appel runSim de java
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include<stdio.h>
typedef struct condorFunctionStruct {
/********************
poiteur de fonctions
**********************/
void (*runSimul)(int nb);
void (*writeResult)(int *tab, int taille);
/*********
poiteur de variables
**********/
int scanBDO;
/*
int *maxIter;
//char *method[20];
double *epscon ;
double *minVar;
double *maxVar ;
int *npar ;*/
// char *par_name [20][5];
} condorFunctionStruct;
int main(condorFunctionStruct *mastruct){
printf("les datas ");
printf(mastruct->scanBDO);
/*
printf(mastruct-> maxIter);
//printf(mastruct->method);
printf(mastruct->epscon);
printf(mastruct->minVar);
printf(mastruct->maxVar);
printf(mastruct->npar);
//printf(mastruct->par_name);
printf("");*/
printf(" je suis rentrer dans le main");
printf(" j appel runSim de javavb dddddddddddddddddddddddddddddddddd ");
mastruct->runSimul(5);
return 5;
}
void envoirResultSimulation(int nb, condorFunctionStruct *mastruct ){
//printf("il y a un nombre de resltat de ; "); printf(nb);
int tab[nb] ;
for(int i = 0 ; i < nb; i++){
tab[i] = i;
}
mastruct->writeResult(tab, nb);
} |
D'ou vient le probleme? on ne peut pas passer des valeurs par les structures ?
Merdci d'avance
Partager