I am looking for a way to pass an object (vector<long> in my case) as a WPARAM in C++11 style.
The tutorials I found used a C-style cast or a reinterpret_cast to pass a pointer to the object. This requires that the recipient of the message properly disposes the object after receiving it.
Is there a way to pass the object using a unique_ptr? The recipient can take full ownership of the object.
If you pass a pointer to an object with a windows message then you need to ensure 2 things:
If you know that the message will definitely be handled then you can call
.release()on the sourceunique_ptrwhen sending the message, and then take ownership in the handler with anotherunique_ptr.The problem comes with ensuring it is cleaned up if the message is NOT handled. This is tricky, as there isn’t usually a clean way to check unless you use
SendMessage(notPostMessage) and use the return value to communicate that the parameter has been claimed.