How do I call NetMessageBuffersend send messages? (adaptation)

xiaoxiao2021-03-06  31

How do I call NetMessageBuffersend send messages?

Problem Description:

How do I call the API function netMessageBuffering in WinNT / 2K / XP to send a message?

solution:

The following code has been tested successfully, directly imported PBL

$ PBEXPORTHEADER $ w_main.srw

Forward

Global Type W_Main from Window

End Type

TYPE MLE_1 from MultilineEdit Withnin W_Main

End Type

TYPE CB_1 from CommandButton within w_main

End Type

Type SLE_1 from SingleLineEdit Withnin W_Main

End Type

TYPE ST_2 from StaticText Withnin W_Main

End Type

TYPE ST_1 from StaticText Withnin 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 NetMessageBuffersnd (Ulong Servername, Ref Char Msgname [], Ulong fromname, Ref char BUF [], Ulong Bufflen) library "NetMessageBuffersnd" for "NetMessageBuffers"

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 prototype

Type Variables

Constant Ulong Nerr_suCcess = 0

End variables

Forward Prototypes

Public substerine wf_string_to_unicode (string as_string, ref character ac_unicode [])

Public substerine wf_string_to_unicode (string as_string, ref character ac_unicode [])

Public Function Boolean WF_NetMessageBuffersnd (String as_sendto, String As_Msgtext)

Public Function Boolean WF_PING (String as_Ipaddress, String As_ecHomsg)

End protoypes

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 = NetMessageBuffersnd (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 dam

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 = crete 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 Withnin 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 = "Founded Yao Body"

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 = "Send (& S)"

Int textsize = -10

INT weight = 400

String FacenaMe = "Founded Yao Body"

Fontcharset Fontcharset = GB2312Charset!

Fontpitch fontpitch = variable!

End Type

Event clicked; if not wf_ping (TRIM (SLE_1.TEXT), "") THEN

MessageBox ("Tip", "Specify the destination address does not exist or no!")

Return

END IF

IF WF_NetMessageBuffersnd (Trim (SLE_1.TEXT), TRIM (mle_1.text)) THEN

MessageBox ("Tips", "Send Success!")

Else

MessageBox ("Tips", "Send Failure!") End IF

End Event

Type SLE_1 from SingleLineEdit Withnin 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 = "Founded Yao Body"

Fontcharset Fontcharset = GB2312Charset!

Fontpitch fontpitch = variable!

End Type

TYPE ST_2 from StaticText Withnin W_Main

INT x = 14

Int y = 172

Int width = 379

INT height = 76

Boolean enabled = false

String text = "Send content:"

Boolean FocusRectangle = FALSE

Long TextColor = 33554432

Long backcolor = 67108864

Int textsize = -10

INT weight = 400

String FacenaMe = "Founded Yao Body"

Fontcharset Fontcharset = GB2312Charset!

Fontpitch fontpitch = variable!

End Type

TYPE ST_1 from StaticText Withnin W_Main

INT x = 14

Int y = 52

Int width = 379

INT height = 76

Boolean enabled = false

String text = "Target Address:"

Boolean FocusRectangle = FALSE

Long TextColor = 33554432

Long backcolor = 67108864

Int textsize = -10

INT weight = 400

String FacenaMe = "Founded Yao Body"

Fontcharset Fontcharset = GB2312Charset!

Fontpitch fontpitch = variable!

End Type

***********************************************************

Another way to convert Unicode:

$ PBExportHeader $ w_main.srwforwardglobal type w_main from Windowend typetype mle_1 from multilineedit within w_mainend typetype cb_1 from commandbutton within w_mainend typetype sle_1 from singlelineedit within w_mainend typetype st_2 from statictext within w_mainend typetype st_1 from statictext within w_mainend typeend forward

type icmp_echo_reply from structure unsignedlong address unsignedlong status unsignedlong roundtriptime unsignedlong datasize unsignedlong reserved [3] character data [250] end typeglobal type w_main from Windowint X = 1056int Y = 484int Width = 1531int Height = 1152boolean TitleBar = truestring Title = "NETMESSAGESEND" long BackColor = 80269524Boolean controlmenu = TrueBoolean minbox = trueBoolean resizable = truemle_1 mle_1cb_1 cb_1sle_1 SLE_1ST_2 ST_2ST_1 ST_1END TYPEGLOBAL W_MAIN W_MAIN

type prototypesFunction 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 MultiByteToWideChar (ulong CodePage, ulong dwFlags, ref string lpMultiByteStr, ulong cchMultiByte, ref string lpWideCharStr, ulong cchWideChar) LIBRARY "kernel32.dll" Function ulong NetMessageBufferSend (ulong servername, ref string msgname, ulong fromname, ref string buf, ulong buflen ) Library "netapi32.dll" alias for "netmessagebuffers"

End protoypestype variablesconstant ulong Nerr_suCcess = 0nd Variables

forward prototypespublic function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext) public function boolean wf_ping (string as_ipaddress, string as_echomsg) public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext) public function boolean wf_ping (string as_ipaddress, string as_echomsg) end prototypespublic function boolean wf_netmessagebuffersend (string as_ssgtext); String Ls_msgtext, ls_sendto, ls_wmsgtext, ls_wsendto, ls_charulong ll_result, ll_lenstr

