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 asdis declaredstatic,CreateThreadis a C function and knows nothing about class methods
- make sure asdis declared__stdcall, having wrong calling convention can cause weird and unexpected results.
- make sure thisis 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 WaitForSingleObjectto make sure the thread work is done.
- asddoesn’t return any- DWORDvalue. 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]