-
December 22nd, 2009, 01:14 PM
#1
Error in Multithread
I'm following MFC in VC++.net 2008...
I'm using threads in my codes. The code declared as
Code:
public:
DWORD WINAPI ThreadProc(LPVOID lp);
and
Code:
BOOL CNewSerialPrintDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//bla bla....
HANDLE m_RecvThread=NULL;
DWORD ThreadID = 0;
m_RecvThread = ::CreateThread(NULL,
0,ThreadProc,NULL,0,&ThreadID
);
return TRUE; // return TRUE unless you set the focus to a control
}
DWORD WINAPI CNewSerialPrintDlg::ThreadProc(LPVOID lp)
{
while(1)
{
//bla bla.....
return 0;
}
}
while compiling the error message reported as
Code:
error C3867: 'CNewSerialPrintDlg::ThreadProc': function call missing argument list; use '&CNewSerialPrintDlg::ThreadProc' to create a pointer to member
Plz help me to fix this problem.I don't have more experience on using Thread.
-
December 22nd, 2009, 01:45 PM
#2
Re: Error in Multithread
Prefer _beginthreadex over CreateThread.
Code:
m_hThread1 = (HANDLE)_beginthreadex(
NULL,
0,
&CNewSerialPrintDlg::ThreadProc1,
static_cast<LPVOID>( this ),
0,
NULL);
Also the thread proc needs to be declared as static
Code:
static UINT WINAPI CNewSerialPrintDlg::ThreadProc1( LPVOID lpContext )
{
// Turn the passed in 'this' pointer back into a CNewSerialPrintDlg instance
CNewSerialPrintDlg* pDlg = reinterpret_cast< CNewSerialPrintDlg* >( lpContext );
while( TRUE )
{
}
return 0;
}
Last edited by Arjay; December 23rd, 2009 at 01:01 PM.
Reason: Fixed bug, thanks Cilu.
-
December 22nd, 2009, 02:36 PM
#3
Re: Error in Multithread
For the benefit of anyone else who spends time helping:
http://www.codeguru.com/forum/showthread.php?t=490067
-
December 23rd, 2009, 01:32 AM
#4
Re: Error in Multithread
I've used the above mentioned format.
ThreadProc1 declared in NewSerialPrint.h
Code:
private:
static UINT WINAPI ThreadProc1(LPVOID lpContext);
and in NewSerialPrint.cpp as(otherwise it makes so many errors like parameters can't be static..)
Code:
UINT WINAPI CNewSerialPrintDlg::ThreadProc1( LPVOID lpContext )
{
// Turn the passed in 'this' pointer back into a CNewSerialPrintDlg instance
CNewSerialPrintDlg* pDlg = reinterpret_cast< CNewSerialPrintDlg* >( lpContext );
while(TRUE)
{
//....
}
}
but again the same error message is coming it is like
Code:
error C3867: 'CNewSerialPrintDlg::ThreadProc1': function call missing argument list; use '&CNewSerialPrintDlg::ThreadProc1' to create a pointer to member.
error C3861: '_beginthreadex': identifier not found
how may I fix it
Last edited by arunkr6; December 23rd, 2009 at 01:35 AM.
-
December 23rd, 2009, 05:05 AM
#5
Re: Error in Multithread
The error refers to the code that starts the thread, not the thread procedure. You probably call it with ThreadProc1, and you should use &CNewSerialPrintDlg::ThreadProc1.
-
December 23rd, 2009, 01:03 PM
#6
Re: Error in Multithread
Originally Posted by cilu
The error refers to the code that starts the thread, not the thread procedure. You probably call it with ThreadProc1, and you should use &CNewSerialPrintDlg::ThreadProc1.
Thanks Cilu, I copied that snippet over from code where everything was declared in the header, ATL style (i.e. no cpp file). I've updated the original post.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|