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

The C ++ 11s standard library contains <thread> , which allows you to create threads. However, for Windows api, an ID is required for some functions ( PostThreadMessage , namely). How can i get it?

note: std::thread::get_id() does not 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' 
+7
source share
2 answers

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

+11
source

The thread::id class allows comparisons between id and output. It does not provide a means to access the actual base id . You can try to output it to stringstream and then, apparently, play it out.

0
source

All Articles