Use wm_copydata to share data between processes

Source: Internet
Author: User
Message function: share data between processes (create a memory ing file internally) Message Introduction: Required Data Structure / Type: typedef  Struct  Tagcopydatastruct {ulong_ptr dwdata; DWORD cbdata; pvoid lpdata;} copydatastruct, * Pcopydatastruct; struct parameter description: dwdata (ulong) stores a value, which can be used as a flag such as lpdata (  Void * ) Start address of the data to be sent (can be null) cbdata (DWORD) parameter of the message length of the data to be sent: hwnd: handle of the window for receiving data wparam: the window handle that transmits the data (null does not matter) lparam: Address of the copydatastruct type variable use example: copydatastruct CDs;  Char MSG [] = " Girl does not cry  "  ; CDs. dwdata = 0  ; CDs. lpdata = MSG; CDs. cbdata = Strlen (MSG) + 1 ; //  Please remember to add '\ 0' to the string, or else it will be wrong. Here is the ANSI string Sendmessage (findwindow ( "  Nbsg_class  " , Null), wm_copydata, 0 , (Lparam )&CDs); the receiving end may process the message:  Case  Wm_copydata :{  //  The message here should be a string ending with '\ 0' Copydatastruct * PCDs = (copydatastruct * ) Lparam; MessageBox (hwnd, PCDs -> Lpdata, ""  , Mb_ OK );  Return  True;} description:  
The sent data can be arbitrary. I just used MessageBox for testing, so the sent data is a string of '\ 0.
If the application that receives the messageProgramIf the message is processed, true is returned; otherwise, false is returned. lpdata points to a memory segment. " Data " That is to say, there should be no pointer to a certain data of the program. because sendmessage only copies the cbdata bytes pointed to by lpdata to the shared memory when processing wm_copydata. the private pointer of the current process is not accessible even if it is sent to the receiving program. when the message is sent properly, other threads of the process cannot modify the data. the acceptor application should use this shared memory as the read-only memory for access. do not try to modify the content. the data indicated by lparam is valid only when the message is processed. The returned message is invalid (the shared memory has been released ). the acceptor cannot release the memory. if you want to continue obtaining data after the message is returned, you can copy it to a location of the current process.

Girl don't cry (QQ: 191035066) @ 2012-09-11 23:25:31 @ http://www.cnblogs.com/nbsofer

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.