Solved

Winpopup and function calls

Posted on 1998-07-23
8
187 Views
Last Modified: 2013-11-13
I would like to know how to send a message from VB to Winpopup. What library is required? Does anyone have any code examples to use. Getting Time Critical please help. Thanks
0
Comment
Question by:MalcolmH
8 Comments
 

Author Comment

by:MalcolmH
ID: 1466492
Adjusted points to 200
0
 

Author Comment

by:MalcolmH
ID: 1466493
Edited text of question
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1466494
To send a message to a window, you can use the sendMessage API.


Declare Function SendMessage Lib "User32" Alias _
  "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
  ByVal wParam As Long, lParam As Any) As Long

 As you can see,  you need the handle of the window. If you have the caption of the window, you can get it using the findwindow API.

Let me know if you have any questions.
Regards
DAlin
0
 

Author Comment

by:MalcolmH
ID: 1466495
This solution passes messages between windows. What I require is to pass a message across the network to another machine running Win pop Up. The API was available in Lan Manager under the NETAPI.DLL and a user could access it using the NET SEND Command. It remains available on Windows NT. I have checked this with C++ and VB. It does not appear to be generally accessible on Windows 95, however, Windows 95 uses winpopup which is capable of sending network messages to targeted users. A function call must be available.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:Dalin
ID: 1466496
Have considered to use Winsock Control to communicate in the network?
0
 

Author Comment

by:MalcolmH
ID: 1466497
In this instance, I think we can use the Winsock control with the UDP protocol.
This does not work in all scenarios i.e. requires TCP/IP but for this project we can write our own pop-up messages around the winsock functionality.

Thanks
0
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
ID: 1466498
You could use the following class :

' Class Module clsNetSend
'
' 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")


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
'
' Returns true if this program is running under Windows NT
'-----------------------------------------------------------'
Function IsWindowsNT() As Boolean

   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
   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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1466499
Bought This Question.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now