[Solved] CreateThread() does not work [closed]


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:

  1. make sure asd is declared static, CreateThread is a C function and knows nothing about class methods
  2. make sure asd is declared __stdcall, having wrong calling convention can cause weird and unexpected results.
  3. make sure this is not destroyed until your thread finishes running.
  4. 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.
  5. asd doesn’t return any DWORD value. make sure to return some return code.

General notes:

  1. don’t use C-casts, use C++ cast like static_cast
  2. the standard library already has a thread object: std::thread. consider using that instead.
  3. 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]