Question : Call NetMessageBufferSend function from vb.net

I need to call the NetMessageBufferSend function from an a vb.net application.  I used to do it as follows in VB6 but I cannot convert the function for it to work in vb.net....  I cannot find the proper way to pass the parameters to the function it seems



' Declare the function for the net nessage call
Private Declare Function NetMessageBufferSend _
    Lib "netapi32.dll" (ByVal lpServerName As Byte, _
    lpMsgName As Byte, ByVal lpFromName As Byte, _
    lpBuf As Byte, ByVal lnBufLen As Long) As Long
                         
' Declare the function for the send message call
Private Function SendMsg(lpServerName As String, lpMsgName As String, _
    lpFromName As String, lpBuf As String, lngBufLen As Long) As Long
                         
    Dim arServerName() As Byte
    Dim arMsgName() As Byte
    Dim arFromName() As Byte
    Dim arBuf() As Byte
                       
    arServerName = ConvertToByte(lpServerName & "")
    arMsgName = ConvertToByte(lpMsgName & "")
    arFromName = ConvertToByte(lpFromName & "")
    arBuf = ConvertToByte(lpBuf & "")
                       
    SendMsg = NetMessageBufferSend(0, arMsgName(0), _
        arFromName(0), 0, lngBufLen)

End Function

Answer : Call NetMessageBufferSend function from vb.net

The issue could be type definition for return code. Instead of defining it as Long, define it as Int32. I have seen these kind of issues with wrong type definitions. Give it a shot.

Public Class Win32
        CharSet:=CharSet.Unicode)> _
       Public Shared Function NetMessageBufferSend(ByVal lpServerName As String, _
       ByVal lpMsgName As String, ByVal lpFromName As String, _
       ByVal lpBuf As String, ByVal lnBufLen As Long) As Int32
       End Function
   End Class
Random Solutions  
 
programming4us programming4us