Multi-Thread

Résolu
cjiwank Messages postés 6 Date d'inscription samedi 12 mars 2005 Statut Membre Dernière intervention 14 avril 2005 - 16 mars 2005 à 20:36
cjiwank Messages postés 6 Date d'inscription samedi 12 mars 2005 Statut Membre Dernière intervention 14 avril 2005 - 17 mars 2005 à 09:19
Quelqu'un peut-il me dire pourquoi je compile ce projet (VC++ 6) j'obtient tjs une erreur " error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'"

// Chap18bDoc.cpp : implementation of the CChap18bDoc class
//


#include "stdafx.h"
#include "Chap18b.h"
#include "Spinner.h"
#include "Chap18bDoc.h"
#include "Chap18bView.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CChap18bDoc


IMPLEMENT_DYNCREATE(CChap18bDoc, CDocument)


BEGIN_MESSAGE_MAP(CChap18bDoc, CDocument)
//{{AFX_MSG_MAP(CChap18bDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChap18bDoc construction/destruction


CChap18bDoc::CChap18bDoc()
{
// TODO: add one-time construction code here


}


CChap18bDoc::~CChap18bDoc()
{
}


BOOL CChap18bDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;


// TODO: add reinitialization code here
// (SDI documents will reuse this document)
InitSpinners();
return TRUE;
}





/////////////////////////////////////////////////////////////////////////////
// CChap18bDoc serialization


void CChap18bDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}


/////////////////////////////////////////////////////////////////////////////
// CChap18bDoc diagnostics


#ifdef _DEBUG
void CChap18bDoc::AssertValid() const
{
CDocument::AssertValid();
}


void CChap18bDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CChap18bDoc commands


void CChap18bDoc::CalcPoint(int nID, CSpinner *pSpin)
{
RECT lWndRect;
CPoint pPos;
int iLength;
CChap18bView *pWnd;


pWnd = (CChap18bView*)pSpin->GetViewWnd();
pWnd->GetClientRect(&lWndRect);
iLength = lWndRect.right/6;
switch (nID) {
case 0 : pPos.x = (lWndRect.right/4) - iLength;
pPos.y = (lWndRect.bottom/4) - iLength;
break;
case 1 : pPos.x = ((lWndRect.right/4) * 3) - iLength;
pPos.y = (lWndRect.bottom/4) - iLength;
break;
case 2 : pPos.x = (lWndRect.right/4) - iLength;
pPos.y = ((lWndRect.bottom/4) * 3) - (iLength * 1.25);
break;
case 3 : pPos.x = ((lWndRect.right/4) * 3) - iLength;
pPos.y = ((lWndRect.bottom/4) * 3) - (iLength * 1.25);
break;
}
pSpin->SetLength(iLength);
pSpin->SetPoint(pPos);
}


void CChap18bDoc::InitSpinners()
{
int i;


POSITION pos = GetFirstViewPosition();
if (pos != NULL) {
CView* pView = GetNextView(pos);
for (i=0; i<4; i++) {
m_cSpin[i].SetViewWnd(pView);
m_cSpin[i].SetContinue(NULL);
switch(i) {
case 1 : m_cSpin[i].SetContinue(&((CChap18bView*)pView)->m_bThread1);
break;
case 3 : m_cSpin[i].SetContinue(&((CChap18bView*)pView)->m_bThread2);
break;
}
CalcPoint(i, &m_cSpin[i]);
}
}
}


void CChap18bDoc::DoSpin(int nIndex)
{
m_cSpin[nIndex].Draw();
}


UINT CChap18bDoc::ThreadFunc(LPVOID pParam)
{
CSpinner* lpSpin = (CSpinner*)pParam;
BOOL* pbContinue = lpSpin->GetContinue();
while (*pbContinue)
lpSpin->Draw();
return 0;
}


void CChap18bDoc::SuspendSpinner(int nIndex, BOOL bSuspend)
{
if (!bSuspend) {
if (m_pSpinThread[nIndex]) {
HANDLE hThread = m_pSpinThread[nIndex]->m_hThread;
::WaitForSingleObject(hThread, INFINITE);
}
}
else {
int iSpnr;
switch (nIndex) {
case 0 : iSpnr = 1;
break;
case 1 : iSpnr = 3;
break;
}
m_pSpinThread[nIndex] = AfxBeginThread(ThreadFunc,(LPVOID)&m_cSpin[iSpnr]);
}
}

3 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
17 mars 2005 à 09:02
ThreadFunc doit être un membre static de la class avec la convention d'appel WINAPI.
Si cette fonction doit faire appel à des membres de la classe, il fuat lui passer un pointeur sur l'objet (this en l'occurence) comme param :

.cpp :
UINT WINAPI CChap18bDoc::ThreadFunc(LPVOID pParam)

.h :
class CChap18bDoc
{
static UINT WINAPI ThreadFunc(LPVOID pParam);
};
3
jul39dole Messages postés 117 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 21 janvier 2011
16 mars 2005 à 23:27
et en castant en LPVOID aussi ?
0
cjiwank Messages postés 6 Date d'inscription samedi 12 mars 2005 Statut Membre Dernière intervention 14 avril 2005
17 mars 2005 à 09:19
Merci pour les info. Maintenant cela fonctionne correctement.
Comme quoi parfois il suffit de vraiment peut de chôse.
0
Rejoignez-nous