如何調用NetMessageBufferSend發送訊息?(改編)

來源:互聯網
上載者:User

如何調用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

 


相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。