Ls_sendto = as_sendtols_msgtext = as_msgtext

setnull (ls_char) ll_lenstr = MultiByteToWideChar (0, 0, ls_sendto, -1, ls_char, 0) ls_wsendto = space (ll_lenstr * 2) ll_lenstr = MultiByteToWideChar (0, 0, ls_sendto, -1, ls_wsendto, ll_lenstr)

setnull (ls_char) ll_lenstr = MultiByteToWideChar (0, 0, ls_msgtext, -1, ls_char, 0) ls_wmsgtext = space (ll_lenstr * 2) ll_lenstr = MultiByteToWideChar (0, 0, ls_msgtext, -1, ls_wmsgtext, ll_lenstr)

LL_Result = NetMessageBuffersnd (0, LS_WSENDTO, 0, LS_WMSGTEXT, LL_LENSTR * 2)

If ll_result = NERR_Success Then Return TrueElse Return FalseEnd Ifend functionpublic function boolean wf_ping (string as_ipaddress, string as_echomsg); ULong lul_address, lul_handleLong ll_rc, ll_sizeString ls_replyicmp_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 the return ife end if end if end ifend ifreturn false

END FUNCTION

on w_main.createthis.mle_1 = create mle_1this.cb_1 = create cb_1this.sle_1 = create sle_1this.st_2 = create st_2this.st_1 = create st_1this.Control [] = {this.mle_1, & this.cb_1, & this.sle_1, & this.st_2 , & this.st_1} ENDOT

ON w_main.destroydestroy (this.cb_1) destroy (this.sle_1) destroy (this.st_2) destroy (this.st_1) end ON

type mle_1 from multilineedit within w_mainint X = 27int Y = 264int Width = 1399int Height = 604int TabOrder = 20BorderStyle BorderStyle = StyleLowered! long TextColor = 33554432int TextSize = -10int Weight = 400string FaceName = "Founder Yao body" FontCharSet FontCharSet = GB2312CharSet! FontPitch FontPitch = Variable! End Type

type cb_1 from commandbutton within w_mainint X = 1070int Y = 904int Width = 357int Height = 108int TabOrder = 30string Text = "Send (& S)" int TextSize = -10int Weight = 400string FaceName = "Founder Yao body" FontCharSet FontCharSet = GB2312CharSet! FontPitch Fontpitch = variable! End Type

Event clicked; if isnull (SLE_1.TEXT) or TRIM (SLE_1.TEXT) = "" or trim (mle_1.text) = "" "THEN MessageBox (" Tips "," unfilled items! "Returnend IF

If not wf_ping (TRIM (SLE_1.TEXT), "") Then MessageBox ("Tip", "Specify the destination address does not exist or no!") Returnend IFIF WF_NetMessageBuffersend (TRIM (SLE_1.TEXT), TRIM (mle_1.text)) The MessageBox ("Tips", "Send Success!") Else MessageBox ("Tips", "Send Failure!") End IfEnd Event

type sle_1 from singlelineedit within w_mainint X = 430int Y = 48int Width = 997int Height = 92int TabOrder = 10BorderStyle BorderStyle = StyleLowered! boolean AutoHScroll = falselong TextColor = 33554432int TextSize = -10int Weight = 400string FaceName = "Founder Yao body" FontCharSet FontCharSet = GB2312CharSet Fontpitch fontpitch = variable! End Type

type st_2 Height Enabled Text = "Send Content:" from statictext within w_mainint X = 14int Y = 172int Width = 379int = 76boolean = falsestring boolean FocusRectangle = falselong TextColor = 33554432long BackColor = 67108864int TextSize = -10int Weight = 400string FaceName = "Founder Yao "Fontcharset Fontcharset = GB2312Charset! Fontpitch Fontpitch = variable! End Type

type st_1 from statictext within w_mainint X = 14int Y = 52int Width = 379int Height = 76boolean Enabled = falsestring Text = "Destination Address:" boolean FocusRectangle = falselong TextColor = 33554432long BackColor = 67108864int TextSize = -10int Weight = 400string FaceName = "Founder Yao "Fontcharset Fontcharset = GB2312Charset! Fontpitch Fontpitch = variable! End Type

转载请注明原文地址:https://www.9cbs.com/read-65013.html

New Post(0)