_begintheadex函数调用问题

发布于 2024-10-11 19:55:34 字数 1158 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2024-10-18 19:55:34

非静态类成员上启动线程是非法的,因为创建的线程无法知道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?

稀香 2024-10-18 19:55:34

我在选角时也遇到了同样的问题。
忽略上面答案中提到的所有其他问题,函数指针必须强制转换为 _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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文