Does anyone out there know of a way to call the StartService API and actually pass it arguments in VB? I understand that it takes a "pointer to an array of pointers" to null terminated ANSI strings, but I can't get it to work. Amazingly enough I can't find a single answer out there of someone actually passing arguments to the call - they're always passing NULL for the arguments. I've tried the following with no success:
Creating an array of LONG variable types and populating it with the address of the string contents via StrPtr (this points to a null terminated Unicode string though and I'm using StartServiceA, but I thought I'd give it a try too), then passing it to the API with VarPtr so I'm passing it a pointer to that array.
Creating an array of LONG variable types and populating it with the address of Byte arrays for each argument via VarPtr. I'm creating the Byte arrays from the strings with the following function:
Private Sub unicodeToByteArray(ByRef arrBytes() As Byte, strStringToConvert As String)
' Declare local variable(s)
Dim lngStringLength As Long
Dim lngStringPosition As Long
' Get the length of the string in characters
lngStringLength = Len(strStringToConvert)
' ReDim the byte array with the string length so
' we have room for each character and a null char
' at the end of the array
ReDim arrBytes(lngStringLength) As Byte
' Populate each position in the array with the
' ASCII value of the appropriate letter
For lngStringPosition = 1 To lngStringLength
arrBytes(lngStringPosition - 1) = Asc(Mid(strStringToConvert, lngStringPosition, 1))
Next
' Add a null char to the end of the array
arrBytes(lngStringLength) = Asc(vbNullChar)
End Sub
I'm adding the address of each of these Byte arrays to the "pointer" array via VarPtr, and then passing a "pointer" to the "pointer" array to the API with VarPtr (since it is declared with ByVal in the API declaration), as well as ensuring I'm passing the strings as C++ compatible character arrays via the byte arrays. It seems like this should cover it, but it still doesn't work. Any ideas?
Creating an array of LONG variable types and populating it with the address of the string contents via StrPtr (this points to a null terminated Unicode string though and I'm using StartServiceA, but I thought I'd give it a try too), then passing it to the API with VarPtr so I'm passing it a pointer to that array.
Creating an array of LONG variable types and populating it with the address of Byte arrays for each argument via VarPtr. I'm creating the Byte arrays from the strings with the following function:
Private Sub unicodeToByteArray(ByRef arrBytes() As Byte, strStringToConvert As String)
' Declare local variable(s)
Dim lngStringLength As Long
Dim lngStringPosition As Long
' Get the length of the string in characters
lngStringLength = Len(strStringToConvert)
' ReDim the byte array with the string length so
' we have room for each character and a null char
' at the end of the array
ReDim arrBytes(lngStringLength) As Byte
' Populate each position in the array with the
' ASCII value of the appropriate letter
For lngStringPosition = 1 To lngStringLength
arrBytes(lngStringPosition - 1) = Asc(Mid(strStringToConvert, lngStringPosition, 1))
Next
' Add a null char to the end of the array
arrBytes(lngStringLength) = Asc(vbNullChar)
End Sub
I'm adding the address of each of these Byte arrays to the "pointer" array via VarPtr, and then passing a "pointer" to the "pointer" array to the API with VarPtr (since it is declared with ByVal in the API declaration), as well as ensuring I'm passing the strings as C++ compatible character arrays via the byte arrays. It seems like this should cover it, but it still doesn't work. Any ideas?