When you post a message, you don't know when it will be received. It can be received after the string you want to pass is already out of scope.
If you're posting a message to another window in the same process, use the source/sink idiom (AKA producer/consumer):
wchar_t * wstring = new wchar_t;
::PostMessage(HWND, MY_CUSTOM_MESSAGE, 0, (LPARAM) wstring);
LRESULT On_MyCustomMessage(WPARAM , LPARAM lpWstring)
wchar_t *pString = (wchar_t *) lpWstring;
If you're using
, see the
member function. BSTRs are meant to be passed around.
Hope this helps,