Spawning a class member function into a thread
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Spawning a class member function into a thread

  1. #1
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    14

    Spawning a class member function into a thread

    Is it possible to spawn a class member function into a thread?

    I try to do that, but get this error: error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'

    For example, can we have something like this

    class C
    {
    public:
    DWORD m_threadId;
    HANDLE m_hThread;
    DWORD WINAPI ThreadFunction(LPVOID lparam);
    void f1(void);
    }

    void C::f1(void){
    m_hThread = CreateThread(NULL, NULL, ThreadFunction, NULL,
    NULL, &m_threadId);
    }



    TIA.
    rh

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at the following FAQ...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  3. #3
    Join Date
    Feb 2002
    Posts
    5,758
    Define the member function as a static public member fuction. Include "__stdcall" so the compiler will accept it.

    Kuphryn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center