Hello,
I am having issues getting my worker thread to function properly. I am working with visual c++ 6 and I am unsure that this is the correct forum to post in but I could not find another that seemed to better suit my question.
I am trying to initiate a thread to populate a list box when I click on a button. Once I figure out I will be populating the list box with more complex code, but if I can't even get this to work, I can't move forward on the next part. I am trying to make the following code work but it is obviously not correct:
void CDialogDlg::OnB utton1()
{
AfxBeginThread( CDialogDlg::MyT hreadFunction,( LPVOID)this);
}
UINT CDialogDlg::MyT hreadFunction(L PVOID lparam)
{
m_listbox.AddSt ring("testfromf unction");
return 0;
}
This code produces the following error:
'AfxBeginThread ':none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
If I change it to the following code, AfxBeginThread works just fine, but I cannot populate the listbox because the MyThreadFunctio n does not know anything about the m_listbox variable, let alone the AddString member function:
void CDialogDlg::OnB utton1()
{
AfxBeginThread( MyThreadFunctio n,(LPVOID)this) ;
}
UINT MyThreadFunctio n(LPVOID lparam)
{
AfxMessageBox(" testfromfunctio n");
return 0;
}
Any help would be greatly appreciated,
Thanks
I am having issues getting my worker thread to function properly. I am working with visual c++ 6 and I am unsure that this is the correct forum to post in but I could not find another that seemed to better suit my question.
I am trying to initiate a thread to populate a list box when I click on a button. Once I figure out I will be populating the list box with more complex code, but if I can't even get this to work, I can't move forward on the next part. I am trying to make the following code work but it is obviously not correct:
void CDialogDlg::OnB utton1()
{
AfxBeginThread( CDialogDlg::MyT hreadFunction,( LPVOID)this);
}
UINT CDialogDlg::MyT hreadFunction(L PVOID lparam)
{
m_listbox.AddSt ring("testfromf unction");
return 0;
}
This code produces the following error:
'AfxBeginThread ':none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
If I change it to the following code, AfxBeginThread works just fine, but I cannot populate the listbox because the MyThreadFunctio n does not know anything about the m_listbox variable, let alone the AddString member function:
void CDialogDlg::OnB utton1()
{
AfxBeginThread( MyThreadFunctio n,(LPVOID)this) ;
}
UINT MyThreadFunctio n(LPVOID lparam)
{
AfxMessageBox(" testfromfunctio n");
return 0;
}
Any help would be greatly appreciated,
Thanks
Comment