2010-06-21 71 views
1
 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? 

该错误指定第三个参数,但是当我双击错误,它将我带到最后一个参数?
尝试运行MSDN CreateThread的例子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 

回答

1

单击错误带你到最后一个参数,因为去到错误功能只能通过声明去,整个函数调用是一个语句。

基本上,你的问题是MyThreadFunction有错误的签名。它应该是unsigned long __stdcall MyThreadFunction(void*)(或其等价物),但你写了void MyThreadFunction(void)(或其等价物)。

1

当您双击错误,它带来了对发生错误的来源。由于函数调用表达式跨越多行,它将选择表达式的最后一行。

问题是MyThreadFunction没有正确的功能类型。 MyThreadFunction是一个不带参数且不返回任何内容的函数。您需要将指针传递给带有一个参数的函数(一个void*)并返回一个unsigned long

2

您的函数签名与预期的签名不匹配。

你的MythreadFunction函数应该返回ULONG。

喜欢的东西:

DWORD WINAPI MyThreadFunction(LPVOID lpParameter) { 
} 
3

调试器只是把你带到声明的结尾。

在任何情况下,您的函数签名都是错误的,需要匹配函数指针类型。对于CreateThread,应该是:

DWORD WINAPI ThreadProc(LPVOID lpParameter);