Search code examples
c++multithreadingwinapiclassvisual-studio-express

_begintheadex function call problem


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);

Solution

  • 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?