| 发表于:2007-02-01 13:42:328楼 得分:0 |
to feiyun0112(http://feiyun0112.cnblogs.com/) 这个我上次就试过,不知道为什么还是不行,我把我的测试代码贴出来,请你看看. 发送方: wholeinfo mystruct = new wholeinfo(); ..... // 对里面的变量赋值 intptr p = marshal.allochglobal(marshal.sizeof(mystruct)); marshal.structuretoptr(mystruct, p, true); cds.lpdata = p; sendmessage(window_handler, wm_copydata, 0, ref cds); ----------------------------------------------------------------------------- 接收方: protected override void defwndproc(ref system.windows.forms.message m) { switch (m.msg) { case wm_copydata: copydatastruct mystr = new copydatastruct(); type mytype = mystr.gettype(); mystr = (copydatastruct)m.getlparam(mytype); wholeinfo h; h = (wholeinfo)marshal.ptrtostructure(mystr.lpdata, typeo(wholeinfo)); this.textbox1.text = h.cpath; this.textbox2.text = h.lpath; }....... -------------------------------------------------------------- 先是在h = (wholeinfo)marshal.ptrto...... 处报错, "external component has thrown an exception. " 如果继续往下走,则在main函数中的application.run(new accepterdlg()); 处报错,{ "attempted to read or write protected memory. this is often an indication that other memory is corrupt. "} | | |
|