CreateThread or CWinThread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mccanaveras
    New Member
    • May 2007
    • 5

    CreateThread or CWinThread

    Hello,

    I need to implement a Thread in a Visual C++ 6.0 application. I've never done this, then I've been investigating, but I don't have any properly solution.

    One of them is use CWinThread to comunicate to a Dialog but it has been already created. And the other possibility is create a thread with the function CreateThread(), but it gives me an error in the third parameter:

    error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (class CDialogoPrimero *,void *)' to 'unsigned long (__stdcall *)(void
    *)'
    Would you mind pass me an example without this error?? the solution is doing the function "static" but it have another problems.

    Thank you in advance.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    CreateThread requires that your thread functon is a ThreadProc.

    A ThreadProc has this prototype:

    [code= c]
    DWORD WINAPI ThreadProc(LPVO ID);
    [/code]

    That means you can have any function for a thread but is must have this prototype. For example:

    [code=c]
    DWORD WINAPI MyFunction(LPVO ID date);
    DWORD WINAPI ThresholdDetect or(LPVOID thedata);
    [/code]

    etc..

    Then you can call CreateThread and use MyFunction or ThresholdDetect or as the thread argument.

    Comment

    • mccanaveras
      New Member
      • May 2007
      • 5

      #3
      Thank you very much.

      But my problem was the following one:

      error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)

      I have to comunicate with a interface and I don't know how to do. I find it really difficult, although it musn't be so tricky.

      Good day!!

      Originally posted by weaknessforcats
      CreateThread requires that your thread functon is a ThreadProc.

      A ThreadProc has this prototype:

      [code= c]
      DWORD WINAPI ThreadProc(LPVO ID);
      [/code]

      That means you can have any function for a thread but is must have this prototype. For example:

      [code=c]
      DWORD WINAPI MyFunction(LPVO ID date);
      DWORD WINAPI ThresholdDetect or(LPVOID thedata);
      [/code]

      etc..

      Then you can call CreateThread and use MyFunction or ThresholdDetect or as the thread argument.

      Comment

      • gnanapoongothai
        New Member
        • Jun 2007
        • 62

        #4
        Hi,
        Can just breif out the problem. because i wil also be working with multithreding concepts in VC++ 6.0.Just new to the community ans VC++.

        Comment

        Working...