Jump to content

Problem calling NetMessageBufferSend in netapi32.dll


_Kurt
 Share

Recommended Posts

Hey guys,

I was looking into the NetMessageBufferSend function in netapi32.dll. For some reason my function doesn't seem to be working correctly, I'm pretty sure I'm calling it correctly through the DllCall, but I think it's my first parameter that isn't quite working for me. After searching around and translating, I've came up with the following:

;$Input = @ComputerName ;<-- for testing purposes I guess
;$Input = vbNullString ;<-- How can you send a vbNullString parameter (so it uses the local computer) ?
;$Input = @IPAddress1  ;<-- This should be the right one, right?

$Test_Return = NetMessageBufferSend($Input, "MyFromName", "MyToName", "Hello there.")

If $Test_Return = 1 Then
    Msgbox(0,"","SUCCESS")
Else
    MsgBox(0,"","FAILURE" & @CRLF & @CRLF & $Test_Return)
EndIf


Func NetMessageBufferSend($ServerName, $ToName, $FromName, $Msg)
    Local Const $ERROR_ACCESS_DENIED = 5
    Local Const $ERROR_BAD_NETPATH = 53
    Local Const $ERROR_INVALID_PARAMETER = 87
    Local Const $ERROR_NOT_SUPPORTED = 50
    Local Const $ERROR_INVALID_NAME = 123
    Local Const $NERR_BASE = 2100
    Local Const $NERR_SUCCESS = 0                     
    Local Const $NERR_NETWORKERROR = $NERR_BASE + 36
    Local Const $NERR_NAMENOTFOUND = $NERR_BASE + 173
    Local Const $NERR_USENOTFOUND = $NERR_BASE + 150
    $Ret = DllCall("netapi32.dll", "long", "NetMessageBufferSend", _
        "wstr", $ServerName, "wstr", $ToName, "wstr", $FromName, _
        "wstr", $Msg, "long*", StringLen($Msg))
    If $Ret[0] = $NERR_SUCCESS Then
        Return 1
    Else
        Return $Ret[0]
    EndIf
EndFunc

#cs
Local Declare Function NetMessageBufferSend Lib "netapi32" _
  (ByVal servername As String, _
   ByVal msgname As String, _
   ByVal fromname As String, _
   ByVal msgbuf As String, _
   ByRef msgbuflen ) 
#ce

Does this work for anybody? What am I doing wrong?

Thanks,

Kurt

Edited by _Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

This works for me

changed Long* to wstr

or

"dword", StringLen($Msg)*2

(dword for byte buffer)

haven't tried yet, assume needs struct

MSDN

NetMessageBufferSend Function

NET_API_STATUS NetMessageBufferSend(

__in LPCWSTR servername,

__in LPCWSTR msgname,

__in LPCWSTR fromname,

__in LPBYTE buf,

__in DWORD buflen

);

"" = NULL or Chr(0)

$Test_Return = NetMessageBufferSend("", @ComputerName, @ComputerName, "Hello"&@LF&"There.") ; send to local machine
;$Test_Return = NetMessageBufferSend("", "network-compname", @ComputerName, "Hello"&@LF&"There.") ; send to networked machine "network-compname"
;$Test_Return = NetMessageBufferSend("", "Workgroup*", "", "Hello"&@LF&"There.") ; broadcast to all machines on "Workgroup"
;$Test_Return = NetMessageBufferSend("", "Domain*", @ComputerName, "Hello"&@LF&"There.") ; broadcast to all machines on "Domain"

If $Test_Return = 1 Then
    Msgbox(0,"","SUCCESS")
Else
    MsgBox(0,"","FAILURE" & @CRLF & @CRLF & $Test_Return)
EndIf


Func NetMessageBufferSend($ServerName, $ToName, $FromName, $Msg)
    Local Const $ERROR_ACCESS_DENIED = 5
    Local Const $ERROR_BAD_NETPATH = 53
    Local Const $ERROR_INVALID_PARAMETER = 87
    Local Const $ERROR_NOT_SUPPORTED = 50
    Local Const $ERROR_INVALID_NAME = 123
    Local Const $NERR_BASE = 2100
    Local Const $NERR_SUCCESS = 0                     
    Local Const $NERR_NETWORKERROR = $NERR_BASE + 36
    Local Const $NERR_NAMENOTFOUND = $NERR_BASE + 173
    Local Const $NERR_USENOTFOUND = $NERR_BASE + 150

    $Ret = DllCall("netapi32.dll", "long", "NetMessageBufferSend", _
        "wstr", $ServerName, "wstr", $ToName, "wstr", $FromName, _
       ; "wstr", $Msg, "wstr", StringLen($msg)) ; works but probably not proper usage
        "wstr", $Msg, "dword", StringLen($Msg)*2)

    If $Ret[0] = $NERR_SUCCESS Then
        Return 1
    Else
        Return $Ret[0]
    EndIf
EndFunc
Edited by rover

I see fascists...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...