Solved

Winpoup messages

Posted on 1998-11-25
9
331 Views
Last Modified: 2012-08-14
I'm using winpoup as my sender messages program. However I cannot pass parameters to it from a command line. So I'm interest in another application or even bulding, using VB6, an application like a winpoup to send messages on network, which I will be able to pass parameters, like the username and the message.

Could You help me to indicate some steps, like a :Which API should I use, Which commands, and some parts of program that I have to build ?
0
Comment
Question by:MVianna
  • 5
  • 2
  • 2
9 Comments
 

Author Comment

by:MVianna
Comment Utility
Edited text of question
0
 

Author Comment

by:MVianna
Comment Utility
Edited text of question
0
 

Author Comment

by:MVianna
Comment Utility
I will use this program with other program in FOX, that sends its messages to my machine, which is not the same where the Fox application runs.

This problem happened when my network has changed from Netware to NT. I use to write programs using the SEND Netware command with the Fox statment RUN /N. However Windows 95 under NT  doesn't have this function. I've done a litle research and I saw that the NT server has the NET SEND command, but I need the same NET SEND command on each station, and according our expertises here, we haven't this command available to WIN 95. So I thought in use the winpoup, which use to be our normal exchange-messages application. But I'm not able to pass parameter as an username and message from a command line as a statment.

That's when I thought in build an application with VB6 and some API who I would call a network service.
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Here is a class to send message to winpopup

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 5/10/98
' * Time             : 15:28
' * Module Name      : class_NetSend
' * Module Filename  : NetSend.cls
' **********************************************************************
' * Comments         :
' * By: Perry Harmon
' *    pharmon@email.msn.com
' *
' * Requires VB5 and NT 4.0
' * Sends message from NT 4.0 to NT 4.0 or Win95 running winpopup
' *
' Properties:
'   SendTo - Read/Write
'   SendFromServer - Read/Write
'   Message - Read/Write
'   Err - Read Only
'   ErrorText - Read Only
'
' Methods:
'   NetSendMessage - Boolean Returns True/False (Success/Failure)
'       optional parameters:
'           sUser ' String - Message Recipient
'           sMsg  ' String - Message Text
'
'   ClearError - Sets object.Err = 0, object.ErrorText = ""
'
' Events:
'   Error - raised on error
'       parameters:
'           lError ' Error Code
'           ErrorText ' Just That
'   Sent - raised when object.NetSendMessage executed without errors
'       parameters: None
'
'
'**** Example  ******
'
' Add to Form Declarations Section
' Private WithEvents mNetSend As clsNetSend
'
' Add to a procedure/function
' Set mNetSend = New clsNetSend
' With mNetSend
'    .Message = "Your Message Here"
'    .SendTo = "UserNameOrWorkStation"
'    .SendFromServer = "ServerOrWorkStation" 'This is optional
'    .NetSendMessage ' Send the message
' End With

' Private Sub mNetSend_Error(ByVal lError As Long, ByVal ErrorText As String)
'    Debug.Print lError & " - " & ErrorText
' End Sub

' Private Sub mNetSend_Sent()
'    debug.print "Message Sent"
' End Sub
'
'**** Example  ******
'
' Private mNetSend As New clsNetSend
' Dim bSuccess As Boolean
' If mNetSend.NetSendMessage("UserOrWorkstationName", "This Is A Test") Then
'   MsgBox "Message Sent"
' else
'   MsgBox "Error " & mNetSend.Err & " - " & mNetSend.ErrorText
' End If
'
' Broadcast a message to all members of Domain called DomainName
' bSuccess = mNetSend.NetSendMessage("DomainName*", "This Is A Test")
'
' **********************************************************************


Option Explicit

Private Const ERROR_ACCESS_DENIED = 5&
Private Const ERROR_BAD_NETPATH = 53&
Private Const ERROR_INVALID_PARAMETER = 87&
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_INVALID_NAME = 123&
Private Const NERR_Success = 0&       ' Success
Private Const NERR_NameNotFound = 2273& ' The message alias could not be found on the network.
Private Const NERR_NetworkError = 2136& ' A general network error occurred.

Private Declare Function NetSend Lib "Netapi32" Alias "NetMessageBufferSend" (ByVal cServerName As String, ByVal cMsgName As String, ByVal cFromName As String, ByVal cBuf As String, ByRef iBufLen As Integer) As Integer
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Private Const VER_PLATFORM_WIN32_NT = 2

Private Type OSVERSIONINFO
   dwOSVersionInfoSize  As Long
   dwMajorVersion       As Long
   dwMinorVersion       As Long
   dwBuildNumber        As Long
   dwPlatformId         As Long
   szCSDVersion         As String * 128      '  Maintenance string for PSS usage
