C ++ MFC-创建线程错误@.@ [英] C++ MFC - Create Thread error @.@

查看:71
本文介绍了C ++ MFC-创建线程错误@.@的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误C2664:``CreateThread'':无法将参数3从``DWORD(__stdcall *)(void)''转换为``LPTHREAD_START_ROUTINE&''

我是C ++ mfc应用程序的新手,但我一直卡在此错误中..有人知道如何解决此问题吗?

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?

推荐答案

CreateThread [此处中所述声明此功能 [ ^ ].
您没有发布线程过程的声明和对CreateThread的调用,因此很难分辨出问题出在哪里,而是查看错误消息(无法将参数3从''DWORD(__stdcall *)( void )''到``LPTHREAD_START_ROUTINE&''
)我怀疑您的线程过程函数没有任何参数.如果是这种情况,请更改函数以获取指向void(LPVOID)的指针,否则请发布一些代码.
:)

[更新]
将线程过程声明为:static DWORD WINAPI timerThread(LPVOID lpParameter).

一些评论:
-您对CreateThread的调用指示timerThreadCIODialogDlg类中声明,但是您的函数定义没有前缀类名(CIODialogDlg::).
-同样,timerThread的声明不带任何参数(不正确),但定义带参数.

因此,这一切都前后矛盾且混乱不堪.请看一些使用CreateThread创建线程的示例:
-来自MSDN的示例 [有关CreateThread的CodeProject文章 [关于该主题的MSDN线程 [ ^ ]

还可以考虑使用 _beginthreadex [AfxBeginThread [
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]


这篇关于C ++ MFC-创建线程错误@.@的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