pb利用NetMessageBufferSend在局域网发送中文消息(实现cmd中 NET SEND功能)

 

         这是一个窗口w_main的导出对象,需要的自己保存为文件,再导入。

        这个版本其实来自网上,只是网上的那个不能发送中文,现在做了修改,支持发送中文了。

        记住,net send 依赖于系统服务Messenger,在使用API函数 NetMessageBufferSend 前必须保证该服务已经启用(需要在程序中自动启用该服务的,可以下载pb操作系统服务——重启MSSQLSERVER 自己整合)。

 

$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type mle_1 from multilineedit within w_main
end type
type cb_1 from commandbutton within w_main
end type
type sle_1 from singlelineedit within w_main
end type
type st_2 from statictext within w_main
end type
type st_1 from statictext within w_main
end type
type icmp_echo_reply from structure within w_main
end type
end forward

type icmp_echo_reply from structure
    unsignedlong        address
    unsignedlong        status
    unsignedlong        roundtriptime
    unsignedlong        datasize
    unsignedlong        reserved[3]
    character       data[250]
end type

global type w_main from window
integer x = 1056
integer y = 484
integer width = 1531
integer height = 1152
boolean titlebar = true
string title = "NETMESSAGESEND"
boolean controlmenu = true
boolean minbox = true
boolean resizable = true
long backcolor = 80269524
mle_1 mle_1
cb_1 cb_1
sle_1 sle_1
st_2 st_2
st_1 st_1
end type
global w_main w_main

type prototypes
Function ulong IcmpCreateFile () Library "icmp.dll"
Function long IcmpSendEcho (ulong IcmpHandle, ulong DestinationAddress, string RequestData,long RequestSize, long RequestOptions, Ref icmp_echo_reply ReplyBuffer, long ReplySize, long Timeout ) Library "icmp.dll" Alias for "IcmpSendEcho"
Function long IcmpCloseHandle (ulong IcmpHandle) Library "icmp.dll"
Function ulong inet_addr (string cp) Library "ws2_32.dll" Alias for "inet_addr"

Function ulong NetMessageBufferSend(ulong servername, ref char msgname[],ulong fromname, ref char buf[], ulong buflen) Library "netapi32.dll" Alias for "NetMessageBufferSend"
function ulong MultiByteToWideChar(uint codepage, ulong dwflags, ref string lpmultibytestr, int cchmultibyte, ref char lpwidecharstr[], int cchwidechar) library "kernel32.dll" alias for "MultiByteToWideChar"

end prototypes
type variables
CONSTANT ulong NERR_Success = 0

end variables
forward prototypes
public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext)
public function boolean wf_ping (string as_ipaddress, string as_echomsg)
public subroutine wf_string2unicode (ref character as_unicode[], string as_string)
end prototypes

public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext);Ulong lul_result, lul_buflen

Char lc_msgname[],lc_msgtext[]
string ls1, ls2
wf_string2unicode( lc_msgname, as_sendto)
wf_string2unicode( lc_msgtext, as_msgtext)

lul_buflen = UpperBound(lc_msgtext)

lul_result = NetMessageBufferSend(0, lc_msgname,0, lc_msgtext, lul_buflen)

If lul_result = NERR_Success Then
    Return True
Else
    Return False
End If

end function

public function boolean wf_ping (string as_ipaddress, string as_echomsg);ULong lul_address, lul_handle
Long ll_rc, ll_size
String ls_reply
icmp_echo_reply lstr_reply

lul_address = inet_addr(as_ipaddress)
If lul_address > 0 Then
    lul_handle = IcmpCreateFile()
    ll_size = Len(as_echomsg)
    ll_rc = IcmpSendEcho(lul_handle, lul_address, &
                        as_echomsg, ll_size, 0, &
                        lstr_reply, 278, 200)
    IcmpCloseHandle(lul_handle)
    If ll_rc <> 0 Then
        If lstr_reply.Status = 0 Then
            ls_reply = String(lstr_reply.Data)
            If ls_reply = as_echomsg Then
                Return True
            End If
        End If
    End If
End If
 
Return False

end function

public subroutine wf_string2unicode (ref character as_unicode[], string as_string);char lc_data[]
long ll_len, ll_rc
ll_len = lenw(as_string) * 2
lc_data = space(ll_len)

ll_rc = multibytetowidechar(936, 0, as_string , -1, lc_data, ll_len)

as_unicode = lc_data
as_unicode[upperbound(as_unicode) + 1] = char(0)
as_unicode[upperbound(as_unicode) + 1] = char(0)
end subroutine

on w_main.create
this.mle_1=create mle_1
this.cb_1=create cb_1
this.sle_1=create sle_1
this.st_2=create st_2
this.st_1=create st_1
this.Control[]={this.mle_1,&
this.cb_1,&
this.sle_1,&
this.st_2,&
this.st_1}
end on

on w_main.destroy
destroy(this.mle_1)
destroy(this.cb_1)
destroy(this.sle_1)
destroy(this.st_2)
destroy(this.st_1)
end on

type mle_1 from multilineedit within w_main
integer x = 27
integer y = 264
integer width = 1399
integer height = 604
integer taborder = 20
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
string text = "你好"
borderstyle borderstyle = stylelowered!
end type

type cb_1 from commandbutton within w_main
integer x = 1070
integer y = 904
integer width = 357
integer height = 108
integer taborder = 30
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
string text = " 发送(&S)"
end type

event clicked;if not wf_ping(trim(sle_1.text),"") then
    messagebox("提示","指定目标地址不存在或不通!")
    return
end if

 

if wf_NetMessageBufferSend(trim(sle_1.text),trim(mle_1.text)) then
   //messagebox("提示","发送成功!")
else
   messagebox("提示","发送失败!")   
end if

end event

type sle_1 from singlelineedit within w_main
integer x = 430
integer y = 48
integer width = 997
integer height = 92
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
string text = "hhyy"
boolean autohscroll = false
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_main
integer x = 14
integer y = 172
integer width = 379
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
string text = "发送内容:"
boolean focusrectangle = false
end type

type st_1 from statictext within w_main
integer x = 14
integer y = 52
integer width = 379
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
string text = "目标地址:"
boolean focusrectangle = false
end type


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值