Re: PostThreadMessage in c#
What did you mean by this:
Quote:
Originally Posted by
sulabh120881
if I send msg in interger format then I am able to get the data.
But I want to send/recv data in structure format only.
:confused:
Re: PostThreadMessage in c#
Hi,
Here I want to say
in PostThreadMessage(int threadId, uint msg, ushort wParam, uint lParam);
if I send msg = 10, lParam = 20, I can see the data in GetMessage's MSG structure.
But if I want to send some string value how I can send it.
I tried it
string s = "bob";
char[] buff = new char[100];
s.CopyTo(0, buff, 0, s.Length);
unsafe
{
fixed (char* pbuff = buff) postit((uint)pbuff);
}
where postit is
PostThreadMessage(idthread, 11, 0, buff);
but not able to recv this string with GetMessage()
Re: PostThreadMessage in c#
Are you using PostThreadMessage across different processes, or merely between threads of the same process? If you are posting across different processes, then since each process has its own memory, one process will not be able to see the memory content of another.
You might want to consider the WM_COPYDATA message if posting between different processes: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Incidentally, use of PostThreadMessage is definitely BAD if the target thread has any visible UI. If the UI of the target thread is being manipulated by the user, then the posted message will be LOST: "PRB: PostThreadMessage Messages Lost When Posted to UI Thread" at http://support.microsoft.com/kb/183116
Mike
Re: PostThreadMessage in c#
In C#, there's no need to call postthreadmessage. Instead use the builtin threading functionality of C#.
Like backgroundworker class. Also check out InvokeRequired property.