how to implement the ICustommarshaler interface in vb.net?

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

The Thinker

Guest
I was wondering I noticed the ICustommarshaller interface in vb.net. Is it possible to implement it? I want to use the marshalmanagedtonative function. Heres my code so far which has a warning about cool not being assigned a value:

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 a As SAFEARRAY = New SAFEARRAY
how many dimensions are their in the array one-dimensional, two-dimensional, etc?
a.cDims = 1
a.cLocks = 0
features to pass with the safe array
a.fFeatures = 2194

x(userindex) = xcoord
y(userindex) = ycoord
Dim j As Integer
Dim cool As ICustomMarshaler
Dim InputReport1test(4) As IntPtr
InputReport.inputreport1(0) = CByte(0)
InputReport.inputreport1(1) = CByte(x(userindex))
InputReport.inputreport1(2) = CByte(y(userindex))
InputReport.inputreport1(3) = CByte(0)
InputReport.inputreport1(4) = CByte(0)
For Me.i = 0 To playercount
InputReport1test(i) = cool.MarshalManagedToNative(InputReport.inputreport1(i))
Next i
Dim inputreportp() As IntPtr = New IntPtr() {}

InputReport.inputreport1 = {CByte(0), CByte(x(userindex)), CByte(y(userindex)), CByte(0), CByte(0)}
Marshal.GetNativeVariantForObject(InputReport.inputreport1(0), inputreportp(0))
Marshal.GetNativeVariantForObject(InputReport.inputreport1(1), inputreportp(1))
Marshal.GetNativeVariantForObject(InputReport.inputreport1(2), inputreportp(2))
Marshal.GetNativeVariantForObject(InputReport.inputreport1(3), inputreportp(3))
Marshal.GetNativeVariantForObject(InputReport.inputreport1(4), inputreportp(4))



Dim what As Array
what = Array.CreateInstance(GetType(Object), 5)
For j = 0 To 4
what.SetValue(InputReport1(j), j)
Next j
ReDim inputreport1(4)


MsgBox(x(usernum))
If VarType(InputReport.inputreport1(0)) = VariantType.Variant Or VarType(InputReport.inputreport1(0)) = VariantType.Byte Then
MsgBox("variant or byte array type")
End If
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
attempt to reconfigure c++ code.
GenericHIDDev(usernum).devInputReportBytes(InputReport1)
GenericHIDDev(usernum).QueueInputReport(InputReport1test, CUInt(10))
GenericHIDDev(usernum).StartProcessing()
End If

sendinputreport = True
End Function

It appears its creating an intptr type to pass to c++. How do I do get this interface to work in vb.net? I think this might resolve my other question about safe array in vb.net. I decided to create a new post on this because its a different code sample and subject and did not want to have my safe array thread go off-topic.
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