Sender:
Static void main (string [] ARGs)
{
While (true)
{
String strinput = console. Readline ();
If (strinput = "Q ")
Break;
Int hpdf = ipctool. findwindow (null, @ "watermark0 ");
If (hpdf! = 0)
{
Ipctool. copydatastruct CDs;
CDs. dwdata = (intptr) 256;
CDs. lpdata = "Hello csharptestconsole ";
CDs. cbdata = 256;
Ipctool. sendmessage (hpdf, 0x004a, 0, ref CDs );
}
}
}
Acceptor:
// Override Window Proc
Protected override void defwndproc (ref message m)
{
Switch (M. msg)
{
Case 0x004a:
{
Ipctool. copydatastruct CDATA = new ipctool. copydatastruct ();
// CDATA = (ipctool. copydatastruct) Marshal. ptrtostructure (M. lparam, typeof (ipctool. copydatastruct ));
CDATA = (ipctool. copydatastruct) M. getlparam (CDATA. GetType ());
// MessageBox. Show (CDATA. lpdata );
Break;
}
Default:
Base. defwndproc (ref m );
Break;
}
}
Structure Definition:
Public class ipctool
{
Public struct copydatastruct
{
Public intptr dwdata;
Public int cbdata;
[Financialas (unmanagedtype. lpstr)]
Public String lpdata;
}
[Dllimport ("user32.dll", entrypoint = "sendmessage")]
Public static extern int sendmessage (
Int hwnd, // handle of the target window
Int MSG, // message
Int wparam, // The first message Parameter
Ref copydatastruct lparam // The second Message Parameter
);
[Dllimport ("user32.dll", entrypoint = "findwindow")]
Public static extern int findwindow (string lpclassname, string
Lpwindowname );
Const int wm_copydata = 0x004a;
}