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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. _beginthread newbie question

_beginthread newbie question

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
8 Posts 6 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
    tareqsiraj
    wrote on last edited by
    #1

    Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

    R R T L V 6 Replies Last reply
    0
    • T tareqsiraj

      Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      Have you declared the thread function as a static ? ~RaGE();

      1 Reply Last reply
      0
      • T tareqsiraj

        Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

        R Offline
        R Offline
        Renjith Ramachandran
        wrote on last edited by
        #3

        In the Thread function You must specify the Calling convention of the Function Like unsigned __stdcall YourThreadFunction(void* pVoid) { return something; } and try to write the fucntion a a pubic, not a member

        1 Reply Last reply
        0
        • T tareqsiraj

          Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

          T Offline
          T Offline
          tareqsiraj
          wrote on last edited by
          #4

          Thankx Rage for the quick reply. I didnt make the function static. That was the problem. Now it works fine but i have another problem. Can i access any objects declared in the mail dlg class? I have an edit box named _edit. if i use _edit.AppendText("blah blah"), it gives me the following error. :(( error C2228: left of '.AppendText' must have class/struct/union type Thankx again for your response. -Tareq

          J 1 Reply Last reply
          0
          • T tareqsiraj

            Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            1. modify your ThreadFunc like this: void ThreadFunc(void * dummy) 2. call _beginthread like this: _beginthread(ThreadFunc, 0, this); 3. again, modify your ThreadFunc to call a member function of your CMainDlg:

            void ThreadFunc(void * dummy)
            {
            CMainDlg* m_pDlg = (CMainDlg*)dummy;
            if(m_pDlg != NULL)
            m_pDlg->ThreadFunc(NULL);
            }

            regards

            1 Reply Last reply
            0
            • T tareqsiraj

              Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

              V Offline
              V Offline
              Vitali Halershtein
              wrote on last edited by
              #6

              Hi, Your thread ThreadFunc is CMainDlg mamber. To use CRT _beginthread try to declare it as separate function as: void ThreadFunc(void * dummy) { } Or try to use AfxBeginThread, or CreateThread Hope it help. Vitali

              1 Reply Last reply
              0
              • T tareqsiraj

                Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error. error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)' I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h _beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... } Any help/pointer will be very helpful. Thankx in advance. -Tareq

                T Offline
                T Offline
                tareqsiraj
                wrote on last edited by
                #7

                Thank you all for your replys. Greg S. your solution worked like a charm and its so obvious ... i only forgot to cast it to the editor pointer inside the thread function. :D ... again thank you all for your solutions. -Tareq

                1 Reply Last reply
                0
                • T tareqsiraj

                  Thankx Rage for the quick reply. I didnt make the function static. That was the problem. Now it works fine but i have another problem. Can i access any objects declared in the mail dlg class? I have an edit box named _edit. if i use _edit.AppendText("blah blah"), it gives me the following error. :(( error C2228: left of '.AppendText' must have class/struct/union type Thankx again for your response. -Tareq

                  J Offline
                  J Offline
                  Jim Crafton
                  wrote on last edited by
                  #8

                  You're inside a static function of a class - therefor you can't access member functions. Typically what people do is pass in a application variable to the thread's void* argument. In your case, this would be a pointer to the instance of your Dialog class. then you could refernece it. However with that solved your next problem will arise in making changes to UI controls from outside the main UI thread of execution. You must be very careful when doing this or risk causing lock, or various other wicked and evil things to happen. To simplify this, you might consider Posting a message back to your dialog class instance and then accessing the control there. This way you ensure that you're back in the context of the main UI thread. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

                  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