views:

62

answers:

4
     HANDLE  hThread;
     DWORD   dwThreadId;

         hThread = CreateThread( 
     NULL,                   // default security attributes
     0,                      // use default stack size  
     MyThreadFunction,       // thread function name
     0,                      // argument to thread function 
     0,                      // use default creation flags 
     &dwThreadId);           // returns the thread identifier  <--Debugger takes me to this line?

The error specifies the 3rd parameter but when i double click on the error it takes me to the last parameter?
Trying to run the msdn CreateThread example http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx

error C2664: 'CreateThread' : cannot convert parameter 3 from 'void (void)' to 'unsigned long (__stdcall *)(void *)'
        None of the functions with this name in scope match the target type
+2  A: 

When you double-click the error, it brings up the source for where the error occurred. Since the function call expression spans multiple lines, it will select the last line of the expression.

The problem is that MyThreadFunction does not have the correct function type. MyThreadFunction is a function that takes no arguments and returns nothing. You need to pass a pointer to a function that takes one argument (a void*) and returns an unsigned long.

James McNellis
+2  A: 

Your function signature does not match the expected signature.

Your MythreadFunction function should return ULONG.

Something like:

DWORD WINAPI MyThreadFunction(LPVOID lpParameter) {
}
John Gietzen
+1  A: 

Clicking on the error takes you to the last parameter because the go-to-error function can only go by statements, and the entire function call is one statement.

Basically, your problem is that MyThreadFunction has the wrong signature. It should be unsigned long __stdcall MyThreadFunction(void*) (or the equivalent thereof), but you wrote void MyThreadFunction(void) (or the equivalent thereof).

JSBangs
+3  A: 

The debugger is just taking you to the end of the statement.

In any case, your function signature is wrong and needs to match the function pointer type. For CreateThread, it should be:

DWORD WINAPI ThreadProc(LPVOID lpParameter);
GMan