how to make a fixedlength and static array?

  • Thread starter Thread starter The Thinker
  • Start date Start date
T

The Thinker

Guest
I was wondering how to create an safe array out of the following code which has a fixed length and static array:

Dim x(40), y(40) As Integer
Private Structure InputReport
<MarshalAsAttribute(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_VARIANT)> Dim InputReport1() As Object
Dim InputReportMain As System.Array
End Structure
Public Function sendinputreport(xcoord As Integer, ycoord As Integer, leftclick As Boolean, rightclick As Boolean) As Boolean
device report to send to computer (x,y coordinates, left or right clicks, and scrolling).
file contents:
number of devices
x for dev1
y for dev1
left click for dev1
x for dev2
y for dev2
left click for dev2
Dim mousereport As InputReport
mousereport.InputReport1 = New Object(5) {CByte(0), CByte(x(usernum)), CByte(y(usernum)), CByte(0), CByte(0), CByte(0)}

x(usernum) = xcoord
y(usernum) = ycoord
MsgBox(x(usernum))
mousereport.InputReportMain = Array.CreateInstance(GetType(Byte), 5)
mousereport.InputReportMain = mousereport.InputReport1
InputReport1(0) = CByte(0)
InputReport1(1) = CByte(x(usernum))
InputReport1(2) = CByte(y(usernum))
InputReport1(3) = CByte(0)
InputReport1(4) = CByte(0)

make sure byte is below 255 because thats the max it can be in integer or other format.
If x(usernum) <= 255 And y(usernum) <= 255 Then
InputReportMain.SetValue(CByte(0), 0)
InputReportMain.SetValue(CByte(100), 1)
InputReportMain.SetValue(CByte(100), 2)
InputReportMain.SetValue(CByte(0), 3)
InputReportMain.SetValue(CByte(0), 4)
GenericHIDDev(usernum).devInputReportBytes(InputReport1)
GenericHIDDev(usernum).QueueInputReport(mousereport.InputReportMain, 0)
GenericHIDDev(usernum).StartProcessing()
End If

sendinputreport = True
End Function

I know this seems weird but I was trying to call a com object but visual studio automatically create a RCW(runtime callable wrapper) that wrappers the com code and turns the safe array to type system.array. I thing because the attributes fixed and static are not being passed to com the unmanaged code excludes the data from being used.


Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr

Continue reading...
 
Back
Top