| | |
invalid conversion
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi, i'm havnig problem with calling CreateThread. The problem is that it gives me a conversion error from const void* to void*
dwThreadId id is the problem, the function is supose to take a pointer to a DWORD.
Thanks for any help
Cgris
C++ Syntax (Toggle Plain Text)
DWORD dwThreadId; HANDLE myThread; myThread = CreateThread( NULL, 0, MyThreadFunction, "HELLO", 0, &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
OK, by no means is this safe. It was a meer test to get me started with threads.
exact error: 17 invalid conversion from `const void*' to `void*'
Thanks
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream> DWORD WINAPI MyThreadFunction( LPVOID lpParam ); int main() { DWORD dwThreadId; HANDLE myThread; myThread = CreateThread( NULL, 0, MyThreadFunction, "HELLO", 0, &dwThreadId); while(1){ Sleep(3); std::cout << "main"; } std::cin.get(); return 0; } DWORD WINAPI MyThreadFunction( LPVOID lpParam ) { std::cout << lpParam; while(1){ Sleep(10); std::cout << "thread"; } return 0; }
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
I'd be willing to bet that it's the string literal causing you problems. Try this:
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream> DWORD WINAPI MyThreadFunction( LPVOID lpParam ); int main() { DWORD dwThreadId; HANDLE myThread; char *param = "HELLO"; myThread = CreateThread( NULL, 0, MyThreadFunction, param, 0, &dwThreadId); while(1){ Sleep(3); std::cout << "main"; } std::cin.get(); return 0; } DWORD WINAPI MyThreadFunction( LPVOID lpParam ) { std::cout << lpParam; while(1){ Sleep(10); std::cout << "thread"; } return 0; }
I'm here to prove you wrong.
THIS compiled ok on dev-cpp:
notice the
[edit]And Narue's code compiles on Dev
[/edit]
C++ Syntax (Toggle Plain Text)
int main() { DWORD dwThreadId; HANDLE myThread; void *ptr=NULL; myThread = CreateThread( NULL, 0, MyThreadFunction, ptr, 0, &dwThreadId); while(1){ Sleep(3); std::cout << "main"; } std::cin.get(); return 0; }
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.
•
•
•
•
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*)
Thanks,
Chris
Knowledge is power -- But experience is everything
![]() |
Similar Threads
- Invalid conversions while using other people's software (C++)
- need help w/ 'invalid conversion' (C++)
- Convert first character from lowercase to uppercase? (C)
- C++ program using classes (C++)
- Is this how to read in char only (C++)
- passing a vector to a function? :errors: (C++)
Other Threads in the C++ Forum
- Previous Thread: rock paper scissor program
- Next Thread: Inserting a node on a Tree
| Thread Tools | Search this Thread |
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg simple string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






