Open Watcom CreateThread pointer parameter problems, m'kay?

This is a discussion on Open Watcom CreateThread pointer parameter problems, m'kay? within the Windows Programming forums, part of the Platform Specific Boards category; So a while back I wrote a miniature debugger to try and familiarize myself with the Windows debugging API. I ...

  1. #1
    Disrupting the universe Mad_guy's Avatar
    Join Date
    Jun 2005
    Posts
    258

    Open Watcom CreateThread pointer parameter problems, m'kay?

    So a while back I wrote a miniature debugger to try and familiarize myself with the Windows debugging API. I got my debugger finished quite a while back but I've hit a recent snag that I have had racking my brain for a while. I'm trying to get my code to work properly under open watcom. The program compiles fine but it ALWAYS gives me an error whenever the actual logging thread is created in the program. I refrained from my usual 'don't use threads' policy in this manner because I wanted users to have the option to monitor processes, etc. etc..


    Either way, whenever I compile the program under Open Watcom (which it compiles flawlessly,) the debugging thread checks the passed parameter to make sure that the proper flag is set. It always returns 0x00000004 though, which is an 'unrecongized' flag for the thread functions parameter in the struct.

    I'm probably not making sense here, so I'll shorten it and then post the code: when you specify to debug an active process or a new one it sets a flag which is then given to the thread function and checks that parameter, but in Open watcom it's always wrong while in, say, GCC it's correct. I'll pastebin it and highlight the (what I think are) relevent sections.


    Source.


    Any help? I'm obviously not used to strict compilers and I've pulled every single trick I can think of, but to no avail. I don't have to get this to work on Open Watcom, I just feel if I can other people won't have a problem if they wish to compile my apps by source.
    operating systems: mac os 10.6, debian 5.0, windows 7
    editor: back to emacs because it's more awesomer!!
    version control: git

    website: http://0xff.ath.cx/~as/

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    int dbgMain(PVOID pvParam);
    
            hThread = CreateThread(
                    NULL,
                    0,
                    (LPTHREAD_START_ROUTINE)dbgMain,
                    dbgStats,
                    CREATE_SUSPENDED,
                    &dThrID
            );
    Nice program you've got there! The problem appears to be simply the wrong calling convention for your thread function. The correct prototype for a thread function is:
    Code:
    DWORD WINAPI dbgMain(LPVOID lpParameter);
    As a general rule you can avoid many of these type of problems by never using a cast unless you know exactly why it is needed. Without the cast in CreateThread, the compiler would have issued a warning about the mismatched calling conventions. As far as I know, there is no valid need to ever cast the thread function passed to CreateThread.

  3. #3
    Disrupting the universe Mad_guy's Avatar
    Join Date
    Jun 2005
    Posts
    258
    Go figure the reason I'd get screwed is because of calling conventions. This hit me a while back with __stdcall and __pascal getting interchanged within some of my Delphi <-> C Programs and DLLs. I'll keep that in mind, it works. Thanks.

    EDIT: Right there in MSDN. Screw not paying attention to minor details and not reading function prototypes for this type of crap: "Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread. Code that does this is common, but it can crash on 64-bit Windows."
    Last edited by Mad_guy; 11-06-2005 at 01:33 AM.
    operating systems: mac os 10.6, debian 5.0, windows 7
    editor: back to emacs because it's more awesomer!!
    version control: git

    website: http://0xff.ath.cx/~as/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  3. more pointer problems
    By dharh in forum C Programming
    Replies: 3
    Last Post: 02-11-2003, 06:52 PM
  4. Problems with functions in a class with pointer to self
    By BigDaddyDrew in forum C++ Programming
    Replies: 6
    Last Post: 02-03-2003, 11:24 PM
  5. Problems with open and save boxes
    By pinkcheese in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2002, 07:03 PM

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