Hola a todos
Soy nuevo en el foro y tengo una duda sobre como controlar un Joystick con VB.NET, utilizo Microsoft Visual Basic 2008 Express Edition
El ejemplo esta sacado de otro enlace
He intentado adaptar este codigo a VB.NET, bueno estoy empezando pero me da errores.
A continuacion muestro la clase utilizada para manejar el jostick
Imports System.Runtime.InteropServices
Public Class joystick
' Joystick API functions
Public Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long, ByRef pji As JOYINFOEX) As Long
Public Declare Function joyGetDevCapsA Lib "winmm.dll" (ByVal uJoyID As Long, ByRef pjc As JOYCAPS, ByVal cjc As Long) As Long
Public Declare Function joyGetNumDevs Lib "winmm.dll" () As Integer
<StructLayout(LayoutKind.Sequential)> _
Public Structure JOYCAPS
Dim wMid As Short
Dim wPid As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Dim szPname As String
Dim wXmin As Integer
Dim wXmax As Integer
Dim wYmin As Integer
Dim wYmax As Integer
Dim wZmin As Integer
Dim wZmax As Integer
Dim wNumButtons As Integer
Dim wPeriodMin As Integer
Dim wPeriodMax As Integer
Dim wRmin As Integer
Dim wRmax As Integer
Dim wUmin As Integer
Dim wUmax As Integer
Dim wVmin As Integer
Dim wVmax As Integer
Dim wCaps As Integer
Dim wMaxAxes As Integer
Dim wNumAxes As Integer
Dim wMaxButtons As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Dim szRegKey As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Dim szOEMVxD As String
End Structure
Public Structure JOYINFOEX
Dim dwSize As Integer
Dim dwFlags As Integer
Dim dwXpos As Integer
Dim dwYpos As Integer
Dim dwZpos As Integer
Dim dwRpos As Integer
Dim dwUpos As Integer
Dim dwVpos As Integer
Dim dwButtons As Integer
Dim dwButtonNumber As Integer
Dim dwPOV As Integer
Dim dwReserved1 As Integer
Dim dwReserved2 As Integer
End Structure
Public MYJOYEX As JOYINFOEX
Public MYJOYCAPS As JOYCAPS
Public Sub InitJoy()
'Get the joystick number in the system and about information
Dim xJa, xRj As Long
Dim xJn As Integer
xJa = joyGetNumDevs
Debug.Print("There are " & xJa & " joysticks")
Debug.Print("Longitud MYJOYCAPS: " & Len(MYJOYCAPS))
For xJn = 0 To xJa
Debug.Print(xJn)
xRj = joyGetDevCapsA(xJn, MYJOYCAPS, 404)
If Val(MYJOYCAPS.wPid) <> 0 Then
Debug.Print(MYJOYCAPS.wPid)
End If
Next
End Sub
End Class
El problema es que cuando llamo al metodo InitJoy no me detecta ningun joystick (todos los wPid son cero).
No se si estoy realizando algo mal, agradeceria cualquier ayuda y/o comentario.
Gracias a todos.