Bonjour a tous,
mon probleme est le suivant : je dois realiser une classe qui me permette d'executer un thread de reception a chaque instance car g plusieurs port
j'ai une erreur a la compilation du genre :
D:\_stage_2004\test-rs3\rs3\rs3.cpp(64) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__cdecl *)(void *)'
None of the functions with this name in scope match the target type
et le .cpp
// rs3.cpp: implementation of the rs3 class.
//
//////////////////////////////////////////////////////////////////////
#include "rs3.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
rs3::rs3()
{
hComPort = CreateFile(TEXT("COM1:"),GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
HANDLE g_hSendEvent = INVALID_HANDLE_VALUE;
HANDLE hReadThread = INVALID_HANDLE_VALUE;
}
// ne fonctionne pas encore
rs3::rs3(char *ch)
{
hComPort = CreateFile(TEXT("ch"),GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
}
rs3::~rs3()
{
}
//---------------- Init---------------------------------
bool rs3::init(){
if (hComPort != INVALID_HANDLE_VALUE)
{
//On configure le port serie, d'abord on accede a son etat courant
GetCommState(hComPort,&dcb) ;
//puis on modifie les champs que l'on veut initialiser
dcb.BaudRate = CBR_9600 ; //vitesse de communication
dcb.fParity = FALSE ; //validation (ou non) du controle de parite
dcb.fDtrControl=DTR_CONTROL_DISABLE ; //pas de controle de flux materiel
dcb.fOutX=FALSE ; //pas de controle de flux logiciel en sortie
dcb.fInX=FALSE; //pas de controle de flux logiciel en entree
dcb.fNull=FALSE ; //on conserve les char NULL reçus
dcb.ByteSize=8; //largeur des donnees
dcb.Parity=NOPARITY; //type de parite associee aux donnees
dcb.StopBits=ONESTOPBIT; //nb de bits de stop
//puis on initialise le port
SetCommState(hComPort,&dcb) ;
//On fixe maintenant les differentes valeurs des timeouts
/*Timeouts infinis
cto.ReadIntervalTimeout=0;
cto.ReadTotalTimeoutConstant=0 ;
cto.ReadTotalTimeoutMultiplier=0;
cto.WriteTotalTimeoutConstant=0;
cto.WriteTotalTimeoutMultiplier=0;
SetCommTimeouts(hLocal,&cto) ;
//DEBUG
wsprintf(szBuffer,TEXT("Port serie COM1 ouvert et initialise\r\n")) ;
SetWindowText(hTB3,szBuffer); */
printf("Port serie ouvert\n");
//On retourne le handle du port ouvert
// start read thread if not already started
//=============erreur signalée par le compilo=========================================
if(!GetExitCodeThread (hReadThread, &dwTStat) || (dwTStat != STILL_ACTIVE) ){
hReadThread = CreateThread(NULL, 0, readThread, hWnd, 0, &dwTStat);
if(hReadThread)
CloseHandle(hReadThread);
}
return true ;
}
else
{
//DEBUG
// wsprintf(szBuffer,TEXT("Erreur d'ouverture de COM1\r\n")) ;
// SetWindowText(hTB3,szBuffer);
printf("Port serie non ouvert\n");
//On retourne le handle d'erreur
return false ;
}
}
//------------ Fonction du thread de lecture----------------------------------
DWORD WINAPI rs3::readThread (PVOID pArg){
// variables
DWORD cBytes, i;
BYTE szText[256], *pPtr;
TCHAR tch;
hWnd=(HWND)pArg;
while(TRUE){
tch = 0;
pPtr = szText;
for(i=0;i < sizeof(szText)- sizeof(TCHAR);i++){
while(!ReadFile(hComPort, pPtr, 1, &cBytes, 0 ))
if(hComPort == INVALID_HANDLE_VALUE)
return 0;
//synchronisation en format unicode masque
tch = (tch <<8) & 0xFF00;
tch |= *pPtr++;
if(tch == TEXT('\n'))
break;
}
*pPtr++=0;
*pPtr++=0;
//gdsfgsdf
if(i%2){
pPtr = szText;
while(*pPtr || *(pPtr+1)){
*pPtr = *(pPtr+1);
pPtr++;
}
*pPtr = 0;
}
//SendDlgItemMessage(hWnd, ID_RCVTEXT, EM_REPLACESEL, 0, (LPARAM)szText);
printf("voici le message + %s",&pPtr);
}
return 0;
};
//------------------- fermer -------------------------------------------
bool rs3::fermer(){
//On ferme le port serie (s'il est a ete ouvert sans erreur)
if(hComPort!=NULL)
{
CloseHandle(hComPort);
return true;
}
else
return 0;
}
//------------- emettre ---------------------------------------------------
bool rs3::emettre(char *txt){
DWORD NumBytes=0;
if(hComPort!=NULL)
{
// pas d'erreur
// g_ErrCom=e_ErrCom_None;
//Emission du buffer
if(WriteFile(hComPort,txt,strlen(txt),&NumBytes,NULL)==0)
{
//Erreur lors de l'émission
return false;
}
return true;
}
else
//Le port n'a pas été ouvert
return false;
}
//--------------- purger -------------------------------------------------
void rs3::purger(){
PurgeComm(hComPort,PURGE_TXCLEAR);
PurgeComm(hComPort,PURGE_RXCLEAR);
}
//====================== MAIN =============================================================
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int CmdShow)
{
rs3 *mrs;
char *t="COM2:/0";
mrs = new rs3();
printf("construteur\n");
mrs->init();
printf("init effectee\n");
mrs->emettre("salut");
printf("emission faite\n");
mrs->purger();
mrs->fermer();
printf("connexion fermée\n");
return 0;
}
je developpe sous microsoft embedded C++
voila merci de m'aider
Et pourvu qu'ca dure