What's wrong with this????
-
I'm trying to create my threads, but when I go to compile this I get an error:
void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} }
Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.com -
I'm trying to create my threads, but when I go to compile this I get an error:
void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} }
Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.comYou did not indicate what line was in error so I can only assume it was the
AfxBeginThread()
statement. Yes? If so,myThreadFunc()
should be astatic
member, or a non-class function.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
-
You did not indicate what line was in error so I can only assume it was the
AfxBeginThread()
statement. Yes? If so,myThreadFunc()
should be astatic
member, or a non-class function.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
Thanks David, I saw that in another program that I wrote a while back. After I made the function static, I received another error. On the same call I get an error "operator =" function is not avaliable in CWinThread. In the MSDN is says that it returns a pointer to the newly created object. Did I not setup my pointer right? Thanks Tom Wright tawright915@yahoo.com
-
Thanks David, I saw that in another program that I wrote a while back. After I made the function static, I received another error. On the same call I get an error "operator =" function is not avaliable in CWinThread. In the MSDN is says that it returns a pointer to the newly created object. Did I not setup my pointer right? Thanks Tom Wright tawright915@yahoo.com
OK, this may help you out. Firtly make the myThreadFunc static as David says. Then if you alter the parameter class/struct to hold a pointer to the CLAMsgSwDlg class you can call the non-static member function and therefore other member elements. Add the following to the ThreadInfo class/struct
CLAMsgSwDlg* thdParent;
Make the alterations in bold
void CLAMsgSwDlg::StartAllThreads()
{
int nCount = m_lClientConn.GetItemCount();ThreadInfo *mythreadinfo = new ThreadInfo[nCount];
for (int i = 0; i < nCount; i++)
{
mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0);
mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1);
mythreadinfo[i].thdParent = this;//Start all threads here.
CWinThread* pThread = new CWinThread[nCount];
pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]);//Save the handle to the thread
HANDLE* hThread = new HANDLE[nCount];
hThread[i] = pThread->m_hThread;
}
}UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam)
{
**ThreadInfo *threadinfo = reinterpret_cast<ThreadInfo*>(pParam);
ASSERT(theadinfo != NULL);threadinfo->thdParent->DoThreadStuff();**
}**void CLAMsgSwDlg::DoThreadStuff()
{
m_sConnectSocket.SetParent(this);
//if (OnCreate)
//{//}**
}Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain) -
I'm trying to create my threads, but when I go to compile this I get an error:
void CLAMsgSwDlg::StartAllThreads() { int nCount = m_lClientConn.GetItemCount(); ThreadInfo *mythreadinfo = new ThreadInfo[nCount]; for (int i = 0; i < nCount; i++) { mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0); mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1); //Start all threads here. CWinThread* pThread = new CWinThread[nCount]; pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]); //Save the handle to the thread HANDLE* hThread = new HANDLE[nCount]; hThread[i] = pThread->m_hThread; } } UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam) { m_sConnectSocket.SetParent(this); //if (OnCreate) //{ //} }
Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter" Thanks Tom Wright tawright915@yahoo.comHi, myThreadFunc function must have 2 be a global function. So you are using a worker thread.Have a look @ this link this will surely help you http://www.flounder.com/workerthreads.htm[^] Sujan