|
-
Dec 22nd, 2004, 01:40 PM
#1
Thread Starter
Addicted Member
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim devices As Microsoft.DirectX.DirectInput.DeviceList
Dim dev As Microsoft.DirectX.DirectInput.DeviceInstance
Dim gamepadDevice As Microsoft.DirectX.DirectInput.Device
devices = Microsoft.DirectX.DirectInput.Manager.GetDevices(Microsoft.DirectX.DirectInput.DeviceClass.GameControl, Microsoft.DirectX.DirectInput.EnumDevicesFlags.AttachedOnly)
MsgBox(dev.ProductName)
gamepadDevice = New Microsoft.DirectX.DirectInput.Device(dev.ProductGuid)
gamepadDevice.RunControlPanel()
MsgBox(gamepadDevice.Caps.NumberButtons)
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.
-
Dec 22nd, 2004, 01:43 PM
#2
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
-
Dec 22nd, 2004, 02:22 PM
#3
Thread Starter
Addicted Member
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.
-
Sep 10th, 2005, 11:25 AM
#4
New Member
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
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.
-
Sep 10th, 2005, 11:56 AM
#5
New Member
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim devices As DeviceList
Dim dev As DeviceInstance
Dim gamepadDevice As Device
devices = Manager.GetDevices(DeviceType.Gamepad, EnumDevicesFlags.AllDevices)
devices.MoveNext()
dev = devices.Current
des.Items.Add(dev.InstanceName)
des.Items.Add(dev.InstanceGuid)
des.Items.Add(dev.ProductName)
des.Items.Add(dev.ProductGuid)
des.Items.Add(dev.FFDriverGuid)
des.Items.Add(dev.Usage)
des.Items.Add(dev.UsagePage)
Try
gamepadDevice = New Device(dev.ProductGuid)
Catch ex As Exception
gamepadDevice = New Device(dev.InstanceGuid)
End Try
des.Items.Add(gamepadDevice.Caps.DeviceType)
des.Items.Add(gamepadDevice.Caps.ForceFeedback)
des.Items.Add(gamepadDevice.Caps.FFDriverVersion)
des.Items.Add(gamepadDevice.Caps.FFMinTimeResolution)
des.Items.Add(gamepadDevice.Caps.FFSamplePeriod)
des.Items.Add(gamepadDevice.Caps.FirmwareRevision)
des.Items.Add(gamepadDevice.Caps.HardwareRevision)
des.Items.Add(gamepadDevice.Caps.NumberAxes)
des.Items.Add(gamepadDevice.Caps.NumberButtons)
des.Items.Add(gamepadDevice.Caps.NumberPointOfViews)
End Sub
This snippet if from a viewer program i built for testing and all. des is ofcourse a ListBox. I use
VB Code:
Imports Microsoft.DirectX.DirectInput
so i don't have to spell it out everytime.
-
Sep 19th, 2005, 12:06 PM
#6
New Member
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
-
Jun 8th, 2009, 06:58 PM
#7
New Member
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?
-
Jun 8th, 2009, 10:07 PM
#8
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.
-
Jun 9th, 2009, 05:00 AM
#9
New Member
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
-
Jun 9th, 2009, 08:39 AM
#10
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.
-
Jun 11th, 2009, 11:46 AM
#11
New Member
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.
-
Sep 6th, 2009, 09:26 AM
#12
Member
Re: Joystick with DirectX [RESOLVED]
 Originally Posted by Grimmest
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim devices As DeviceList
Dim dev As DeviceInstance
Dim gamepadDevice As Device
devices = Manager.GetDevices(DeviceType.Gamepad, EnumDevicesFlags.AllDevices)
devices.MoveNext()
dev = devices.Current
des.Items.Add(dev.InstanceName)
des.Items.Add(dev.InstanceGuid)
des.Items.Add(dev.ProductName)
des.Items.Add(dev.ProductGuid)
des.Items.Add(dev.FFDriverGuid)
des.Items.Add(dev.Usage)
des.Items.Add(dev.UsagePage)
Try
gamepadDevice = New Device(dev.ProductGuid)
Catch ex As Exception
gamepadDevice = New Device(dev.InstanceGuid)
End Try
des.Items.Add(gamepadDevice.Caps.DeviceType)
des.Items.Add(gamepadDevice.Caps.ForceFeedback)
des.Items.Add(gamepadDevice.Caps.FFDriverVersion)
des.Items.Add(gamepadDevice.Caps.FFMinTimeResolution)
des.Items.Add(gamepadDevice.Caps.FFSamplePeriod)
des.Items.Add(gamepadDevice.Caps.FirmwareRevision)
des.Items.Add(gamepadDevice.Caps.HardwareRevision)
des.Items.Add(gamepadDevice.Caps.NumberAxes)
des.Items.Add(gamepadDevice.Caps.NumberButtons)
des.Items.Add(gamepadDevice.Caps.NumberPointOfViews)
End Sub
This snippet if from a viewer program i built for testing and all. des is ofcourse a ListBox. I use
VB Code:
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
-
Nov 21st, 2009, 01:14 PM
#13
Junior Member
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.
-
Nov 21st, 2009, 04:28 PM
#14
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.
-
Nov 21st, 2009, 05:57 PM
#15
Junior Member
Re: Joystick with DirectX [RESOLVED]
 Originally Posted by kleinma
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,
 Originally Posted by pjrage
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|