Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Advanced
Sep 17, 1998

Send Messages to WinPopUp from Your Application

If you have an application that must run "unattended" and you want it to alert you if something goes wrong, your application can send you a message through WinPopUp. WinPopUp uses a mail slot to communicate with other computers in the network. Choose a mail slot name, such as \\computername \mailslot\messngr, and use this code:
 Option Explicit

Private Declare Function CloseHandle Lib _
	"kernel32" (ByVal hHandle As Long) As Long
Private Declare Function WriteFile Lib _
	"kernel32" (ByVal hFileName As Long, _
	ByVal lpBuff As Any, _
	ByVal nNrBytesToWrite As Long, _
	lpNrOfBytesWritten As Long, _
	ByVal lpOverlapped As Long) As Long
Private Declare Function CreateFile Lib _
	"kernel32" Alias "CreateFileA" ( _
	ByVal lpFileName As String, _
	ByVal dwAccess As Long, _
	ByVal dwShare As Long, _
	ByVal lpSecurityAttrib As Long, _
	ByVal dwCreationDisp As Long, _
	ByVal dwAttributes As Long, _
	ByVal hTemplateFile As Long) As Long

Private Const OPEN_EXISTING = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const GENERIC_EXECUTE = &H20000000
Private Const GENERIC_ALL = &H10000000
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
 
Function SendToWinPopUp(PopFrom As String, _
	PopTo As String, MsgText As String) As Long
	' parms:		PopFrom: user or computer that 
	'			sends the message
	'			PopTo: computer that receives the 
	'			message
	'			MsgText: the text of the message 
	'			to send
	Dim rc  As Long
	Dim mshandle As Long
	Dim msgtxt As String
	Dim byteswritten As Long
	Dim mailslotname As String
	' name of the mailslot
	mailslotname = "\\" + PopTo + _
		"\mailslot\messngr" 
	msgtxt = PopFrom + Chr(0) + PopTo + Chr(0) + _
		MsgText + Chr(0) 
	mshandle = CreateFile(mailslotname, _
		GENERIC_WRITE, FILE_SHARE_READ, 0, _
		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
	rc = WriteFile(mshandle, msgtxt, _
		Len(msgtxt), byteswritten, 0)
	rc = CloseHandle(mshandle)
End Function
Mauro Mariz
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date