数据库

本类阅读TOP10

·SQL语句导入导出大全
·SQL Server日期计算
·SQL语句导入导出大全
·SQL to Excel 的应用
·Oracle中password file的作用及说明
·MS SQLServer OLEDB分布式事务无法启动的一般解决方案
·sqlserver2000数据库置疑的解决方法
·一个比较实用的大数据量分页存储过程
·如何在正运行 SQL Server 7.0 的服务器之间传输登录和密码
·SQL中两台服务器间使用连接服务器

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
如何调用NetMessageBufferSend发送消息?(改编)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

如何调用NetMessageBufferSend发送消息?

问题描述:

如何调用WINNT/2K/XP下的API函数NetMessageBufferSend模拟net send命令来发送消息?

解决方案:

下面代码已测试成功,直接导入PBL即可

 

$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

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

int X=1056

int Y=484

int Width=1531

int Height=1152

boolean TitleBar=true

string Title="NETMESSAGESEND"

long BackColor=80269524

boolean ControlMenu=true

boolean MinBox=true

boolean Resizable=true

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 NetMessageBufferSend(ulong servername, ref char msgname[],ulong fromname, ref char buf[], ulong buflen) Library "netapi32.dll" Alias for "NetMessageBufferSend"

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"

end prototypes

type variables

CONSTANT ulong NERR_Success = 0

end variables

forward prototypes

public subroutine wf_string_to_unicode (string as_string, ref character ac_unicode[])

public subroutine wf_string_to_unicode (string as_string, ref character ac_unicode[])

public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext)

public function boolean wf_ping (string as_ipaddress, string as_echomsg)

end prototypes

 

public subroutine wf_string_to_unicode (string as_string, ref character ac_unicode[]);Integer li_loop, li_len, li_uni

 

li_len = Len(as_string)

 

FOR li_loop = 1 TO li_len

    li_uni = li_uni + 1

    ac_unicode[li_uni] = Mid(as_string, li_loop, 1)

    li_uni = li_uni + 1

    ac_unicode[li_uni] = Char(0)

NEXT

 

li_uni = li_uni + 1

ac_unicode[li_uni] = Char(0)

li_uni = li_uni + 1

ac_unicode[li_uni] = Char(0)

 

end subroutine

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

Char lc_msgname[],lc_msgtext[]

 

wf_string_to_unicode(as_sendto, lc_msgname)

wf_string_to_unicode(as_msgtext, lc_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

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

int X=27

int Y=264

int Width=1399

int Height=604

int TabOrder=20

BorderStyle BorderStyle=StyleLowered!

long TextColor=33554432

int TextSize=-10

int Weight=400

string FaceName="方正姚体"

FontCharSet FontCharSet=GB2312CharSet!

FontPitch FontPitch=Variable!

end type

 

type cb_1 from commandbutton within w_main

int X=1070

int Y=904

int Width=357

int Height=108

int TabOrder=30

string Text=" 发送(&S)"

int TextSize=-10

int Weight=400

string FaceName="方正姚体"

FontCharSet FontCharSet=GB2312CharSet!

FontPitch FontPitch=Variable!

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

int X=430

int Y=48

int Width=997

int Height=92

int TabOrder=10

BorderStyle BorderStyle=StyleLowered!

boolean AutoHScroll=false

long TextColor=33554432

int TextSize=-10

int Weight=400

string FaceName="方正姚体"

FontCharSet FontCharSet=GB2312CharSet!

FontPitch FontPitch=Variable!

end type

 

type st_2 from statictext within w_main

int X=14

int Y=172

int Width=379

int Height=76

boolean Enabled=false

string Text="发送内容:"

boolean FocusRectangle=false

long TextColor=33554432

long BackColor=67108864

int TextSize=-10

int Weight=400

string FaceName="方正姚体"

FontCharSet FontCharSet=GB2312CharSet!

FontPitch FontPitch=Variable!

end type

 

type st_1 from statictext within w_main

int X=14

int Y=52

int Width=379

int Height=76

boolean Enabled=false

string Text="目标地址:"

boolean FocusRectangle=false

long TextColor=33554432

long BackColor=67108864

int TextSize=-10

int Weight=400

string FaceName="方正姚体"

FontCharSet FontCharSet=GB2312CharSet!

FontPitch FontPitch=Variable!

end type

 




相关文章

相关软件