0

Win32 API:PostMessage

BOOL WINAPI PostMessage(
  _In_opt_ HWND   hWnd,
  _In_     UINT   Msg,
  _In_     WPARAM wParam,
  _In_     LPARAM lParam
);

I have a shared_ptr created in a worker thread, and I need to pass it to the UI thread. How can I do it?

I have defined my own message WM_USER_THREAD, hWnd is the main window.

Zach
  • 5,715
  • 12
  • 47
  • 62
  • http://stackoverflow.com/a/2515285/2864740 - note LPARAM's definition. (Concurrency / access issues are a separate animal.) – user2864740 May 14 '15 at 01:40
  • @user2864740, thanks for your link. But LPARAM is a raw pointer. How to hold a shared_ptr? – Zach May 14 '15 at 01:50
  • How would one pass any object as a pointer? [shared_ptr](http://en.cppreference.com/w/cpp/memory/shared_ptr) is just a class of which instances are created.. Imagine this: what if the 'passed' object was: `struct { shared_ptr<..> my_ptr; }`? It's the same for a shared_ptr object, just with one less level of indirection. – user2864740 May 14 '15 at 01:51
  • This question has in-depth analysis and may help you: https://stackoverflow.com/questions/25667226/how-can-i-use-shared-ptr-using-postthreadmessage – Morris Feb 21 '18 at 11:46

0 Answers0