Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Multithread - Compile error - might be an easy one

Posted on 2005-03-15
9
Medium Priority
?
394 Views
Last Modified: 2008-01-09
  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.
0
Comment
Question by:Sc0rp
  • 5
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13550779
>>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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13550783
Ooops :o)

I of course meant

_beginthread(MyFunction,0,0);

withoput the rest of the text, LOL
0
 

Author Comment

by:Sc0rp
ID: 13550796
  ye, i tryed that too. Still geting the same error.

   Thanks for reply.
0
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.

 
LVL 86

Expert Comment

by:jkr
ID: 13550803
How is 'MyFunction()' declared?
0
 

Author Comment

by:Sc0rp
ID: 13550821
void MyFunction();

I also tryied:

static void MyFunction(); // saw the static tip somewhere on internet
0
 

Author Comment

by:Sc0rp
ID: 13550832
Anyway the MSDN demo Func is just a "void MyFunc();"
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 13550855
>>  Anyway the MSDN demo Func is just a "void MyFunc();"

Actually, according to the docs, it is (and that's what you should use)

void MyFunc(void*);

Have you tried that one also? '_beginthread()' is declared as

unsigned long _beginthread( void( __cdecl *start_address )( void * ), unsigned stack_size, void *arglist );

so your thread proc needs to take a 'void*' as the argument.
0
 

Author Comment

by:Sc0rp
ID: 13550883
  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 ;)
0
 
LVL 86

Expert Comment

by:jkr
ID: 13550891
You're most welcome :o)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

572 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