+ Reply to Thread
Results 1 to 2 of 2

Thread: Error code C2440 with thread MFC/WIN32

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    23

    Error code C2440 with thread MFC/WIN32

    I have following code:

    Code:
    class CTestDlg : public CDialog
    {
    	UINT WINAPI ThreadFunc(void *pParam) ;
    } ;
    
    UINT CTestDlg::ThreadFunc(void *pParam)
    {
    	OutputDebugString("This is a thread function\n") ;
    	return 0 ;
    }
    
    BOOL CTestDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    	AfxBeginThread((AFX_THREADPROC) ThreadFunc, NULL, 0, 0, 0, NULL) ;
    	return TRUE ;
    }
    I get following error with above code:
    error C2440: 'type cast' : cannot convert from '' to 'unsigned int (__cdecl *)(void *)'

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    You are missing "static" keyword as described below:

    Code:
    class CTestDlg : public CDialog
    {
    	static UINT WINAPI ThreadFunc(void *pParam) ; //here you should use "static", this should solve your issue.
    } ;
    
    UINT CTestDlg::ThreadFunc(void *pParam)
    {
    	OutputDebugString("This is a thread function\n") ;
    	return 0 ;
    }
    
    BOOL CTestDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    	AfxBeginThread((AFX_THREADPROC) ThreadFunc, NULL, 0, 0, 0, NULL) ;
    	return TRUE ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts