CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    59

    Exclamation 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.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  3. #3
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Error in Multithread

    For the benefit of anyone else who spends time helping:

    http://www.codeguru.com/forum/showthread.php?t=490067

  4. #4
    Join Date
    Oct 2008
    Posts
    59

    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.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Error in Multithread

    Quote Originally Posted by cilu View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured