_begintheadex函数调用问题
我有一个 SoundManager 类,其中包含一个名为“recordLoop”的函数。在 SoundManager 的构造函数中,我使用此代码:
recordHandle = (HANDLE)_beginthreadex(NULL,0,recordLoop,
(void*)exinfo->length,CREATE_SUSPENDED,0);
它给了我以下错误:
error C3867: 'SoundManager::recordLoop': function call missing argument list; use '&SoundManager::recordLoop' to create a pointer to member
IntelliSense: argument of type "unsigned int (__stdcall SoundManager::*)(void *params)" is incompatible with parameter of type "unsigned int (__stdcall *)(void *)"
所以我尝试按照建议使用 &SoundManager::recordLoop,但它给了我这个:
error C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (__stdcall SoundManager::* )(void *)' to 'unsigned int (__stdcall *)(void *)'
IntelliSense: argument of type "unsigned int (__stdcall SoundManager::*)(void *params)" is incompatible with parameter of type "unsigned int (__stdcall *)(void *)"
启动线程是否非法在类方法上还是我做错了什么?
提前致谢
编辑:抱歉忘记添加 recordLoop >。<这里是:
public:
unsigned __stdcall recordLoop(void* params);
I have a class SoundManager which contains a function called 'recordLoop'. In the constructor of the SoundManager, I am using this code:
recordHandle = (HANDLE)_beginthreadex(NULL,0,recordLoop,
(void*)exinfo->length,CREATE_SUSPENDED,0);
It is giving me the following errors:
error C3867: 'SoundManager::recordLoop': function call missing argument list; use '&SoundManager::recordLoop' to create a pointer to member
IntelliSense: argument of type "unsigned int (__stdcall SoundManager::*)(void *params)" is incompatible with parameter of type "unsigned int (__stdcall *)(void *)"
So I've tried using the &SoundManager::recordLoop as suggested, but it gives me this:
error C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (__stdcall SoundManager::* )(void *)' to 'unsigned int (__stdcall *)(void *)'
IntelliSense: argument of type "unsigned int (__stdcall SoundManager::*)(void *params)" is incompatible with parameter of type "unsigned int (__stdcall *)(void *)"
Is it illegal to start a thread on a class method or did I do something wrong?
Thanks in advance
EDIT: Sorry forgot to add the recordLoop >.< here it is:
public:
unsigned __stdcall recordLoop(void* params);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在非静态类成员上启动线程是非法的,因为创建的线程无法知道
this
是什么。recordLoop
的定义是什么?It's illegal to start a thread on a non-static class member since there is no way for the created thread to know what
this
is.What is the definition of
recordLoop
?我在选角时也遇到了同样的问题。
忽略上面答案中提到的所有其他问题,函数指针必须强制转换为 _beginthreadex 中的
(unsigned(__stdcall*)(void*))
,无论函数是什么类型或其是什么参数列表。I had the same problem with casting.
Ignoring all other problems like one mentioned in the answer above, function pointer must be cast to
(unsigned(__stdcall*)(void*))
in _beginthreadex, no matter what type the function is or what is its parameter list.