End Type

' Events
Public Event Error(ByVal lError As Long, ByVal ErrorText As String)
Public Event Sent()

' Local copies of properties
Private m_sMsgTo As String
Private m_sMsg As String
Private m_sMsgFrom As String
Private m_lNetApiStatus As Long
Private m_sErrorText As String
Private m_bIsWinNT As Boolean

Function IsWindowsNT() As Boolean
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 5/10/98
   ' * Time             : 15:30
   ' * Module Name      : class_NetSend
   ' * Module Filename  : D:\TWA\NetSend\NetSend.cls
   ' * Procedure Name   : IsWindowsNT
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         : Returns true if this program is running under Windows NT
   ' *
   ' *
   ' **********************************************************************

   Dim lRC        As Long
   Dim typOSInfo  As OSVERSIONINFO

   typOSInfo.dwOSVersionInfoSize = Len(typOSInfo)
   lRC = GetVersionEx(typOSInfo)
   IsWindowsNT = (typOSInfo.dwPlatformId = VER_PLATFORM_WIN32_NT)

End Function

Public Sub ClearError()
   
   ' Set Error Properties
   m_lNetApiStatus = 0
   m_sErrorText = ""

End Sub

Public Property Get ErrorText() As String
   
   'Set ErrorText
   ErrorText = m_sErrorText

End Property

Public Property Get Err() As Long
   
   ' Set Error Number
   Err = m_lNetApiStatus

End Property

Private Function SetErrorText(Error As Long) As String
   
   Select Case Error
      Case ERROR_ACCESS_DENIED: SetErrorText = "Access Denied!"
      Case ERROR_BAD_NETPATH: SetErrorText = "Server '" & UCase$(m_sMsgFrom) & "' not Found."
      Case ERROR_INVALID_PARAMETER: SetErrorText = "Invalid parameter specified."
      Case ERROR_NOT_SUPPORTED: SetErrorText = "Network request not supported."
      Case ERROR_INVALID_NAME: SetErrorText = "Illegal character or malformed name."
      Case NERR_Success: SetErrorText = "Message sent."
      Case NERR_NameNotFound: SetErrorText = "User/Workstation '" & m_sMsgTo & "' not found."
      Case NERR_NetworkError: SetErrorText = "General network error occurred."
      Case Else: SetErrorText = "Unknown error executing command."
   End Select

End Function

Private Sub SetLastErr(ByVal lError As Long)
   
   m_lNetApiStatus = lError
   m_sErrorText = SetErrorText(lError)
   If m_lNetApiStatus Then RaiseEvent Error(m_lNetApiStatus, m_sErrorText)

End Sub
Public Function NetSendMessage(Optional ByVal sUser As String = "", Optional ByVal sMsg As String = "") As Boolean

   Dim sBuf             As String
   Dim sMsgFrom         As String
   Dim sMsgName         As String
   Dim Net_Api_Status   As Long

   If Not m_bIsWinNT Then Exit Function

   If Len(sUser) Then m_sMsgTo = sUser ' Else use the SendTo Property

   If m_sMsgTo = "" Then
      NetSendMessage = False
      SetLastErr ERROR_INVALID_PARAMETER
      RaiseEvent Error(ERROR_INVALID_PARAMETER, m_sErrorText)
   Else
      Screen.MousePointer = vbHourglass

      If Len(sMsg) Then m_sMsg = sMsg

      sBuf = StrConv(m_sMsg, vbUnicode)
      sMsgName = StrConv(m_sMsgTo, vbUnicode)

      If Len(m_sMsgFrom) And sUser = "" Then
         sMsgFrom = StrConv(m_sMsgFrom, vbUnicode)
      Else
         sMsgFrom = vbNullString
      End If
      Net_Api_Status = NetSend(sMsgFrom, sMsgName, vbNullString, sBuf, ByVal Len(sBuf))
      SetLastErr Net_Api_Status
      NetSendMessage = Not CBool(Net_Api_Status)
      If NetSendMessage Then RaiseEvent Sent
      Screen.MousePointer = vbNormal
   End If

End Function

Public Property Let Message(ByVal vData As String)
   
   'used when assigning a value to the property, on the left side of an assignment.
   'Syntax: X.sMessage = 5
   m_sMsg = vData

End Property


Public Property Get Message() As String
   
   'used when retrieving value of a property, on the right side of an assignment.
   'Syntax: Debug.Print X.sMessage
   Message = m_sMsg

End Property

Public Property Let SendTo(ByVal vData As String)
   
   m_sMsgTo = vData

End Property

Public Property Get SendTo() As String
   
   SendTo = m_sMsgTo

End Property

Public Property Let SendFromServer(ByVal vData As String)
   
   'used when assigning a value to the property, on the left side of an assignment.
   m_sMsgFrom = vData

End Property

Public Property Get SendFromServer() As String
   
   'used when retrieving value of a property, on the right side of an assignment.
   SendFromServer = m_sMsgFrom

End Property

Private Sub Class_Initialize()
   
   m_bIsWinNT = IsWindowsNT()
   If m_bIsWinNT Then
      m_lNetApiStatus = 0
   Else
      MsgBox "The NetSend class requires Windows NT.", vbCritical + vbOKOnly, "Net Send"
   End If

End Sub

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:MVianna
Comment Utility
Unfortunately Waty's proposed answer using : NT to NT or Win 95,and I appreciate the code, it's very interesting, however I need something different,I need to send messages from Win 95 to win 95 or NT.

Waty, thank for your prompt reply.

Mauricio
0
 
LVL 4

Accepted Solution

by:
gencross earned 100 total points
Comment Utility
To create an application like WinPopup you will use mailslots just like WinPopup does.  Here is some information on mailslots, the api's you have to use and some code, somewhat like waty's, but much simpler, that will send a message to winpopup running on a machine.


Mailslots are.....

A pipe forms a direct connection between two processes. A mailslot can best be thought of as somewhat like the U.S. Postal Service. You can send messages from many different locations that are all addressed to the same mailbox, but you can’t be absolutely certain that they will all arrive safely.
An application establishes a mailslot on its own system with a unique name. The name takes the form “
\\.\mailslot\path\mailslotname.” The server application (the one that creates the mailslot) can only create it on its own system, but client applications can write to mailslots throughout their domain. A mailslot name can have a pseudo path, for example, \\.\mailslot\ desaware\user\marketing. This path does not correspond to any real path on a file system—it is merely a handy way to categorize mailslots into groups.

When a client opens a mailslot using the CreateFile function, it can use “\\.\mailslot\...” if the client and the server are running on the same system, “\\computername\mailslot\...” to open a mailslot on a remote system, or “
\\domainname\mailslot\...” to open every mailslot with the specified name on the specified domain (use “*” for the domain name to specify the primary domain). The client should specify (FILE_SHARE_READ or FILE_SHARE_WRITE) for the file-sharing mode when using mailslots so that more than one client can write to the same server.

Multiple clients can open the same mailslot, in which case each client can write to the mailslot at will—the server will read messages from every client. When a client is connected to multiple mailslots, each active server will receive the message that it sends. Mailslot handles can be duplicated and shared among servers. The DuplicateHandle function can also be used.

Here are the api's, type, and constants that you will need...


Private Type OVERLAPPED
        Internal As Long
        InternalHigh As Long
        offset As Long
        OffsetHigh As Long
        hEvent As Long
End Type

Private Declare Function CreateMailslot Lib "kernel32" Alias "CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long, ByVal lReadTimeout As Long, ByVal lpSecurityAttributes As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function ReadFileAsync Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () 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



Sample code to send a message.  It will show you have to use the mailslots api's (some of them).  Once you understand the way mailslots work you can figure them out.  They are really not that hard to understand.


Global Const OPEN_EXISTING = 3
Global Const GENERIC_READ = &H80000000
Global Const GENERIC_WRITE = &H40000000
Global Const GENERIC_EXECUTE = &H20000000
Global Const GENERIC_ALL = &H10000000
Global Const INVALID_HANDLE_VALUE = -1
Global Const FILE_SHARE_READ = &H1
Global Const FILE_SHARE_WRITE = &H2
Global Const FILE_ATTRIBUTE_NORMAL = &H80

Declare Function CloseHandle Lib "kernel32" (ByVal hHandle As Long) As Long

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

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



Function SendToWinPopUp(PopFrom As String, PopTo As String, MsgText As String) As Long

        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


Private Sub Command1_Click()

        SendToWinPopUp txtFrom, txtTo, txtMsg
End Sub


I hope this helps.
0
 
LVL 4

Expert Comment

by:gencross
Comment Utility
I forget to tell you that the sample code I provided will send a message to Winpopup.  It will help you get an understanding of how mailslots work.
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Sure, mailslot is your solution, or otherwise, communication with simple files. I use files to communicate between some process (some of them are running on NT, other under Unix). Files is the more large easy way to implement a process communication, without any technology, and with any language.
0
 

Author Comment

by:MVianna
Comment Utility
Thank waty, you've agreed. I'm sure i'll have some problems to implement it on my network, but let's do it. If I some problem appear, I would aprreciate your help and also gencross.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now