Results 1 to 15 of 15

Thread: Joystick with DirectX [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    185

    Joystick with DirectX [RESOLVED]

    I am having issues getting a joystick to work with VB.NET and directx 9. I have gotten a joystick to work in VB6 no problem with directx 8, but now with 9, I just can't get it. Here is the code I have so far:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim devices As Microsoft.DirectX.DirectInput.DeviceList
    3.         Dim dev As Microsoft.DirectX.DirectInput.DeviceInstance
    4.         Dim gamepadDevice As Microsoft.DirectX.DirectInput.Device
    5.         devices = Microsoft.DirectX.DirectInput.Manager.GetDevices(Microsoft.DirectX.DirectInput.DeviceClass.GameControl, Microsoft.DirectX.DirectInput.EnumDevicesFlags.AttachedOnly)
    6.         MsgBox(dev.ProductName)
    7.         gamepadDevice = New Microsoft.DirectX.DirectInput.Device(dev.ProductGuid)
    8.         gamepadDevice.RunControlPanel()
    9.         MsgBox(gamepadDevice.Caps.NumberButtons)
    10.     End Sub

    The error I receive is "An unhandled exception of type 'Microsoft.DirectX.DirectInput.DeviceNotRegisteredException' occurred in microsoft.directx.directinput.dll Additional information: Error in the application."

    Any thoughts? How do I register the device in directinput? I cannot figure out what is wrong, if anyone can even point me to ANY VB.NET examples for directinput, that would help greatly. I have found some examples for C/C#, but none for VB.NET. I got what I have so far by trying to take a C example and port it into VB.

    I don't know how to get a device registered with directinput. PLEASE help!!

    BTW if you know how to get a joystick to work with directx 8 and VB.NET, that might also help. I am not stuck on directx 9, but I am having lots of trouble with the code I had for VB6/directx 8 in .NET, because of the "As Any" types that were allowed in VB6 but are not in .NET. They were changed to System.IntPtr and I have no idea what that type even is, let alone how to get the deadzone's System.IntPtr for example! Ahhh, I am new to .NET and already having so many issues!
    Last edited by pjrage; Dec 22nd, 2004 at 02:23 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Joystick with DirectX 9

    sorry I dont program in directx, but you may find some help here

    http://216.5.163.53/DirectX4VB/index.asp

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    185

    Re: Joystick with DirectX 9

    I found an example within the DirectX9 SDK that used VB.NET for a joystick. The sample works with my joystick, so it is only a matter of time until I actually disect it and figure out how it works. Sorry to waste all your time. For anyone who needs help on joysticks with DX9 in the future, look in the DirectX 9 SDK that is available from Microsoft, and you will find in the Samples folder a folder for VB.Net, and within that folder is a directinput/joystick folder. Thanks.

  4. #4
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Re: Joystick with DirectX [RESOLVED]

    I realize this thread is dead, but for anybody that comes to this page looking for answers i copied the code pasted in the first port into VS.net and had the same exception occur i fixed it in a bout two seconds with
    VB Code:
    1. devices.MoveNext()
    The controller that i have hooked it the XBOX controller with XBCD drivers I think it is the HID complient thing that comes up that takes the index 0 in the device list.
    either way Moving to the next item was all i had to do and it picked up fine.

  5. #5
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Re: Joystick with DirectX [RESOLVED]

    Since it took me a little while to find even something remotely close to what i was looking for here is an update. Sry for the double Post.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim devices As DeviceList
    3.         Dim dev As DeviceInstance
    4.         Dim gamepadDevice As Device
    5.         devices = Manager.GetDevices(DeviceType.Gamepad, EnumDevicesFlags.AllDevices)
    6.         devices.MoveNext()
    7.         dev = devices.Current
    8.         des.Items.Add(dev.InstanceName)
    9.         des.Items.Add(dev.InstanceGuid)
    10.         des.Items.Add(dev.ProductName)
    11.         des.Items.Add(dev.ProductGuid)
    12.         des.Items.Add(dev.FFDriverGuid)
    13.         des.Items.Add(dev.Usage)
    14.         des.Items.Add(dev.UsagePage)
    15.         Try
    16.             gamepadDevice = New Device(dev.ProductGuid)
    17.         Catch ex As Exception
    18.             gamepadDevice = New Device(dev.InstanceGuid)
    19.         End Try
    20.         des.Items.Add(gamepadDevice.Caps.DeviceType)
    21.         des.Items.Add(gamepadDevice.Caps.ForceFeedback)
    22.         des.Items.Add(gamepadDevice.Caps.FFDriverVersion)
    23.         des.Items.Add(gamepadDevice.Caps.FFMinTimeResolution)
    24.         des.Items.Add(gamepadDevice.Caps.FFSamplePeriod)
    25.         des.Items.Add(gamepadDevice.Caps.FirmwareRevision)
    26.         des.Items.Add(gamepadDevice.Caps.HardwareRevision)
    27.         des.Items.Add(gamepadDevice.Caps.NumberAxes)
    28.         des.Items.Add(gamepadDevice.Caps.NumberButtons)
    29.         des.Items.Add(gamepadDevice.Caps.NumberPointOfViews)
    30.     End Sub

    This snippet if from a viewer program i built for testing and all. des is ofcourse a ListBox. I use
    VB Code:
    1. Imports Microsoft.DirectX.DirectInput
    so i don't have to spell it out everytime.

  6. #6
    New Member
    Join Date
    Nov 2000
    Posts
    2

    Re: Joystick with DirectX [RESOLVED]

    Hi all,

    Can "pjrage" or some one on here pls share with me a simple example in VB.Net on how to capture information from multiple joysticks. I have already downloaded the dlls for directx9 and the listbox example below works fine for me.

    I am making a simple game but on a tight schedule. Will appreciate help. Thanks.

    Raza

  7. #7
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Joystick with DirectX

    Hi. I have trying this codes which you have paste here. But I always recive an error:

    LoaderLock was detected
    Message: Biblioteka DLL 'C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll'
    translated msg:
    is trying run managed code inside a blockade of operating system loading module. Do not try run managed code iside DllMain function or graphic initialization function, because it can breake the application.
    oryginal msg:
    prbuje wykonać kod zarządzany wewnątrz blokady modułu ładującego systemu operacyjnego. Nie prbuj uruchamiać kodu zarządzanego wewnątrz funkcji DllMain ani funkcji inicjacji obrazu, ponieważ może to spowodować zawieszenie aplikacji.

    in:

    Code:
     devices = Manager.GetDevices(DeviceType.Gamepad, EnumDevicesFlags.AllDevices)
    and msg:



    but when I press [F5] it will continue debugging.

    The main problem is here:

    Code:
            Try
                gamepadDevice = New Device(dev.ProductGuid)
            Catch ex As Exception
                gamepadDevice = New Device(dev.InstanceGuid)      
            End Try

    Microsoft.DirectX.DirectInput.DeviceNotRegisteredException was unhandled
    ErrorCode=-2147221164
    ErrorString="REGDB_E_CLASSNOTREG"
    IsExceptionIgnored=False
    LastError=0
    Message="application occure an error"
    Source="Microsoft.DirectX.DirectInput"
    StackTrace:
    w Microsoft.DirectX.DirectInput.Device..ctor(Guid deviceGuid) w joystick_form.Form1.Form1_Load(Object sender, EventArgs e) w C:\Users\Arche\Documents\Visual Studio 2008\Projects\VB.NET\joystick_form\joystick_form\Form1.vb:wiersz 21 w System.EventHandler.Invoke(Object sender, EventArgs e) w System.Windows.Forms.Form.OnLoad(EventArgs e) w System.Windows.Forms.Form.OnCreateControl() w System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) w System.Windows.Forms.Control.CreateControl() w System.Windows.Forms.Control.WmShowWindow(Message& m) w System.Windows.Forms.Control.WndProc(Message& m) w System.Windows.Forms.ScrollableControl.WndProc(Message& m) w System.Windows.Forms.ContainerControl.WndProc(Message& m) w System.Windows.Forms.Form.WmShowWindow(Message& m) w System.Windows.Forms.Form.WndProc(Message& m) w System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) w System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow) w System.Windows.Forms.Control.SetVisibleCore(Boolean value) w System.Windows.Forms.Form.SetVisibleCore(Boolean value) w System.Windows.Forms.Control.set_Visible(Boolean value) w System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) w System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) w System.Windows.Forms.Application.Run(ApplicationContext context) w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() w Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) w joystick_form.My.MyApplication.Main(String[] Args) w 17d14f5c-a337-4978-8281-53493378c1071.vb:wiersz 81 w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() w System.Threading.ThreadHelper.ThreadStart_Context(Object state) w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) w System.Threading.ThreadHelper.ThreadStart()
    InnerException:



    Coold someone help me?

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Joystick with DirectX [RESOLVED]

    micart, this is a pretty old thread.

    What version of .NET are you using? You can probably make use of XNA at this point, which provides managed wrappers around the DirectX APIs like gamepad. It is much easier to work with.

  9. #9
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Joystick with DirectX [RESOLVED]

    yeah, I'm using .NET 3.5. I have XNA but it is created for C# and it's hard to find anything for VB. I am trying since sunday. I've found quite good site about vb and xna http://www.alanphipps.com but there isn't anything about joystick

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Joystick with DirectX [RESOLVED]

    Yes, its for C#, but you can easily just reference the needed DLLs and use it just the same.. since XNA traditionally uses a game loop, you need to use polling to know what the gamepad state is.

    I have an example that is almost completed, using the xbox controller, which I can post soon.

  11. #11
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Joystick with DirectX [RESOLVED]

    Yeah, I've trying with XNA but I can't go through with this;/ I can't find tutorials about xna + vb.net + joystick. But I have part of a book (example chapter) where is example. Now I'm trying that code and if it will be good I will paste it here.

  12. #12
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Joystick with DirectX [RESOLVED]

    Quote Originally Posted by Grimmest View Post
    Since it took me a little while to find even something remotely close to what i was looking for here is an update. Sry for the double Post.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim devices As DeviceList
    3.         Dim dev As DeviceInstance
    4.         Dim gamepadDevice As Device
    5.         devices = Manager.GetDevices(DeviceType.Gamepad, EnumDevicesFlags.AllDevices)
    6.         devices.MoveNext()
    7.         dev = devices.Current
    8.         des.Items.Add(dev.InstanceName)
    9.         des.Items.Add(dev.InstanceGuid)
    10.         des.Items.Add(dev.ProductName)
    11.         des.Items.Add(dev.ProductGuid)
    12.         des.Items.Add(dev.FFDriverGuid)
    13.         des.Items.Add(dev.Usage)
    14.         des.Items.Add(dev.UsagePage)
    15.         Try
    16.             gamepadDevice = New Device(dev.ProductGuid)
    17.         Catch ex As Exception
    18.             gamepadDevice = New Device(dev.InstanceGuid)
    19.         End Try
    20.         des.Items.Add(gamepadDevice.Caps.DeviceType)
    21.         des.Items.Add(gamepadDevice.Caps.ForceFeedback)
    22.         des.Items.Add(gamepadDevice.Caps.FFDriverVersion)
    23.         des.Items.Add(gamepadDevice.Caps.FFMinTimeResolution)
    24.         des.Items.Add(gamepadDevice.Caps.FFSamplePeriod)
    25.         des.Items.Add(gamepadDevice.Caps.FirmwareRevision)
    26.         des.Items.Add(gamepadDevice.Caps.HardwareRevision)
    27.         des.Items.Add(gamepadDevice.Caps.NumberAxes)
    28.         des.Items.Add(gamepadDevice.Caps.NumberButtons)
    29.         des.Items.Add(gamepadDevice.Caps.NumberPointOfViews)
    30.     End Sub

    This snippet if from a viewer program i built for testing and all. des is ofcourse a ListBox. I use
    VB Code:
    1. Imports Microsoft.DirectX.DirectInput
    so i don't have to spell it out everytime.

    I have used this code in my project and it detects my gamepad. How do I go from here to actually getting the button presses from the gamepad or sending rumble commands to the gamepad?

    Thanks for posting the code Grimmest

  13. #13
    Junior Member
    Join Date
    Nov 2009
    Posts
    17

    Re: Joystick with DirectX [RESOLVED]

    Hi,
    I need all the code in vb6,
    how can I identify the joystick,
    and when I click on the joystick it increases number in text,
    and I need ready code that will work with DirectX and Windows XP,
    and what are the tools that I will use example ( command, text, label, etc.)
    Please Help
    http://www.vbforums.com/showthread.php?t=591859
    Thanks.

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Joystick with DirectX [RESOLVED]

    Please don't hijack threads. This is the VB.NET section, not the VB6 section. This thread is specific to VB.NET, not VB6.

  15. #15
    Junior Member
    Join Date
    Nov 2009
    Posts
    17

    Re: Joystick with DirectX [RESOLVED]

    Quote Originally Posted by kleinma View Post
    Please don't hijack threads. This is the VB.NET section, not the VB6 section. This thread is specific to VB.NET, not VB6.
    I know that this thread is for VB.Net,
    but this thread is form the same subject Joystick with DirectX,
    and also the member (pjrage) said this,
    Quote Originally Posted by pjrage View Post
    I have gotten a joystick to work in VB6 no problem
    and this thread was given to me by a member in my request for code in my thread,
    http://www.vbforums.com/showthread.php?t=591859

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width