我看到另外一篇文章说网上的资料以讹传讹。
说用pb自带的browser看控件的属性和函数事件最好,突然醒悟。
conect有的代码中是不带参数的。有的发送用send。这个应该是控件后面带sp的问题。应该是不同的版本的ocx造成的。有时间我再研究研究。
弄好的界面
这个是接到一个客户搜索pb反编译大师来做的一个小窗口。豆包抄了代码也是不行。
注意那个getdata的使用。string变量不行。9.0的string行。而且要开辟空间,因为是ref引用。
在10以上的系统,习惯使用blob来处理任何二进制的变量。等拿到数据,再自行处理。不要随便用string。麻烦一堆堆。
另外刚开始想用tcp,。但是connect函数调用有问题。所以暂时用udp。
需要的拿代码把。
forward global type w_main from window end type type sle_port2 from editmask within w_main end type type ws_client from olecustomcontrol within w_main end type type sle_ip from singlelineedit within w_main end type type sle_port from editmask within w_main end type type cb_connect from commandbutton within w_main end type type btn_send from commandbutton within w_main end type type sle_send from multilineedit within w_main end type type mle_chat from multilineedit within w_main end type type st_1 from statictext within w_main end type type st_2 from statictext within w_main end type end forward global type w_main from window string tag = "局域网通讯" integer width = 2551 integer height = 2560 boolean titlebar = true string title = "局域网通讯" boolean controlmenu = true boolean minbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true sle_port2 sle_port2 ws_client ws_client sle_ip sle_ip sle_port sle_port cb_connect cb_connect btn_send btn_send sle_send sle_send mle_chat mle_chat st_1 st_1 st_2 st_2 end type global w_main w_main type variables long ii_socket = 0 // 本机socket long ii_client = 0 // 对方连接socket boolean ib_is_server = false end variables on w_main.create this.sle_port2=create sle_port2 this.ws_client=create ws_client this.sle_ip=create sle_ip this.sle_port=create sle_port this.cb_connect=create cb_connect this.btn_send=create btn_send this.sle_send=create sle_send this.mle_chat=create mle_chat this.st_1=create st_1 this.st_2=create st_2 this.Control[]={this.sle_port2,& this.ws_client,& this.sle_ip,& this.sle_port,& this.cb_connect,& this.btn_send,& this.sle_send,& this.mle_chat,& this.st_1,& this.st_2} end on on w_main.destroy destroy(this.sle_port2) destroy(this.ws_client) destroy(this.sle_ip) destroy(this.sle_port) destroy(this.cb_connect) destroy(this.btn_send) destroy(this.sle_send) destroy(this.mle_chat) destroy(this.st_1) destroy(this.st_2) end on event close;ws_client.Object.close() // 关闭 end event type sle_port2 from editmask within w_main integer x = 1042 integer y = 172 integer width = 247 integer height = 112 integer taborder = 60 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "8001" borderstyle borderstyle = stylelowered! string mask = "#####" end type type ws_client from olecustomcontrol within w_main event ocx_error ( integer number, string description, long scode, string source, string helpfile, long helpcontext, boolean canceldisplay ) event dataarrival ( long bytestotal ) event ocx_connect ( ) event connectionrequest ( long requestid ) event ocx_close ( ) event sendprogress ( long bytessent, long bytesremaining ) event sendcomplete ( ) integer x = 928 integer y = 1976 integer width = 128 integer height = 112 integer taborder = 30 borderstyle borderstyle = stylelowered! boolean focusrectangle = false string binarykey = "w_main.win" integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 end type event dataarrival(long bytestotal);//any s_recv[] blob s_recv s_recv = blob(space(2048)) any types any maxlen // 读取数据 ws_client.Object.GetData(ref s_recv) // 显示到聊天框 mle_chat.text += "对方:" + string(s_recv,EncodingANSI!) + "~r~n" //EncodingANSI! // //EncodingUTF8! // //EncodingUTF16LE! (default) // //EncodingUTF16BE! end event event connectionrequest(long requestid);// 有新客户端连接 if ws_client.Object.State <> 0 then ws_client.Object.Close() end if // 接受连接 ws_client.Object.Accept(requestID) mle_chat.text += "客户端已连接~r~n" end event type sle_ip from singlelineedit within w_main integer x = 293 integer y = 40 integer width = 613 integer height = 112 integer taborder = 50 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "192.168.0.10" borderstyle borderstyle = stylelowered! end type type sle_port from editmask within w_main integer x = 375 integer y = 180 integer width = 247 integer height = 112 integer taborder = 40 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "8000" borderstyle borderstyle = stylelowered! string mask = "#####" end type type cb_connect from commandbutton within w_main integer x = 1033 integer y = 28 integer width = 247 integer height = 120 integer taborder = 10 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "设置" end type event clicked;ws_client.object.protocol =1 //winsock通讯协议设为UDP协议 ws_client.object.remotehost=sle_ip.text //对方的ip地址 ws_client.object.remoteport=long(sle_port.text) //对方的winsock通讯端口号 ws_client.object.localport=long(sle_port2.text) //本机的winsock通讯端口号 ws_client.object.bind mle_chat.text = "IP和端口绑定完成~r~n" this.enabled = false end event type btn_send from commandbutton within w_main integer x = 1989 integer y = 32 integer width = 379 integer height = 132 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "发送" end type event clicked;string s_send s_send = sle_send.text if s_send = "" then return // 发送数据(非阻塞) ws_client.Object.SendData(s_send) mle_chat.text += "我方:" + s_send + "~r~n" sle_send.text = "" end event type sle_send from multilineedit within w_main integer x = 64 integer y = 324 integer width = 2359 integer height = 380 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "输入发送的文字..." borderstyle borderstyle = stylelowered! end type type mle_chat from multilineedit within w_main integer x = 64 integer y = 732 integer width = 2363 integer height = 1604 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 boolean vscrollbar = true boolean autovscroll = true boolean displayonly = true borderstyle borderstyle = stylelowered! end type type st_1 from statictext within w_main integer x = 59 integer y = 60 integer width = 1038 integer height = 76 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "IP地址" boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 55 integer y = 196 integer width = 1038 integer height = 76 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "对方端口 我方端口" boolean focusrectangle = false end type最后可以访问我的主页。
------------------------
补充,写了另外窗口,就是其他的exe调用这个窗体完成发送任务。
/* 外部函数申明 Function Long DllRegisterServer() LIBRARY "mswinsck.ocx" FUNCTION ulong FindWindow(string lpClassName,string lpWindowName) LIBRARY "user32.dll" ALIAS FOR "FindWindowA" FUNCTION ulong FindWindow(long lpClassName,string lpWindowName) LIBRARY "user32.dll" ALIAS FOR "FindWindowA" //将源字符串COPY到新分配的内存块中并返回新分配的这个内存地址 Function long lstrcpy(ref string Destination, ref string Source) library "kernel32.dll" //分配指定长度的内存块并返回该内存块的地址 Function long LocalAlloc(long Flags, long Bytes) library "kernel32.dll" //释放指定内存地址的内存块,不要去释放由PB本身分配的那些内存块,只能释放由LocalAlloc分配的内存,否则系统会崩溃 Function long LocalFree(long MemHandle) library "kernel32.dll" //将结构体数据COPY到指定内存地址的内存块中,size为结构体的长度 SUBROUTINE CopyMemory(long pDesc, ref str_copydatastruct pSrc, ulong size) LIBRARY 'kernel32' ALIAS FOR 'RtlMoveMemory' //把指定内存地址的内存块COPY给相同的结构体,size为结构体的长度 SUBROUTINE CopyMemory(ref str_copydatastruct pDesc, long pSrc, ulong size) LIBRARY 'kernel32' ALIAS FOR 'RtlMoveMemory' */ /*一个接头体申明 global type str_copydatastruct from structure long dwdata long cbdata long lpdata end type */ //下面是窗口源码 forward global type w_main from window end type type st_3 from statictext within w_main end type type sle_port2 from editmask within w_main end type type ws_client from olecustomcontrol within w_main end type type sle_ip from singlelineedit within w_main end type type sle_port from editmask within w_main end type type cb_connect from commandbutton within w_main end type type btn_send from commandbutton within w_main end type type sle_send from multilineedit within w_main end type type mle_chat from multilineedit within w_main end type type st_1 from statictext within w_main end type type st_2 from statictext within w_main end type end forward global type w_main from window string tag = "局域网通讯" integer width = 2551 integer height = 2560 boolean titlebar = true string title = "PB_SENDER_01" boolean controlmenu = true boolean minbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true event ue_copydata pbm_copy event writesendlog ( ) st_3 st_3 sle_port2 sle_port2 ws_client ws_client sle_ip sle_ip sle_port sle_port cb_connect cb_connect btn_send btn_send sle_send sle_send mle_chat mle_chat st_1 st_1 st_2 st_2 end type global w_main w_main type variables long ii_socket = 0 // 本机socket long ii_client = 0 // 对方连接socket boolean ib_is_server = false CONSTANT Long WM_COPYDATA = 74 end variables forward prototypes public function integer writesendlog (string s) public function integer writerecvlog (string s) end prototypes public function integer writesendlog (string s);// string filepath filepath = paths + "sendlog\SNED"+ string(today(),"yyyy-mm-dd hhmmss")+".log" long filehandle filehandle = FileOpen(filepath,LineMode!, Write!, LockReadWrite!, Replace!, EncodingUTF8!) if filehandle >0 then filewrite( filehandle,s) fileclose(filehandle) end if return 0 end function public function integer writerecvlog (string s);// string filepath filepath = paths + "recvlog\RECV"+ string(today(),"yyyy-mm-dd hhmmss")+".log" long filehandle filehandle = FileOpen(filepath,LineMode!, Write!, LockReadWrite!, Replace!, EncodingUTF8!) if filehandle >0 then filewrite( filehandle,s) fileclose(filehandle) end if return 0 end function on w_main.create this.st_3=create st_3 this.sle_port2=create sle_port2 this.ws_client=create ws_client this.sle_ip=create sle_ip this.sle_port=create sle_port this.cb_connect=create cb_connect this.btn_send=create btn_send this.sle_send=create sle_send this.mle_chat=create mle_chat this.st_1=create st_1 this.st_2=create st_2 this.Control[]={this.st_3,& this.sle_port2,& this.ws_client,& this.sle_ip,& this.sle_port,& this.cb_connect,& this.btn_send,& this.sle_send,& this.mle_chat,& this.st_1,& this.st_2} end on on w_main.destroy destroy(this.st_3) destroy(this.sle_port2) destroy(this.ws_client) destroy(this.sle_ip) destroy(this.sle_port) destroy(this.cb_connect) destroy(this.btn_send) destroy(this.sle_send) destroy(this.mle_chat) destroy(this.st_1) destroy(this.st_2) end on event close;ws_client.Object.close() // 关闭 end event event other;//如果是跨进程通信(不管是PB应用与PB应用,还是PB应用与其它语言的应用),则必须使用PB窗口事件中的pbm_other事件 //如果不跨进程通信(即在同一个PB应用中),则可以使用PB窗口事件中的pbm_custom01等自定义事件 string ls_msg blob lb_blob string ip string port long posflag2,posflag3 str_CopyDataStruct lstr_data if Message.Number = WM_COPYDATA then CopyMemory(lstr_data, lparam, 12) ls_msg = string(lstr_data.lpdata, "address")//提取内存地址中的内容,格式符中必须是Address lb_blob = blob(ls_msg,EncodingUTF16LE!) //EncodingUTF16LE! is defaultls_result = string(lb_blob, EncodingANSI!) ls_msg = string(lb_blob, EncodingANSI!) sle_send.text = ls_msg //切分ip和端口 if pos(ls_msg,"IP:")>0 then posflag2 = pos(ls_msg,"||PORT:") posflag3 = pos(ls_msg,"|||") ip = mid(ls_msg,4,posflag2 -4) port = mid(ls_msg,posflag2 + 7,posflag3 -posflag2 -7) sle_ip.text = ip sle_port.text = port end if cb_connect.triggerevent(clicked!) btn_send.postevent(clicked!) end if //处理完毕后的返回结果,可以重新定义。如果发送时使用的SendMessage则其一直在等这个结果 return 0 end event event open;// string inipath inipath =paths + "\txrx.ini" this.title = ProfileString(inipath,"sys","WindowTitle","PB_SENDER_01") this.visible = (ProfileInt(inipath,"sys","hide",0) = 0) sle_port2.text = ProfileString(inipath,"sys","portlocal","8001") sle_ip.text = ProfileString(inipath,"sys","remoteip","192.168.1.18") sle_port.text = ProfileString(inipath,"sys","remoteport","8000") cb_connect.triggerevent(clicked!) end event type st_3 from statictext within w_main integer x = 73 integer y = 36 integer width = 320 integer height = 76 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "我方端口" boolean focusrectangle = false end type type sle_port2 from editmask within w_main integer x = 393 integer y = 24 integer width = 274 integer height = 112 integer taborder = 60 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "8001" borderstyle borderstyle = stylelowered! string mask = "#####" end type type ws_client from olecustomcontrol within w_main event ocx_error ( integer number, string description, long scode, string source, string helpfile, long helpcontext, boolean canceldisplay ) event dataarrival ( long bytestotal ) event ocx_connect ( ) event connectionrequest ( long requestid ) event ocx_close ( ) event sendprogress ( long bytessent, long bytesremaining ) event sendcomplete ( ) integer x = 2185 integer y = 196 integer width = 128 integer height = 112 integer taborder = 30 borderstyle borderstyle = stylelowered! boolean focusrectangle = false string binarykey = "w_main.win" integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 end type event dataarrival(long bytestotal);blob s_recv string ls_recv if bytestotal< 10 then return s_recv = blob(space(1024)) // 读取数据 ws_client.Object.GetData(ref s_recv) if mle_chat.LineCount()>20 then mle_chat.text = "" // 显示到聊天框 ls_recv = string(s_recv,EncodingANSI!) mle_chat.text += "对方:" +ls_recv + "~r~n" writerecvlog(ls_recv) end event event connectionrequest(long requestid);// 有新客户端连接 if ws_client.Object.State <> 0 then ws_client.Object.Close() end if // 接受连接 ws_client.Object.Accept(requestID) mle_chat.text += "客户端已连接~r~n" end event type sle_ip from singlelineedit within w_main integer x = 311 integer y = 172 integer width = 613 integer height = 112 integer taborder = 50 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "192.168.1.18" borderstyle borderstyle = stylelowered! end type type sle_port from editmask within w_main integer x = 1353 integer y = 172 integer width = 247 integer height = 112 integer taborder = 40 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "8000" borderstyle borderstyle = stylelowered! string mask = "#####" end type type cb_connect from commandbutton within w_main boolean visible = false integer x = 1358 integer y = 8 integer width = 247 integer height = 120 integer taborder = 10 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "设置" end type event clicked;ws_client.object.close() ws_client.object.protocol =1 //winsock通讯协议设为UDP协议 ws_client.object.remotehost=sle_ip.text //对方的ip地址 ws_client.object.remoteport=long(sle_port.text) //对方的winsock通讯端口号 ws_client.object.localport=long(sle_port2.text) //本机的winsock通讯端口号 ws_client.object.bind() mle_chat.text += "IP和端口绑定完成~r~n" this.enabled = false end event type btn_send from commandbutton within w_main boolean visible = false integer x = 1989 integer y = 32 integer width = 379 integer height = 132 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "发送" end type event clicked;blob b_send string s_send s_send = sle_send.text if s_send = "" then return // 发送数据(非阻塞) b_send = blob(s_send,encodingansi!) ws_client.Object.SendData(b_send) if mle_chat.LineCount()>20 then mle_chat.text = "" mle_chat.text += "接口调用:" + s_send + "~r~n" sle_send.text = "" writesendlog(s_send) end event type sle_send from multilineedit within w_main integer x = 64 integer y = 324 integer width = 2359 integer height = 380 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 string text = "输入发送的文字..." borderstyle borderstyle = stylelowered! end type type mle_chat from multilineedit within w_main integer x = 64 integer y = 732 integer width = 2363 integer height = 1604 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 boolean vscrollbar = true boolean autovscroll = true boolean displayonly = true borderstyle borderstyle = stylelowered! end type type st_1 from statictext within w_main integer x = 59 integer y = 192 integer width = 251 integer height = 76 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "对方IP" boolean focusrectangle = false end type type st_2 from statictext within w_main integer x = 1029 integer y = 188 integer width = 343 integer height = 76 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "对方端口" boolean focusrectangle = false end type下面是主程序调用者的代码
/*外部函数申明 //查找指定显示标题的窗口句柄 FUNCTION ulong FindWindow(string lpClassName,string lpWindowName) LIBRARY "user32.dll" ALIAS FOR "FindWindowA" FUNCTION ulong FindWindow(long lpClassName,string lpWindowName) LIBRARY "user32.dll" ALIAS FOR "FindWindowA" //将源字符串COPY到新分配的内存块中并返回新分配的这个内存地址 Function long lstrcpy(ref string Destination, ref string Source) library "kernel32.dll" ALIAS FOR "lstrcpy" //分配指定长度的内存块并返回该内存块的地址 Function long LocalAlloc(long Flags, long Bytes) library "kernel32.dll" //释放指定内存地址的内存块,不要去释放由PB本身分配的那些内存块,只能释放由LocalAlloc分配的内存,否则系统会崩溃 Function long LocalFree(long MemHandle) library "kernel32.dll" //将结构体数据COPY到指定内存地址的内存块中,size为结构体的长度 SUBROUTINE CopyMemory(long pDesc, ref str_copydatastruct pSrc, ulong size) LIBRARY 'kernel32' ALIAS FOR 'RtlMoveMemory' //把指定内存地址的内存块COPY给相同的结构体,size为结构体的长度 SUBROUTINE CopyMemory(ref str_copydatastruct pDesc, long pSrc, ulong size) LIBRARY 'kernel32' ALIAS FOR 'RtlMoveMemory' */ /*一个传输特殊数据类型的结构体 global type str_copydatastruct from structure long dwdata long cbdata long lpdata end type */ forward global type w_main_caller from window end type type cb_send from commandbutton within w_main_caller end type type mle_msg from multilineedit within w_main_caller end type type sle_port from singlelineedit within w_main_caller end type type sle_ip from singlelineedit within w_main_caller end type type st_2 from statictext within w_main_caller end type type sle_winname from singlelineedit within w_main_caller end type type st_1 from statictext within w_main_caller end type end forward global type w_main_caller from window integer width = 2144 integer height = 1184 boolean titlebar = true string title = "发送测试窗口PB8.0开发的" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_send cb_send mle_msg mle_msg sle_port sle_port sle_ip sle_ip st_2 st_2 sle_winname sle_winname st_1 st_1 end type global w_main_caller w_main_caller type variables CONSTANT Long WM_COPYDATA = 74 end variables on w_main_caller.create this.cb_send=create cb_send this.mle_msg=create mle_msg this.sle_port=create sle_port this.sle_ip=create sle_ip this.st_2=create st_2 this.sle_winname=create sle_winname this.st_1=create st_1 this.Control[]={this.cb_send,& this.mle_msg,& this.sle_port,& this.sle_ip,& this.st_2,& this.sle_winname,& this.st_1} end on on w_main_caller.destroy destroy(this.cb_send) destroy(this.mle_msg) destroy(this.sle_port) destroy(this.sle_ip) destroy(this.st_2) destroy(this.sle_winname) destroy(this.st_1) end on type cb_send from commandbutton within w_main_caller integer x = 1486 integer y = 16 integer width = 530 integer height = 128 integer taborder = 4 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "发送给PB接口" end type event clicked;string ls_Src, ls_Dst long ll_ReceiveWinHandle, ll_Address, ll_SrcLen, ll_CopyDataPointer str_CopyDataStruct lstr_cds //查找接收数据的窗口句柄 ll_ReceiveWinHandle = FindWindow(0,sle_winname.text) if ll_ReceiveWinHandle<1 then messagebox("错误","接口没有打开!") return end if ls_Src = "IP:"+sle_ip.text+"||PORT:"+sle_port.text+"|||" ls_Src += mle_msg.text ls_Dst = space(2048) ll_Address = lstrcpy(ls_Dst, ls_Src) ll_SrcLen = len(ls_Src) + 1 lstr_cds.dwdata = 0//可以是您想传的任意long类型 lstr_cds.cbdata = ll_SrcLen//必须是所传字符串长度再加1,因为还会有一个结束标志 lstr_cds.lpdata = ll_Address//必须是字符串所在内存块的地址 ll_CopyDataPointer = LocalAlloc(0,12) CopyMemory(ll_copyDataPointer,lstr_cds,12) //将保存有结构体的内存块地址以消息的方式发送给目标窗口,事件ID为74,也可以使用API函数SendMessage来发送 //由于使用的是SendMessage(PB把SendMessage封装到Send函数中了),故会等待接收窗口返回结果。如果使用PostMessage则不会等待,只是判断发送是否成功 int ll_rc ll_rc = Send(ll_ReceiveWinHandle, WM_COPYDATA, 0, ll_copyDataPointer) LocalFree(ll_copyDataPointer) end event type mle_msg from multilineedit within w_main_caller integer x = 50 integer y = 356 integer width = 1957 integer height = 640 integer taborder = 5 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "待发送消息" borderstyle borderstyle = stylelowered! end type type sle_port from singlelineedit within w_main_caller integer x = 1472 integer y = 192 integer width = 334 integer height = 116 integer taborder = 3 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "8000" borderstyle borderstyle = stylelowered! end type type sle_ip from singlelineedit within w_main_caller integer x = 567 integer y = 196 integer width = 859 integer height = 116 integer taborder = 2 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "192.168.1.18" borderstyle borderstyle = stylelowered! end type type st_2 from statictext within w_main_caller integer x = 69 integer y = 212 integer width = 457 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "目标IP,端口" boolean focusrectangle = false end type type sle_winname from singlelineedit within w_main_caller integer x = 562 integer y = 24 integer width = 859 integer height = 116 integer taborder = 1 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "PB_SENDER_01" borderstyle borderstyle = stylelowered! end type type st_1 from statictext within w_main_caller integer x = 64 integer y = 56 integer width = 498 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "发送窗口名称" boolean focusrectangle = false end type最后重要的提示注意的是:pb反编译大师,pb decompiler购买联系
ocx控件的两个只要调用getdata和senddata的参数用string都遭到不稳定和运行崩溃的问题,应该是因为pb10是双字节问题。改用blob万无一失。