ipc - Why dwData = new IntPtr(0) would work in WM_COPYDATA (c# visual studio 2015) -
when set copydatastruct, set {
dwdata = new intptr(0) } , , sender send message receiver. however, when tried {
dwdata = new intptr(xxothernumbersxxx) } , not work. can explain me dwdata doing here? thanks!
(p.s. newbie software engineer passionate heart learn, gentle on ratings.... plz.....)
here source code sender in c# :
using system; using system.diagnostics; using system.runtime.interopservices; using system.windows.forms; // application sender // made work receiver made in pascal xxxxxx // receiver located @ // "k:\xxxxxxxxxxx" // // application meant send string "hello world" receiver // if successful, receiver appear on screen: // // wm_copydata from: 3819 // received string "hello world!" @ 6/3/2015 // // application: // 1. put "hello world!" message data structure called "copydatastuct" // 2. find receiver app title "receivermainform" , class "treceivermainform" (debug window: pop-up window should show non-zero integers) // 3. send message in copydatastruct through wm_copydata code receiver namespace findnotepad { class program { //include sendmessage [dllimport("user32.dll")] public static extern int sendmessage(intptr hwnd, int umsg, int wparam, ref copydatastruct lparam); //include sendmessage [dllimport("user32.dll")] public static extern intptr findwindow(string lpszclass, string lpszwindow); //this constant indicating window want send text message const int wm_copydata = 0x004a; static void main(string[] args) { // ---------------- 1. set message sent ----------------------- //put "hello world!" message data structure called "copydatastuct" string msg = "hello world!"; var cds = new copydatastruct { dwdata = new intptr(0), cbdata = msg.length + 1, lpdata = msg }; // ---------------- 2. find receiver application window ----------------------- intptr receiverhandle = findwindow("treceivermainform", "receivermainform"); // debug window pop-up messagebox.show(receiverhandle.tostring()); // ---------------- 3. send message receiver ----------------------- try { sendmessage(receiverhandle, wm_copydata, 3819, ref cds); // receiverhandle: handle receiver window // wm_copydata: application sends wm_copydata message pass data application // 3819: handle of sender application, preset integer can work. distinguish sender sends message on receiver // ref cds: data structure contains message sent. } catch (exception ex) { messagebox.show(ex.message); } } //used wm_copydata string messages public struct copydatastruct { //dwdata //the data passed receiving application. public intptr dwdata; // cbdata // size, in bytes, of data pointed lpdata member. public int cbdata; // lpdata // data passed receiving application. member can null. public string lpdata; } } }
Comments
Post a Comment