1

I've tried to create thread with simple _beginthread function in Windows Forms Application (I did it successfully with making console application.

private: System::Void __cdecl counter() {
             do {
                 Sleep(1);
                 stan++;
                 label1->Text = stan.ToString();
             } while(true);
             _endthread();
         }

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             button1->Enabled = false;
             HANDLE licznik = (HANDLE) _beginthread(counter(), 0, 0);
         }
};`

My error (and warning) are:

c:\users\artur\desktop\clock\thread_clock\thread_clock\Form1.h(117): warning C4441: calling convention of '__cdecl ' ignored; '__clrcall ' used instead 1>c:\users\artur\desktop\clock\thread_clock\thread_clock\Form1.h(128): error C2664: '_beginthread' : cannot convert parameter 1 from 'void' to 'void (__cdecl *)(void *)' 1> Expressions of type void cannot be converted to other types

How to prevent that?

Staly
  • 85
  • 7
  • `counter()` calls the function `counter`. If you want to pass the function as an argument, use its name (`counter`) with no parens. – Mat Dec 02 '12 at 15:16
  • Have already tried it, after deleting parens, it appears: `1>c:\users\artur\desktop\clock\thread_clock\thread_clock\Form1.h(128): error C3867: 'thread_clock::Form1::counter': function call missing argument list; use '&thread_clock::Form1::counter' to create a pointer to member ` – Staly Dec 02 '12 at 15:28
  • Why aren't you just using [System::Threading::Thread](http://msdn.microsoft.com/en-us/library/system.threading.threadstart.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1)? Besides you shouldn't be updating the GUI from another thread, use theForm->Invoke. – user786653 Dec 02 '12 at 18:51

0 Answers0