_Kurt Posted December 19, 2007 Share Posted December 19, 2007 (edited) 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: expandcollapse popup;$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 December 19, 2007 by _Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
_Kurt Posted December 20, 2007 Author Share Posted December 20, 2007 Forgot to mention, see:http://vbnet.mvps.org/index.html?code/netw...ebuffersend.htmfor more information.Thanks,Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
_Kurt Posted December 20, 2007 Author Share Posted December 20, 2007 Bump. Any help? Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
rover Posted December 21, 2007 Share Posted December 21, 2007 (edited) This works for mechanged Long* to wstror "dword", StringLen($Msg)*2(dword for byte buffer)haven't tried yet, assume needs structMSDNNetMessageBufferSend FunctionNET_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 December 22, 2007 by rover I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now