Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CreateThread and AfxBeginThread

CreateThread and AfxBeginThread

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studioquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tom groezer
    wrote on last edited by
    #1

    In MFC what is the difference between these functions and what is the fine line calling AfxBeginThread vs calling ::CreateThread

    H CPalliniC S M 4 Replies Last reply
    0
    • T tom groezer

      In MFC what is the difference between these functions and what is the fine line calling AfxBeginThread vs calling ::CreateThread

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See here[^].

      1 Reply Last reply
      0
      • T tom groezer

        In MFC what is the difference between these functions and what is the fine line calling AfxBeginThread vs calling ::CreateThread

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        The documentation ([^] and [^]) doesn't help, does it? Roughly speaking, you can spot the main difference in the AfxBeginThread overloaded form supporting user interface threads, i.e.:

        CWinThread* AfxBeginThread(
        CRuntimeClass* pThreadClass,
        int nPriority = THREAD_PRIORITY_NORMAL,
        UINT nStackSize = 0,
        DWORD dwCreateFlags = 0,
        LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
        );

        The above provides some boiler plate code helping, user interface threads development. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • T tom groezer

          In MFC what is the difference between these functions and what is the fine line calling AfxBeginThread vs calling ::CreateThread

          S Offline
          S Offline
          ShilpiP
          wrote on last edited by
          #4

          MSDN Use AfxBeginThread to create a thread object and execute it in one step. Use CreateThread if you want to reuse the thread object between successive creation and termination of thread executions.

          Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

          1 Reply Last reply
          0
          • T tom groezer

            In MFC what is the difference between these functions and what is the fine line calling AfxBeginThread vs calling ::CreateThread

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            On Windows, all the thread creation methods eventually call ::CreateThread() to create the thread. The difference is, AfxBeginThread() does MFC-specific initialization on the thread. The typical rule of thumb is: Use AfxBeginThread() to create a thread in MFC if the thread will use any MFC objects. Use _beginthreadex() to create a thread if no MFC objects are used but CRT functions are used (including new/delete!). Use ::CreateThread() if just Win32 APIs/objects are used. Also make sure you link to the multithread MFC/CRT libraries!! :) Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups