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