?
Solved

Multithread - Compile error - might be an easy one

Posted on 2005-03-15
9
Medium Priority
?
393 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

765 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