How do I invoke netmessagebuffersend to send a message? Adapted

Source: Internet
Author: User
Tags end variables string variable trim window net send

How do I invoke netmessagebuffersend to send a message?

Problem Description:

How do I invoke the API function under WINNT/2K/XP netmessagebuffersend the analog net send command to send a message?

Solution:

The following code has been successfully tested to import PBL directly



$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) Lib Rary "Netapi32.dll" Alias for "Netmessagebuffersend"

Function ulong Icmpcreatefile () Library "Icmp.dll"

Function Long Icmpsendecho (ulong icmphandle, ulong destinationaddress, String Requestdata,long requestsize, Long Request Options, 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= "founder 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= "founder Yao Body"

Fontcharset fontcharset=gb2312charset!

Fontpitch fontpitch=variable!

End Type



Event clicked;if not wf_ping (Trim (sle_1.text), "") Then

MessageBox ("Hint", "Specify Destination address does not exist or not!")

Return

End If



If Wf_netmessagebuffersend (Trim (sle_1.text), Trim (mle_1.text)) Then

MessageBox ("Prompt", "Send success!")

Else

MessageBox ("Prompt", "Send failed!")

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= "founder Yao Body"

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= "Send content:"

Boolean Focusrectangle=false

Long textcolor=33554432

Long backcolor=67108864

int textsize=-10

int weight=400

String Facename= "founder Yao Body"

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= "Destination address:"

Boolean Focusrectangle=false

Long textcolor=33554432

Long backcolor=67108864

int textsize=-10

int weight=400

String Facename= "founder Yao Body"

Fontcharset fontcharset=gb2312charset!

Fontpitch fontpitch=variable!

End Type




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.