compiler doesn't like CreateThread

This is a discussion on compiler doesn't like CreateThread within the C++ Programming forums, part of the General Programming Boards category; ok, last one for the night, i swear.... essentially, all i'm trying to do is create a win32 thread with ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    17

    compiler doesn't like CreateThread

    ok, last one for the night, i swear....

    essentially, all i'm trying to do is create a win32 thread with the CreateThread function

    (for those not familiar w/ it)
    Code:
    HANDLE CreateThread (
                         LPSECURITY_ATTRIBUTES lpThreadAttributes, 
                         SIZE_T dwStackSize,
                         LPTHREAD_START_ROUTINE lpStartAddress,
                         LPVOID lpParameter,
                         DWORD dwCreationFlags,
                         LPDWORD lpThreadId  )
    for whatever reason, the compiler is telling me that my function call does not match the definition of this function. i actually even tried copying someone's example code straight from a tutorial, and it's still giving me the same error message. anyway, here's my code:

    Code:
        DWORD genericThread;
        HANDLE updateThread;
        char lszThreadParam[3]; 
        strcpy(lszThreadParam,"3");
        updateThread = CreateThread(NULL,0,CheckUpdates,&lszThreadParam,0,&genericThread);
    .... any ideas??

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    maybe:
    Code:
    updateThread = CreateThread(NULL,0,CheckUpdates,lszThreadParam,0,&genericThread);
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    ok, just realized that it's called from within a class, so i thought maybe it was looking for a method in the class called CreateThread? maybe? i dunno.... i tried changing the function call to ::CreateThread and got a different error, saying "illegal implicit conversion from '__stdcall unsigned long (*) (void*)' to '__stdcall unsigned long (*) (void*)'".... which makes even less sense to me.... damn it....

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    DWORD WINAPI CheckUpdates(LPVOID lp)
    {
    	return 0;
    }
    
    int main()
    {
       DWORD genericThread;
       HANDLE updateThread;
       char lszThreadParam[3]; 
       strcpy(lszThreadParam,"3");
       updateThread = CreateThread(NULL,0,CheckUpdates,lszThreadParam,0,&genericThread);
    	
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    ok... i got something. basically i can't call a member function of a class in CreateThread:

    from: <http://www.ciprian-miclaus.com/sources/win32threads.asp?id=1&tip=c>
    (no intentions of plagiarizing here)

    DWORD WINAPI ThreadProc(
    LPVOID lpParameter
    );

    We'll notice this prototype will keep us from having this callback function as a member of a class, as it's member functions are passed a hidden parameter: this.


    this page also provided a solution, but i didn't entirely understand it... and the code was a little sloppy too, i think. so i've identified the problem, but don't know how to solve it.... any more suggestions? please??? this thing is making me want to pull out my hair.

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    You can only call a static function of a class ( as it does not get passed a "hidden" this pointer ). Pass the class as parameter. In the static function, cast the parameter to an object of your class and invoke the function you originally wanted to call in a thread. Sounds more complicated than it is.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Be aware that many compilers had problems using CreateThread() if at the same time they used the standard c library. The problems were subtle resulting in small memory leaks which accumulated over time.

    Most really modern compilers should have this fixed now, but there are a lot of people, me included, that have grown up wary of CreateThread() and routinely use beginthread() or beginthreadex() which never suffered from this problem.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21