Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error C2664: 'CreateThread' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void)' to 'LPTHREAD_START_ROUTINE&'

i'm new to c++ mfc apps, and i'm stuck with this error.. anyone know how to solve this?
Posted

1 solution

The third parameter of CreateThread[^] API is a pointer to your thread procedure.
This function must be strictly declared as described here[^].
You didn't post the declaration of your thread procedure and your call to CreateThread so it is hard to tell where exactly is the problem but looking at your error message (cannot convert parameter 3 from 'DWORD (__stdcall *)(void)' to 'LPTHREAD_START_ROUTINE&'
) I suspect that your thread procedure function does not take any parameters. If this is the case, change your function to take a pointer to void (LPVOID) if not please post some code.
:)

[Update]
Declare your thread procedure as: static DWORD WINAPI timerThread(LPVOID lpParameter).

Some comments:
- Your call to CreateThread indicates that timerThread is declared in CIODialogDlg class, but your function definition is not prefixed with the class name (CIODialogDlg::).
- Also the declaration of timerThread does not take any parameter (which is incorrect) but the definition takes parameter.

So it is all inconsistent and messed up. Please have a look at some examples of creating threads using CreateThread:
- Example from MSDN[^]
- CodeProject article on CreateThread[^]
- MSDN thread on the topic[^]

Also consider using _beginthreadex[^] or AfxBeginThread[^] as a better alternatives of create thread.
[/Update]
 
Share this answer
 
v6
Comments
adrian khor 13-Feb-11 4:47am    
well.. thanks for your comment.
I do declared static DWORD WINAPI timerThread();
and HANDLE m_hThread in my IODialogDlg.h file.

Below is part of the code in IODialogDlg.cpp:
<pre>
m_hThread = CreateThread(NULL, 0, &CIODialogDlg::timerThread, this, 0, NULL);

static DWORD WINAPI timerThread( LPVOID pObj)
{
return 0;
}
</pre>

Thanks for help!
Nuri Ismail 13-Feb-11 5:21am    
Please see my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900