C # inter-process communication copydata

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.