Multithreading
OK, I think I'm getting the picture now with multithreading, but I've got myself in a bit of a pickle.....
I'm getting this below, which having read up I know the reason for but don't know the best way to fix it....
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
The function being called is a class member of my dialog...Declaring the function as static isn't helping because it needs access to the dialog class member variables, and declaring these variables as static gives me unresolved external symbols.
Is there an easy way around this or will I have to make all needed variables global?This must be fairly common?
[768 byte] By [
ggmn] at [2007-11-19 1:10:51]

# 2 Re: Multithreading
...The function being called is a class member of my dialog...Declaring the function as static isn't helping because it needs access to the dialog class member variables, and declaring these variables as static gives me unresolved external symbols.
If your thread function is a member of a class, it's impossible to circumvent the requirement that the function be declared "static".
You're right, though, this is a common situation. What you do is pass the "this" pointer into the thread function as its parameter, and then cast it back to a "localized" pseudo-this pointer in the thread function, like this:
// .. when starting the thread ..
CMyClass::StartupThread()
{
..
AfxBeginThread( MyThreadFunc, (LPVOID) this);
..
}
// .. for your thread function, which is declared "static"
UINT CMyClass::MyThreadFunc( void* pVoid )
{
CMyClass* pThis = (CMyClass*) pVoid; // now pThis points to an object of your class
int iNumToProcess = pThis->m_iSomeMemberVariable;
// etc
return 0;
}
Mike