_beginthreadex静态成员函数 [英] _beginthreadex static member function

查看:170
本文介绍了_beginthreadex静态成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建静态成员函数的线程例程

How do I create a thread routine of a static member function

class Blah
{
    static void WINAPI Start();
};

// .. 
// ...
// ....

hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL);

这给我以下错误:

***error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void (void)' to 'unsigned int (__stdcall *)(void *)'***

我做错了什么?

推荐答案

有时候,读取您遇到的错误很有用。

Sometimes, it is useful to read the error you're getting.

cannot convert parameter 3 from 'void (void)' to 'unsigned int (__stdcall *)(void *)'

在它说什么。对于参数三,你给它一个带有签名 void(void)的函数,即一个不带参数,不返回任何内容的函数。它无法将此转换为 _beginthreadex unsigned int(__stdcall *)(void *)预期

Let's look at what it says. For parameter three, you give it a function with the signature void(void), that is, a function which takes no arguments, and returns nothing. It fails to convert this to unsigned int (__stdcall *)(void *), which is what _beginthreadex expects:

它需要一个函数:


  • unsigned int

  • 使用 stdcall 调用约定

  • 采用 void * 参数。

  • Returns an unsigned int:
  • Uses the stdcall calling convention
  • Takes a void* argument.

我的建议是给它一个函数与它要求的签名。

So my suggestion would be "give it a function with the signature it's asking for".

class Blah
{
    static unsigned int __stdcall Start(void*);
};

这篇关于_beginthreadex静态成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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