How to get the winapi id of a thread that has been created using the standard library?

c++, c++11, multithreading, winapi, windows

Solution

Use the member function `native_handle()`. It provides the native thread handle. Then you can call `GetThreadId()` on it.

Problem

C++11’s standard library contains `<thread>` which allows threads to be created. However, the Windows api requires an ID for some functions (PostThreadMessage, namely). How can I get it? remark: `std::thread::get_id()` doesn’t seem to work: ``` PostThreadMessage(m_thread->get_id(), WM_QUIT, 0, 0); e:\documents\khook\khooker\hook_runner.cpp(129): error C2664: 'PostThreadMessageW' : cannot convert parameter 1 from 'std::thread::id' to 'DWORD' ```

Original source