invalid conversion

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

invalid conversion

 
0
  #1
Oct 16th, 2008
Hi, i'm havnig problem with calling CreateThread. The problem is that it gives me a conversion error from const void* to void*

  1. DWORD dwThreadId;
  2. HANDLE myThread;
  3.  
  4. myThread = CreateThread(
  5. NULL,
  6. 0,
  7. MyThreadFunction,
  8. "HELLO",
  9. 0,
  10. &dwThreadId);

dwThreadId id is the problem, the function is supose to take a pointer to a DWORD.

Thanks for any help
Cgris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: invalid conversion

 
1
  #2
Oct 16th, 2008
Post a complete program that exhibits the problem, please. Also post the exact error message rather than summarizing.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: invalid conversion

 
0
  #3
Oct 16th, 2008
OK, by no means is this safe. It was a meer test to get me started with threads.

  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. DWORD WINAPI MyThreadFunction( LPVOID lpParam );
  5.  
  6. int main()
  7. {
  8. DWORD dwThreadId;
  9. HANDLE myThread;
  10.  
  11. myThread = CreateThread(
  12. NULL,
  13. 0,
  14. MyThreadFunction,
  15. "HELLO",
  16. 0,
  17. &dwThreadId);
  18.  
  19. while(1){
  20. Sleep(3);
  21. std::cout << "main";
  22. }
  23. std::cin.get();
  24. return 0;
  25. }
  26.  
  27. DWORD WINAPI MyThreadFunction( LPVOID lpParam )
  28. {
  29. std::cout << lpParam;
  30. while(1){
  31. Sleep(10);
  32. std::cout << "thread";
  33. }
  34. return 0;
  35. }

exact error: 17 invalid conversion from `const void*' to `void*'

Thanks
Last edited by Freaky_Chris; Oct 16th, 2008 at 4:53 pm.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: invalid conversion

 
1
  #4
Oct 16th, 2008
What compiler are you using?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: invalid conversion

 
0
  #5
Oct 16th, 2008
*cough*
Dev-Cpp
Last edited by Freaky_Chris; Oct 16th, 2008 at 5:02 pm.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: invalid conversion

 
2
  #6
Oct 16th, 2008
I'd be willing to bet that it's the string literal causing you problems. Try this:
  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. DWORD WINAPI MyThreadFunction( LPVOID lpParam );
  5.  
  6. int main()
  7. {
  8. DWORD dwThreadId;
  9. HANDLE myThread;
  10. char *param = "HELLO";
  11.  
  12. myThread = CreateThread(
  13. NULL,
  14. 0,
  15. MyThreadFunction,
  16. param,
  17. 0,
  18. &dwThreadId);
  19.  
  20. while(1){
  21. Sleep(3);
  22. std::cout << "main";
  23. }
  24. std::cin.get();
  25. return 0;
  26. }
  27.  
  28. DWORD WINAPI MyThreadFunction( LPVOID lpParam )
  29. {
  30. std::cout << lpParam;
  31. while(1){
  32. Sleep(10);
  33. std::cout << "thread";
  34. }
  35. return 0;
  36. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: invalid conversion

 
1
  #7
Oct 16th, 2008
Originally Posted by Freaky_Chris View Post
*cough*
Dev-Cpp
THIS compiled ok on dev-cpp:
  1. int main()
  2. {
  3. DWORD dwThreadId;
  4. HANDLE myThread;
  5. void *ptr=NULL;
  6.  
  7. myThread = CreateThread(
  8. NULL,
  9. 0,
  10. MyThreadFunction,
  11. ptr,
  12. 0,
  13. &dwThreadId);
  14.  
  15. while(1){
  16. Sleep(3);
  17. std::cout << "main";
  18. }
  19. std::cin.get();
  20. return 0;
  21. }

notice the void* ptr; I suspect problem is in your "HELLO", not in dwThreadId

[edit]And Narue's code compiles on Dev [/edit]
Last edited by Sci@phy; Oct 16th, 2008 at 5:08 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: invalid conversion

 
0
  #8
Oct 16th, 2008
Ah that would make much more sense. i did wonder, thanks guys.

i feel like a fool now lol!

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: invalid conversion

 
0
  #9
Oct 16th, 2008
Just to mention, you don't have to declare char ptr, you can simply cast string:
(LPVOID)"HELLO";
But, if you want your string to work inside function that you call, you have to typecast it back to (char*)
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: invalid conversion

 
0
  #10
Oct 16th, 2008
Originally Posted by Sci@phy View Post
Just to mention, you don't have to declare char ptr, you can simply cast string:
(LPVOID)"HELLO";
But, if you want your string to work inside function that you call, you have to typecast it back to (char*)
Yes, im aware of both of these, it was just the mere fact i was paying way to much time listening to my god damn compiler / IDE and not enough looking at what i had actually written!

Thanks,
Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC