Un peu de code.
Mon fichier Communication.h :
#ifndef COMMUNICATION_H
#define COMMUNICATION_H
#ifdef _DLL
#ifndef _AFXDLL
#define _AFXDLL
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <afx.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
#include "..\ParamSerie.h"
class Communication
{
public :
Communication();
~Communication();
vector<LPBYTE> * lesPorts;
void detecterPorts();
ParamSerie * param;
int ouvrir(ParamSerie * config); // Permet d'ouvrir la communication
int fermer(ParamSerie * config); // Permet de fermer la communication
int envoyer(ParamSerie * config, const void * telBuffer, int telleTailleBuffer); // Permet d'envoyer des octets sur la liaison série
char* recevoir(ParamSerie * config, int * telCodeErreur); // Permet de recevoir des octets sur le liaison série
int configurer(ParamSerie * config); // Permet de configurer la communication
int charger(ParamSerie * config, char * telCheminFichier, vector<int> * tellesErreurs); // Permet de charger une configuration depuis un fichier
int sauver(ParamSerie * config, char * telCheminFichier); // Permet de sauver une configuration dans un fichier
};
#endif
Constructeur dans Form1.h :
Form1(void)
{
InitializeComponent();
//
//TODO : ajoutez ici le code du constructeur
//
com = new Communication();
// on charge la configuration
vector<int> lesCodesErreur;
int leRetour = com->charger(com->param,CHEMIN_CONFIGCOM,&lesCodesErreur);
if(com->lesPorts == NULL || com->lesPorts->size()==0)
{
System::Windows::Forms::MessageBox::Show("Aucun port série","Erreur port",MessageBoxButtons::OK,MessageBoxIcon::Error);
return;
}
else
for(unsigned int i=0; i<com->lesPorts->size(); i++)
{
// System::String^ portAAjouter = gcnew ;
CBoxPorts->Items->Add(gcnew String((char*)(*com->lesPorts)[i]));
}
String^ nomPortStr = gcnew String(com->param->nomPort);
int indexPort = CBoxPorts->FindStringExact(nomPortStr,0);
delete nomPortStr;
if( indexPort==CB_ERR )
{
CBoxPorts->SelectedIndex = 0;
CString portSelectionne = CBoxPorts->SelectedItem->ToString();
com->param->changerPort((char*)(LPCTSTR)portSelectionne);
}
else
CBoxPorts->SelectedIndex = indexPort;
}// Form1
A+