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.
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.
Ooops :o)
I of course meant
_beginthread(MyFunction,0, 0);
withoput the rest of the text, LOL
I of course meant
_beginthread(MyFunction,0,
withoput the rest of the text, LOL
ASKER
ye, i tryed that too. Still geting the same error.
Thanks for reply.
Thanks for reply.
How is 'MyFunction()' declared?
ASKER
void MyFunction();
I also tryied:
static void MyFunction(); // saw the static tip somewhere on internet
I also tryied:
static void MyFunction(); // saw the static tip somewhere on internet
ASKER
Anyway the MSDN demo Func is just a "void MyFunc();"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ;)
Thank you jkr for the help ;)
You're most welcome :o)
That should actually be
when I use _beginthread(MyFunction,0,
By using theparenthesis, you tell the compiler to use the return value of 'MyFunction()' as a parameter, which is not what you want.