Je vous met ici le code que j'ai pour le moment:
La structure que j'utilise pour tester:
typedef struct t_listeInteraction{
string interaction;
t_listeInteraction* suivant;
}listeInteraction;
Le programme d'écriture:
int main()
{
HANDLE hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,0x4000,"filemap");
listeInteraction* mData = (listeInteraction*)MapViewOfFile(hFileMap,FILE_MAP_ALL_ACCESS,0,0,0);
//Déclaration des variables
listeInteraction* inter1;
listeInteraction* inter2;
listeInteraction* inter3;
listeInteraction* temp;
inter1 = new listeInteraction;
inter2 = new listeInteraction;
inter3 = new listeInteraction;
temp = new listeInteraction;
//Initialisation des variables
inter1->interaction = "Essai";
inter1->suivant = inter2;
inter2->interaction = "CA MARCHE!";
inter2->suivant = NULL;
mData = inter1;
(*inter3).interaction = "La, ca marche vraiment";
(*inter3).suivant = NULL;
while (true)
{
char txt[0xFF];
scanf("%s",&txt);
if (txt == "EXIT")//Soit je quitte
break;
else{//Soit jécrit une troisieme valeur
inter3->suivant = mData;
mData = inter3;
}
}
UnmapViewOfFile(mData);
CloseHandle(hFileMap);
return 0;
}
Le programme de lecture:
int main()
{
HANDLE hFileMap = OpenFileMapping(FILE_MAP_READ,FALSE,"filemap");
listeInteraction* mData = (listeInteraction*)MapViewOfFile(hFileMap,FILE_MAP_READ,0,0,0);
//Déclation de variables
listeInteraction* temp;
temp = new listeInteraction;
while (true)
{
char txt[0xFF];
scanf("%s",&txt);
if (strcmp(txt,"PRINT") == 0) {// Affichage de la variable partagée
temp = mData;
while(temp!=NULL){//Je parcours la liste
cout << temp->interaction << endl;
temp = temp->suivant;
}
}
else if(strcmp(txt,"EXIT") == 0) // Je quitte la boucle
break;
}
UnmapViewOfFile(mData);
CloseHandle(hFileMap);
return 0;
}
|