Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Messenger service popup in vb.net not behaving as it should...

Using NetMessageBufferSend function, the messenger pop up shows funny symbols after the message text eg: !!!???!!@@@ and so on. How can I get rid of this?

The code is:

Public Declare Unicode Function NetMessageBufferSend Lib "netapi32" _
            (ByVal servername As String, _
            ByVal msgname As String, _
            ByVal fromname As String, _
            ByVal msgbuf As String, _
            ByRef msgbuflen As Long) As Long

I know that msgbuf should be in byte. But then how do I change the input message to byte in vb.net?
Can anyone help? Thanks...
0
krchome
Asked:
krchome
1 Solution
 
EDDYKTCommented:
Try this

Try this


Option Explicit

Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, yToName As Byte, yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long

Private Sub Command1_Click()
   Dim lRet As Long
   
   lRet = BroadcastMessage("TO_NODE_NAME", "FROM_NODE_NAME", "YOUR_MESSAGE")
   
   '----- Traitement postirieur de l'envoi
  Select Case lRet
     Case 0
        Debug.Print "  MESSAGE SUCCESSFULLY SENT !"
     Case 53
        Debug.Print "  ERROR : BAD NAME !   ( FROM )"
     Case 123
        Debug.Print "  ERROR : EMPTY NAME !"
     Case 2273
        Debug.Print "  ERROR : BAD NAME !   ( TO )"
  End Select
End Sub

Private Function BroadcastMessage(pDst As String, pExp As String, pMsg As String) As Long
 
  '----- Variables
  Dim lDstName() As Byte
  Dim lExpName() As Byte
  Dim lMsg() As Byte
  Dim lRet As Long
 
  '----- Affectation des valeurs
  lDstName = pDst & vbNullChar
  lExpName = pExp & vbNullChar
  lMsg = pMsg & vbNullChar
 
  '----- Envoi du message
  lRet = NetMessageBufferSend(lExpName(0), lDstName(0), lExpName(0), lMsg(0), UBound(lMsg))
  BroadcastMessage = lRet
End Function
0
 
krchomeAuthor Commented:
Sorry the code you have sent works in vb6 but not in vb.net. I have got the answer myself and now I am sending you the translated code which will make your code work in vb.net. It might be useful to you if you migrate to vb.net. I am already using NetMessageBufferSend in vb6, so I was aware of the code that you have sent. Thanks anyway!! Here goes...

Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (ByRef yServer As Byte, ByRef yToName As Byte, ByRef yFromName As Byte, ByRef yMsg As Byte, ByVal lSize As Integer) As Integer
     
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim lRet As Integer
         
lRet = BroadcastMessage("TO_NODE_NAME", "FROM_NODE_NAME", "YOUR_MESSAGE")
         
'----- Traitement postirieur de l'envoi
Select Case lRet
Case 0
System.Diagnostics.Debug.WriteLine("  MESSAGE SUCCESSFULLY SENT !")
Case 53
System.Diagnostics.Debug.WriteLine("  ERROR : BAD NAME !   ( FROM )")
Case 123
System.Diagnostics.Debug.WriteLine("  ERROR : EMPTY NAME !")
Case 2273
System.Diagnostics.Debug.WriteLine("  ERROR : BAD NAME !   ( TO )")
End Select
End Sub
     
Private Function BroadcastMessage(ByRef pDst As String, ByRef pExp As String, ByRef pMsg As String) As Integer
         
'----- Variables
Dim lDstName() As Byte
Dim lExpName() As Byte
Dim lMsg() As Byte
Dim lRet As Integer
         
'----- Affectation des valeurs
lDstName = System.Text.UnicodeEncoding.Unicode.GetBytes(pDst & vbNullChar)

lExpName = System.Text.UnicodeEncoding.Unicode.GetBytes(pExp & vbNullChar)
         
lMsg = System.Text.UnicodeEncoding.Unicode.GetBytes(pMsg & vbNullChar)
         
'----- Envoi du message
lRet = NetMessageBufferSend(lExpName(0), lDstName(0), lExpName(0), lMsg(0), UBound(lMsg))
BroadcastMessage = lRet
End Function
0
 
CleanupPingCommented:
Hi krchome,
This old question (QID 20568509) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GrahamSkanRetiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ/Refund
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GrahamSkan
0
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now