T
TheVillageCodingIdiot
I'm creating a GUI for the NetSend service. I created a class called
Netsend. In there are to functions. The send function is public and
the NetMessageBufferSend function is private. Below is the code I
created for this class.
Public Class Netsend
Public Function Send(ByVal sTo As String, ByVal sMessage As
String) As Integer
Dim iReturnValue As Integer
Dim sReturn As String
Dim bBuffer As Byte() =
Encoding.Unicode.GetBytes(sMessage)
If sTo.Length And sMessage.Length <> 0 Then
iReturnValue = NetMessageBufferSend(Nothing, sTo,
Nothing, sMessage, sMessage.Length * 2 + 2)
Select Case iReturnValue
Case 0
sReturn = "Successfully sent message to " &
sTo
Case 2100
sReturn = ""
Case 2273
sReturn = "The message alias could not be
found on network for " & sTo
Case 2136
sReturn = "General network error occurred for
" & sTo
Case 5
sReturn = "Error: Access denied for " & sTo
Case 87
sReturn = "Invalid parameter for " & sTo
Case 50
sReturn = "This is not a supported command on
targert " & sTo
Case Else
sReturn = "Unknown return value for " & sTo
End Select
Return sReturn
Else
Return "Error: Either no computer was selected or
message was blank."
End If
End Function
<DllImportAttribute("Netapi32", CharSet:=CharSet.Unicode)> _
Private Shared Function NetMessageBufferSend(ByVal servername
As String, ByVal msgname As String, ByVal fromname As String, ByVal
buf As String, ByVal buflen As Integer) As Integer
End Function
So my form creates a new object for this class and calls the Send
function and passes the correct arguments, Computer name and message.
Then "send function" then validates and calls the Private function
NetMessageBufferSend and assigns the return to var iReturnValue.
the "Send" function runs through a case statment to set the value of
sReturn.
Then that value of sReturn is returned to the main form.
When it tries to return the value back to a string var on the form, i
get a invalid cast error saying that it is expecting a integer. I am
able to return a integer to the main form, but why cant I return a
string?
Netsend. In there are to functions. The send function is public and
the NetMessageBufferSend function is private. Below is the code I
created for this class.
Public Class Netsend
Public Function Send(ByVal sTo As String, ByVal sMessage As
String) As Integer
Dim iReturnValue As Integer
Dim sReturn As String
Dim bBuffer As Byte() =
Encoding.Unicode.GetBytes(sMessage)
If sTo.Length And sMessage.Length <> 0 Then
iReturnValue = NetMessageBufferSend(Nothing, sTo,
Nothing, sMessage, sMessage.Length * 2 + 2)
Select Case iReturnValue
Case 0
sReturn = "Successfully sent message to " &
sTo
Case 2100
sReturn = ""
Case 2273
sReturn = "The message alias could not be
found on network for " & sTo
Case 2136
sReturn = "General network error occurred for
" & sTo
Case 5
sReturn = "Error: Access denied for " & sTo
Case 87
sReturn = "Invalid parameter for " & sTo
Case 50
sReturn = "This is not a supported command on
targert " & sTo
Case Else
sReturn = "Unknown return value for " & sTo
End Select
Return sReturn
Else
Return "Error: Either no computer was selected or
message was blank."
End If
End Function
<DllImportAttribute("Netapi32", CharSet:=CharSet.Unicode)> _
Private Shared Function NetMessageBufferSend(ByVal servername
As String, ByVal msgname As String, ByVal fromname As String, ByVal
buf As String, ByVal buflen As Integer) As Integer
End Function
So my form creates a new object for this class and calls the Send
function and passes the correct arguments, Computer name and message.
Then "send function" then validates and calls the Private function
NetMessageBufferSend and assigns the return to var iReturnValue.
the "Send" function runs through a case statment to set the value of
sReturn.
Then that value of sReturn is returned to the main form.
When it tries to return the value back to a string var on the form, i
get a invalid cast error saying that it is expecting a integer. I am
able to return a integer to the main form, but why cant I return a
string?