Link to home
Start Free TrialLog in
Avatar of Sc0rp
Sc0rp

asked on

Multithread - Compile error - might be an easy one

  I'm trying to use multithread on my program. But when I use _beginthread(MyFunction(),0,0); i get a compile error:

error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void *)' None of the functions with this name in scope match the target type

   I searched internet and I found out that i should use static functions or/and use specific cast but no matters what I do, i still getting that compile error. I'm using vc++6 and I have the lib linked the #include <process.h> and I'm using multithread libs.

   What is funny is that I can run the demo that comes with MSDN without any problem. Maybe the problem is that I'm using windows API. Please don't tell me to use MFC. Or a config of the project. I used an empty windows project for that one that gives me the error and a default project for that one that doesn't.
Avatar of jkr
jkr
Flag of Germany image

>>when I use _beginthread(MyFunction(),0,0); i get a compile error

That should actually be

when I use _beginthread(MyFunction,0,0); i get a compile error

By using theparenthesis, you tell the compiler to use the return value of 'MyFunction()' as a parameter, which is not what you want.
Ooops :o)

I of course meant

_beginthread(MyFunction,0,0);

withoput the rest of the text, LOL
Avatar of Sc0rp
Sc0rp

ASKER

  ye, i tryed that too. Still geting the same error.

   Thanks for reply.
How is 'MyFunction()' declared?
Avatar of Sc0rp

ASKER

void MyFunction();

I also tryied:

static void MyFunction(); // saw the static tip somewhere on internet
Avatar of Sc0rp

ASKER

Anyway the MSDN demo Func is just a "void MyFunc();"
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sc0rp

ASKER

  lol I would never thought about that. I tryied. No compile errors and it seems to work. I already tested my app and no prob :D

   Thank you jkr for the help ;)
You're most welcome :o)