• Sábado 5 de Julio de 2025, 11:25

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Temas - gdonaire

Páginas: [1]
1
VB .NET / Duda Control Joystick VB.NET
« en: Miércoles 12 de Noviembre de 2008, 01:39 »
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

Código: Text
  1.  
  2. Imports System.Runtime.InteropServices
  3.  
  4. Public Class joystick
  5.     ' Joystick API functions
  6.     Public Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long, ByRef pji As JOYINFOEX) As Long
  7.     Public Declare Function joyGetDevCapsA Lib "winmm.dll" (ByVal uJoyID As Long, ByRef pjc As JOYCAPS, ByVal cjc As Long) As Long
  8.     Public Declare Function joyGetNumDevs Lib "winmm.dll" () As Integer
  9.  
  10.  
  11.     <StructLayout(LayoutKind.Sequential)> _
  12.     Public Structure JOYCAPS
  13.         Dim wMid As Short
  14.         Dim wPid As Short
  15.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
  16.         Dim szPname As String
  17.         Dim wXmin As Integer
  18.         Dim wXmax As Integer
  19.         Dim wYmin As Integer
  20.         Dim wYmax As Integer
  21.         Dim wZmin As Integer
  22.         Dim wZmax As Integer
  23.         Dim wNumButtons As Integer
  24.         Dim wPeriodMin As Integer
  25.         Dim wPeriodMax As Integer
  26.         Dim wRmin As Integer
  27.         Dim wRmax As Integer
  28.         Dim wUmin As Integer
  29.         Dim wUmax As Integer
  30.         Dim wVmin As Integer
  31.         Dim wVmax As Integer
  32.         Dim wCaps As Integer
  33.         Dim wMaxAxes As Integer
  34.         Dim wNumAxes As Integer
  35.         Dim wMaxButtons As Integer
  36.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
  37.         Dim szRegKey As String
  38.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
  39.         Dim szOEMVxD As String
  40.     End Structure
  41.  
  42.     Public Structure JOYINFOEX
  43.         Dim dwSize As Integer
  44.         Dim dwFlags As Integer
  45.         Dim dwXpos As Integer
  46.         Dim dwYpos As Integer
  47.         Dim dwZpos As Integer
  48.         Dim dwRpos As Integer
  49.         Dim dwUpos As Integer
  50.         Dim dwVpos As Integer
  51.         Dim dwButtons As Integer
  52.         Dim dwButtonNumber As Integer
  53.         Dim dwPOV As Integer
  54.         Dim dwReserved1 As Integer
  55.         Dim dwReserved2 As Integer
  56.     End Structure
  57.  
  58.     Public MYJOYEX As JOYINFOEX
  59.     Public MYJOYCAPS As JOYCAPS
  60.  
  61.     Public Sub InitJoy()
  62.         'Get the joystick number in the system and about information
  63.         Dim xJa, xRj As Long
  64.         Dim xJn As Integer
  65.         xJa = joyGetNumDevs
  66.         Debug.Print("There are " & xJa & " joysticks")
  67.         Debug.Print("Longitud MYJOYCAPS: " & Len(MYJOYCAPS))
  68.         For xJn = 0 To xJa
  69.             Debug.Print(xJn)
  70.             xRj = joyGetDevCapsA(xJn, MYJOYCAPS, 404)
  71.  
  72.             If Val(MYJOYCAPS.wPid) <> 0 Then
  73.                 Debug.Print(MYJOYCAPS.wPid)
  74.            End If
  75.  
  76.         Next
  77.  
  78.     End Sub
  79. End Class
  80.  
  81.  

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.

Páginas: [1]