You didn’t post any minimal compiling code we can help you debug, so, everything I’m about to say are guesses based on other questions I’ve seen on this topic:
- make sure
asd
is declaredstatic
,CreateThread
is a C function and knows nothing about class methods - make sure
asd
is declared__stdcall
, having wrong calling convention can cause weird and unexpected results. - make sure
this
is not destroyed until your thread finishes running. - make sure your program doesn’t finish before the thread finishes running. you don’t expect to see to output if the program exits before the thread gets a change to print something, right? store the thread handle somewhere, and use
WaitForSingleObject
to make sure the thread work is done. asd
doesn’t return anyDWORD
value. make sure to return some return code.
General notes:
- don’t use C-casts, use C++ cast like
static_cast
- the standard library already has a thread object:
std::thread
. consider using that instead. - Like any system call, you must check the result of any system call. if the returned handle is null, you should check the value of the last error with
GetLastError
.
solved CreateThread() does not work [closed]