?
Solved

thread error

Posted on 2004-04-23
5
Medium Priority
?
732 Views
Last Modified: 2007-12-19
#pragma once

namespace example
{
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;
      mytest * obj1;
      static void testthread()
      {
            obj1 = new mytest();
      }
      public __gc class Form1 : public System::Windows::Forms::Form
      {      
      public:

            Form1(void)
            {
                  InitializeComponent();
                  _beginthread(testthread, 0, NULL);
            }

      protected:
            void Dispose(Boolean disposing)
            {
                  if (disposing && components)
                  {
                        components->Dispose();
                  }
                  __super::Dispose(disposing);
            }
      private: System::Windows::Forms::ListBox *  listBox1;
      private: System::Windows::Forms::ListBox *  listBox2;

      private:
            System::ComponentModel::Container * components;
            void InitializeComponent(void)...
==========================================================================
This is the error i am getting eventhough I defined the function testthread as static.

error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void *)'

THanks for any input.
      
0
Comment
Question by:lordiano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 200 total points
ID: 10902778
>>error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void *)'

use

    static void __cdecl testthread(LPVOID)
    {
         obj1 = new mytest();
    }

0
 

Author Comment

by:lordiano
ID: 10905233
Hi jkr, thanks for input
it doesnt seem to work,
if i use
static void __cdecl testthread(LPVOID)
it seems that the compiler does not like LPVOID says that the identifier is unknown or something, then i removed the LPVOID and i would still get the same error...
0
 

Author Comment

by:lordiano
ID: 10905267
Actually I changed LPVOID to void* dummy and now it works
But What can I do if i want to make my testthread(void * dummy) be able to modify my windows form components?
Say i want it to be able to add stuffs in Form1->listBox1
I cannot seem to create that static void __cdecl testthread inside the Form1 class.. or at least i dont know how
0
 
LVL 86

Expert Comment

by:jkr
ID: 10908523
>>But What can I do if i want to make my testthread(void * dummy) be able to modify my windows
>>form components?

You'd pass the necessary information via that 'void*'.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 300 total points
ID: 10913546
>> But What can I do if i want to make my testthread(void * dummy) be able to modify my windows form components?

Change the call of _beginthread in Form1 constructor to this

        Form1(void)
          {
               InitializeComponent();
               _beginthread(testthread, 0, this);
          }

And in thread function do this

    static void __cdecl testthread(void* pParam)
    {
        static char* pMsg = "Thread started successfully";
         Form1* pForm = (Form1*)pForm;
         // do something with pForm, e. g. send a message
         pForm->PostMessage(WM_APP + 1, 1, (LPARAM) pMsg );
 
         obj1 = new mytest();
    }

If you call a member function from thread be aware that calling is asynchronous in the thread's context. i. e. you may not change member variables while not using synchronisation objects like CriticalSection or Mutex.

Regards, Alex
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question