Transmission string between processes

xiaoxiao2021-03-06  38

During the process, the string BCB_FANS (four famous arrested champions): in the same process

Code: SendMessage (Handle, WM_SETTEXT, (WPARAM) NULL, (LPARAM) "Just a test"); const int WM_TEST = WM_USER 10; void __fastcall TForm1 :: Button2Click (TObject * Sender) {SendMessage (this-> Handle, WM_TEST, (WPARAM) 0, (LPARAM) "Justa A Test");} void __fastcall tform1 :: wm_test: Ansistring str = Ansistring ((char *) message.lparam); Memo1-> Lines -> Add (str); // No problem Break; default: tform :: wndpproc (message); Break;}

Different processes: To pass data in different processes, you can only use messages WM_CopyData, which cannot be used to customize the message. Below is the code that uses the WM_CopyData message, the test is not problematic.

Code: // Send: CopyDataStruct CDS; ANSISTRING DATA = Edit2-> text; // "Just A Test"; cds.dwdata = sizeof (copyDataStruct); cds.cbdata = data.length (); cds.lpdata = (lpvoid Data.c_STR (); // Turning a Target Window Send message WM_CopyData SendMessage ((hwnd) Edit1-> text.Toint (), WM_COPYDATA, (WPARAM) NULL, (LPARAM) & CDS); // Receive: if (Message. msg == WM_COPYDATA) {COPYDATASTRUCT * cds; char * DataBuf; cds = (COPYDATASTRUCT *) Message.LParam; DataBuf = new char [cds-> cbData]; CopyMemory (DataBuf, cds-> lpData, cds-> cbData); Ansistring str = ansistring (databuf); memo1-> lines-> add ("str =" str); delete [] databuf;}

转载请注明原文地址:https://www.9cbs.com/read-58275.html

New Post(0)