In Dephi, I create a thread, like this, which will send message to main form from time to time
Procedure TMyThread.SendLog(I: Integer);
Var
Log: array[0..2
Use SendMessage().
PostMessage() will process your message asynchronously, it basically puts into the target message queue and Returns immediately. At the time where the handler code accesses the data sent in wparam/lparam, your caller has already freed the string.
In contrast, SendMessage() bypasses the message queue and calls the window proc directly (synchronously). At the time when SendMessage() returns, it is safe to free the string.