Alors voilà la solution :
// Meteo.h ( THREAD DE COMMUNICATION SOCKET)
#if !defined(AFX_METEO_H__4BB4970B_F2ED_4E97_9C58_24835AA71B7C__INCLUDED_)
#define AFX_METEO_H__4BB4970B_F2ED_4E97_9C58_24835AA71B7C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Meteo.h : header file
//
#include "PrimsolClimatDoc.h"
#include "CommSocket.h"
/////////////////////////////////////////////////////////////////////////////
// CMeteo thread
class CMeteo : public CWinThread
{
DECLARE_DYNCREATE(CMeteo)
protected:
CMeteo(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
int Run();
void setDoc(CPrimsolClimatDoc * doc) { m_pDonnees = doc;}
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMeteo)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~CMeteo();
// Generated message map functions
//{{AFX_MSG(CMeteo)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_Port;
CString m_IPSrv;
CPrimsolClimatDoc * m_pDonnees;
CCommSocket m_pCommSocket;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_METEO_H__4BB4970B_F2ED_4E97_9C58_24835AA71B7C__INCLUDED_)
// Meteo .cpp (la fonction RUN est la fonction lancée par le thread )
// Meteo.cpp : implementation file
//
#include "stdafx.h"
#include "PrimsolClimat.h"
#include "Meteo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMeteo
IMPLEMENT_DYNCREATE(CMeteo, CWinThread)
CMeteo::CMeteo()
{
}
CMeteo::~CMeteo()
{
}
BOOL CMeteo::InitInstance()
{
// TODO: perform and per-thread initialization here
//M__sock = new CCommSocket(); //CCommSocket dérivé de CAsyncSocket
return TRUE;
}
int CMeteo::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CMeteo, CWinThread)
//{{AFX_MSG_MAP(CMeteo)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMeteo message handlers
int CMeteo::Run()
{
m_IPSrv = "192.168.1.56";
m_Port = 4000;
float vrafvent1=0;
float vrafvent2=0;
float vrafvent=0;
int dvent=0;
float temp1=0;
float temp2=0;
float temp=0;
int signe=0;
int hygr=0;
int pluv=0;
while(1)
{
int BufSize = 256;
char *pBuf=new char[BufSize];
//m_pCommSocket->setDoc(m_pDonnees); // transfert de l'adresse du pointeur m_pDonnees à la classe CCommSocket
// client,cree un socket par default
m_pCommSocket.Create();
// ouvre la connexion sur le serveur
m_pCommSocket.Connect(m_IPSrv,m_Port);
// reçoit la trame du serveur
m_pCommSocket.Receive(pBuf,BufSize);
// ferme le socket connecte
Sleep(1);
m_pCommSocket.Close();
Sleep(1);
vrafvent1 = pBuf[0];
vrafvent2 = pBuf[1];
vrafvent = vrafvent1 + vrafvent2/10;
dvent = pBuf[2];
temp1 = pBuf[3];
temp2 = pBuf[4];
temp = temp1+temp2/10;
hygr = pBuf[5];
pluv = pBuf[6];
Sleep(1);
m_pDonnees->m_pVerrouMeteo.Lock();
m_pDonnees->acquisitionReelleMeteo[0]= temp;
m_pDonnees->acquisitionReelleMeteo[1]= (float)hygr;
m_pDonnees->acquisitionReelleMeteo[2]= (float)pluv;
m_pDonnees->acquisitionReelleMeteo[3]= vrafvent;
m_pDonnees->acquisitionReelleMeteo[4]= (float)dvent;
m_pDonnees->m_pVerrouMeteo.Unlock();
delete[]pBuf;
Sleep(5000);
}
return (0);
}
Création du thread et passage du pointeur sur doc
m_pMeteo = (CMeteo*) AfxBeginThread(RUNTIME_CLASS(CMeteo),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
m_pMeteo->setDoc(m_pDoc);
m_pMeteo->ResumeThread();
ne pas oublier de déclarer comme ceci dans meteo.h :
void setDoc(CPrimsolClimatDoc * doc) { m_pDonnees = doc;}
voili voilou, je t'envoie le projet complet (ou presque) sur ton adresse mail.