problems using CreateThread on a member function

谁说我不能喝 提交于 2019-12-02 03:07:47

static functions aren't bound to a particular instance; there is no this pointer, and you have no "member variables." You can pass the this pointer as an argument to your function, and then cast it into a Dac* and access member variables from it.

So you could do

ping_thread = CreateThread (NULL , 0, ping_loop, (LPVOID)this, 0, &dping_thread);

And change your ping_loop to this:

static DWORD WINAPI ping_loop(void* param)
{
    Dac* dac = (Dac*)param;
    while ( dac->com.dac_ping() == 0)
        Sleep(900);

    return 1; //since this is an infinite loop, if the loop breaks, it has failed
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!