Click to See Complete Forum and Search --> : Multiple threads in Windows Form program


Espectro
October 14th, 2009, 01:44 PM
I hope this is the right forum (as I originally posted it in the wrong one - VC++).

Good afternoon people!

First of all, I'm rather a newbie with C++, but I am forced to work with it due to some hardware limitation. I have earlier worked with C# and Java, but right now I'm facing some problems using multiple threads in my program.

In my project (Windows console), I have several threads running in my main application just fine. One of these threads is opening up my Windows form object by using the Application::Run(); command. This is all fine and dandy - and I'm handling threads like this:

_beginthread( joystickthread, 0, (void*)12 );

where the code to be run is like this (sample code):

void joystickthread( void *arg )
{

int h;
h = 4;

}


As mentioned before, this is all working just fine. But whenever I try to use the same commands in my Windows Form class, I get the following error:

Error 1 error C3867: 'hapitest::GUItest::joystickthread2': function call missing argument list; use '&hapitest::GUItest::joystickthread2' to create a pointer to member c:\users\michael\documents\visual studio 2008\projects\hapitest\hapitest\GUItest.h 52 hapitest


I've got no idea what the error is - why is it working in my main program, and not in my Windows Form class?

In hope for an answer
Sincerely
Michael

PS. I hope that it is clear that I would like to have multiple threads in my windows form object (as I have some calculations to do in the background). Thank you

Regards
Michael

darwen
October 16th, 2009, 10:09 AM
Have you tried doing what it tells you to do in the error message ?


_beginthread(&::hapitest::GUItest::joystickthread2, ...)

// probably
_beginthread(&joystickthread2, ...)


You have to put the '&' infront of methods to get a function pointer - I think this is a tightening up on the C++ standard.

Anyway this is a moot point : why not just use .NET threads instead ? (If you do you still have to put '&' infront of methods to reference them as pointers).

Darwen.