Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error with AfxBeginThread 2

Status
Not open for further replies.

VincentP

Programmer
Apr 1, 2001
116
I am just learning how to use threads, and the compiler throws an error I can't figure how to solve...

In my document class (SDI application), I have the following function:

UINT CMyDoc::ThreadPseudo(LPVOID pParam)
{
// do stuff, but I don`t use pParam, only member variables of CMyDoc

return 0;
}

In another of my Doc methods, I have the following:

m_pThread = AfxBeginThread( ThreadPseudo, NULL );

where m_pThread is a CWinThread * member variable.

The compiler throws the following error:

error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

Every example I can find seems to indicate I am doing this the right way... Can anybody help me?

Vincent
 
what does ThreadPseudo as a functions parameter mean? John Fill
1c.bmp


ivfmd@mail.md
 
This is the declaration of AfxBeginThread:

CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );

The MSDN help gives the following:

pfnThreadProc

Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows:

UINT MyControllingFunction( LPVOID pParam );

(This is the equivalent of the "main" function for a thread.)

I would like to know why my function does work. It looks to me like it is declared correctly...

I can't find the definition of AFX_THREADPROC anywhere, so I can't make sure how the parameter looks like exactly, but both MSDN and my "Teach Yourself VC++ 6.0" book seem to indicate I am doing this right... :-(

Vincent
 
in this case, I think your ThreadPseudo should be declared as a static function. John Fill
1c.bmp


ivfmd@mail.md
 
Darn, it works. Except that now my function doesn't do much, since the variables it is accessing are not "static". I think I should find a way around that easily.

Thanks,

Vincent

P.S.: Any idea WHY it should be static? I have a SDI application after all, there will never be more than one CDocument object anyways, so "static" member variables will not change anything in my case...

In my book's example (which I have not tried, just read), they do the same as I do: they tell the reader to add a new member function to the class (a "doc" class), type UINT, declaration as "ThreadFunc( LPVOID pParam ) and access as private.
 
put in parameter LPVOID the pointer to CWinThread, and when you will call it you will put there the pointer this.
UINT CMyDoc::ThreadPseudo(DWORD* x)
{
CWinThread* pwt = (CWinThread*)x;
pwt->a = ....;
pwt->xxx(....);
// do stuff, but I don`t use pParam, only member variables of CMyDoc

return 0;
} John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top