RE:API NetMessageBufferSend(...)
En VB6
crea un formulario con un listbox con su name: lst
un textbox con su name: txtMsg
un textbox con su name: txtResultado
un boton con su name: cmdSend
y copia este codigo.
Este codigo te permite ver los equipos en red y mandar un mensaje a cualquiera de ellos usando NetMessageBufferSend.
Espero te sirva.
Option Explicit
Const ERROR_SUCCESS = 0
Const ERROR_MORE_DATA = 234
Const SV_TYPE_SERVER = &H2
Const SIZE_SI_101 = 24
Private Type SERVER_INFO_101
dwPlatformId As Long
lpszServerName As Long
dwVersionMajor As Long
dwVersionMinor As Long
dwType As Long
lpszComment As Long
End Type
Private Declare Function NetServerEnum Lib "netapi32.dll" (ByVal servername As String, _
ByVal level As Long, buffer As Long, ByVal prefmaxlen As Long, entriesread As Long, _
totalentries As Long, ByVal servertype As Long, ByVal domain As String, resumehandle As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (BufPtr As Any) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" _
(hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function lstrcpyW Lib "KERNEL32" _
(ByVal lpszDest As String, ByVal lpszSrc As Long) As Long
Private Const NERR_Success As Long = 0&
Private Const NERR_BASE = 2100
Private Const NERR_NameNotFound = NERR_BASE + 173
Private Const NERR_NetworkError = NERR_BASE + 36
Private Const ERROR_ACCESS_DENIED = 5
Private Const ERROR_INVALID_PARAMETER = 87
Private Const ERROR_NOT_SUPPORTED = 50
Private Declare Function NetMessageBufferSend Lib "netapi32.dll" (servername As Any, _
msgname As Byte, fromname As Any, buf As Byte, ByVal buflen As Long) As Long
Private Sub cmdSend_Click()
Dim nRet As Long
Dim sTo() As Byte
Dim sMsg() As Byte
sTo = lst.List(lst.ListIndex) & Chr(0)
sMsg = txtMsg & Chr(0)
nRet = NetMessageBufferSend(ByVal 0, sTo(0), ByVal 0, sMsg(0), UBound(sMsg))
Select Case nRet
Case NERR_Success: txtResultado.Text = "Mensaje enviado con éxito!!!"
Case NERR_NameNotFound: txtResultado.Text = "Nombre de máquina no encontrado!!!"
Case NERR_NetworkError: txtResultado.Text = "Error en la Red!!!"
Case ERROR_ACCESS_DENIED: txtResultado.Text = "Acceso denegado!!!"
Case ERROR_INVALID_PARAMETER: txtResultado.Text = "Parametros invalidos!!!"
Case ERROR_NOT_SUPPORTED: txtResultado.Text = "No soportado!!!"
Case Else: MsgBox "Error inesperado!!!"
End Select
End Sub
Private Function PointerToString(lpszString As Long) As String
Dim lpszStr1 As String, lpszStr2 As String, nRet As Long
lpszStr1 = String(1000, "*")
nRet = lstrcpyW(lpszStr1, lpszString)
lpszStr2 = (StrConv(lpszStr1, vbFromUnicode))
PointerToString = Left(lpszStr2, InStr(lpszStr2, Chr$(0)) - 1)
End Function
Private Sub Form_Load()
Dim pszServer As String, pszDomain As String
Dim nLevel As Long, i As Long, BufPtr As Long, TempBufPtr As Long
Dim nPrefMaxLen As Long, nEntriesRead As Long, nTotalEntries As Long
Dim nServerType As Long, nResumeHandle As Long, nRet As Long
Dim ServerInfo As SERVER_INFO_101
nLevel = 101
BufPtr = 0
nPrefMaxLen = &HFFFFFFFF
nEntriesRead = 0
nTotalEntries = 0
nServerType = SV_TYPE_SERVER
nResumeHandle = 0
Do
nRet = NetServerEnum(pszServer, nLevel, BufPtr, nPrefMaxLen, nEntriesRead, _
nTotalEntries, nServerType, pszDomain, nResumeHandle)
If ((nRet = ERROR_SUCCESS) Or (nRet = ERROR_MORE_DATA)) And (nEntriesRead > 0) Then
TempBufPtr = BufPtr
For i = 1 To nEntriesRead
RtlMoveMemory ServerInfo, TempBufPtr, SIZE_SI_101
lst.AddItem PointerToString(ServerInfo.lpszServerName)
TempBufPtr = TempBufPtr + SIZE_SI_101
Next i
Else
MsgBox "NetServerEnum failed: " & nRet
End If
NetApiBufferFree (BufPtr)
Loop While nEntriesRead < nTotalEntries
End Sub