Data delivery between Win9x downstream
Everyone knows that an application in Window 9x cannot directly access another program's memory address, because Win9X provides its own virtual space for each run, however, it also makes two There is no way to exchange data between a program, but this is not to say that the program will not be data transmission. Win9X provides us with a few special methods to implement this purpose, such as the WINDOWS message WM_COPYDATA and storage impact files. . Use the message WM_COPYDATA to transfer the memory address of the data buffer that needs to be passed, before, we cannot send the address of the memory block from an application to another, because the address in a virtual storage space is meaningless in another address space . However, the WM_COPYDATA message returns some special operations in the background, so we can get the correct address in the recipient. This message needs to be passed to pass the handle of the window being sent, and a pointer to the TcopyDataStruct structure. The structure is as follows: tagcopydatatruct = Packed Recorddwdata: dword; // This is an additional 32-bit parameter; CBData: dword; // We will pass the size of the data buffer; LPDATA: POINTER; / / Pointer to the data buffer . End; TcopyDataStruct = Tag CopyDataStruct; an example, the SendData program contains a text box that sends the content in the text box to the getData program in its onchange event.
In SendCopyData program, a text box OnChange event handler is as follows: procedure TForm1.InputEditChange (Sender: TObject); varcds: TCopyDataStruct; ss: PChar; targetHandle: THandle; begincds.cbData: = Length (InputEdit.Text) 1; GetMem (s, cds.cbdata); // Apply for the CBDATA size buffer and assign the needle to SS; strcopy (SS, PCHAR (INPUTEDIT.TEXT); cds.lpdata: = ss; // Set buffer pointer TargetHandle : = FindWindow ( 'TForm1', 'GetCopyData'); // Get API function "GetCopyData" window handle if targetHandle = 0 thenbeginShowMessage ( 'don''t find target window'); exit; end; SendMessage (targetHandle, WM_COPYDATA , Handle, integer ((@ cds)))); // Send a target window to the CDS structure pointer; // target Leak the target window handle; // Handle Send the window handle of the message; FreeMem (SS); End; in the getCopyData program by a custom message handler accepts wm_CopyData message: publicprocedure GetCopyData (var msg: TWMCopyData); message WM_COPYDATA; procedure TForm1.GetCopyData (var msg: TWMCopyData); beginwith msg.CopyDataStruct ^ dobeginForm1.Edit1.Text: = PChar ( LPDATA); END; END; where the TWMCopyData structure is defined as follows: TWMCopyData = Recordmsg: cardinal; from: hwnd; // Send the message of the window CopyDataStruct: pcopyDataStruct; //, the consult: longint; End; except for WM_COPYDATA In addition to messaging data, Windows also provides file_mapping memory sharing technology to implement program data sharing.