Bonjour,

Je me présente à vous car je me trouve face à un problème qui me laisse dans une impasse totale.
Le principe de mon programme est de récupérer une fonction, préalablement compiler sous Matlab sous forme de DLL, dans un programme C.
Ici je dois uniquement récupérer une simple fonction addition.
Je crée donc un projet sous visualexpress 2008, puis saisie mon code comme expliquer sur plusieurs tutoriels du web en incluant au projet les headers et libraries nécessaires.
Lors de la compilation aucun problème, mais lorsque je veut l'éxécuter je récupère le message d'erreur suivant:
exception non gérée à 0xc0000005: access violation
Pour la pile des appels la compilation s'arrête à: testmatrix32.exe!main()ligne 85+0xe octets
Je suppose que cela doit être du à un problème de pointeurs mais je ne trouve vraiment aucune solutions.

Voici mon programme:


double addition(int t1, int t2);//prototype de la fonction simulée

int main(int argc, char **argv)
{
mclmcrInitialize();
return mclRunMain((mclMainFcnType)run_main,0,NULL);
}

int run_main(int argc, char **argv)
{
double m;
int t1=44;//nombre 1
int t2=22;//nombre 2

m=addition(t1,t2);//appel de la fonction simulée

printf("The value of added matrix is:%4.2f\t\n",m);//affichage résultat
getchar();//permet de ne pas fermer la fenêtre après éxécution
return 0;
}

double addition(int t1, int t2)
{
mxArray *in1, *in2; /* Define input parameters */
mxArray *out;/* and output parameters to be passed to the library functions */
int i=0, j=0; /* loop index variables */
int r=0, c=0; /* variables to store the row and column length of the matrix */
double *data; /* variable to point to the double data stored within the mxArray */
double a[]={0};//tableaux
double b[]={0};

a[0]=t1;//affectation des variables
b[0]=t2;//affectation des variables

mclmcrInitialize();//initialisation du compiler matlab

if( !mclInitializeApplication(NULL,0) )
{
printf("Could not initialize the application.\n");
return 5;
}

in1 = mxCreateDoubleMatrix(1,1,mxREAL);//création matrice 1x1
in2 = mxCreateDoubleMatrix(1,1,mxREAL);//création matrice 1x1
memcpy(mxGetPr(in1), a , 1*sizeof(double));//affectation des valeurs à la matrice
memcpy(mxGetPr(in2), b , 1*sizeof(double));//affectation des valeurs à la matrice

if (!libmatrixInitialize())
{
fprintf(stderr,"Could not initialize the application.\n");

return 8;
}
else
{
mlfAddmatrix(1,&out,in1,in2);
printf("The value of added matrix is:\n");

/* Get the size of the matrix */
r = mxGetM(out);
c = mxGetN(out);
/* Get a pointer to the double data in mxArray */
data = mxGetPr(out);
mxDestroyArray(out); out=0;
/* Loop through the data and display the same in matrix format */
for( i = 0; i < c; i++ )
{
for( j = 0; j < r; j++)
{
printf("%4.2f\t",data[j*c+i]);
}
printf("\n");
}
printf("\n");

libmatrixTerminate();
mxDestroyArray(in1); in1=0;
mxDestroyArray(in2); in2=0;
}

mclTerminateApplication();

return data[(j-1)*c+(i-1)];
}

Merci pour aide.
Cordialement.