Here is my prototype:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool PostMessage(int hhwnd, uint msg, IntPtr wparam, IntPtr lparam);
And here is how I use it:
PostMessage(HWND_BROADCAST, msg, Marshal.StringToHGlobalAuto("bob"), IntPtr.Zero);
In another thread, I can intercept this message, but when I try to return bob with:
string str = Marshal.PtrToStringAuto(m.WParam);
I do not get bob in str.
I think this should be due to the fact that I was referring to the string "bob" in one thread stack, and this link makes absolutely no sense in another thread stack. But if that is the case, are these wparam and lparam pointers really only used for messages being sent on the same thread?
Edit * Bugfix: By stream, I mean the process. This is the problem of passing a string between processes, not threads.
source
share