[SlimDX] Trouble initializing DirectInput

Started by
3 comments, last by munawar 15 years, 10 months ago
Hi, The SlimDX WIKI instructed that I post questions here concerning SlimDX but this seems to be an XNA forum, so forgive me if this is offtopic to this forum. I am switching to DirectInput using slimDX. Having a small problem though...well, it's small but I don't know if I'll have to do some recoding to fix it :). I have this code: imports SlimDX.DirectInput imports SlimDX.DirectInput.Key module dxInput public keyboardDev As Device Public Sub DInputInit(ByVal Handle As IntPtr) DirectInput.Initialize() 'initialize DI as instructed from the WIKI diDev = New Device(SystemGuid.Keyboard) diDev.SetCooperativeLevel(Handle, CooperativeLevel.Foreground + CooperativeLevel.Exclusive) diDev.Acquire() End Sub When I compile, I get this error: Too few type arguments to 'SlimDX.DirectInput.Device(Of DataFormat)'. (BC32042) - C:\Documents and Settings\Munawar\My Documents\projects\BPCR2\dxInput.vb:14 The error points to this line: public keyboardDev As Device I'm not doing any construction here, just declaring a device object, so why does the compiler expect some arguments? Also, I can't find record of these parameters anywhere--the only parameter to device is the GUID. Could this be a compiler issue? I have the march 2008 DXSDK installed but it doesn't help. Thanks for any help you can give. This is my first time implementing SlimDX--I just found out about three days ago that Managed DX is no longer supported (wow I'm behind the times :d), and the people at the XNA forums were very helpful in showing me what else I can use. Munawar
Advertisement
I have never worked with SlimDX so sorry I can't be of much help. However, take a look at this and see if it helps at all: http://code.google.com/p/ionware-engine/source/browse/trunk/IWEngine/IWInputEngine.cs?r=20
I'm not too familiar with VB.Net, but I do know that DirectInput devices in SlimDX are generic, and they need a type parameter to specify the kind of data format they will be returning. This is how it would look in C#:

Device<KeyboardState> keyboardDevice = new Device<KeyboardState>(SystemGuid.Keyboard);


I don't think it will be all that hard to translate to VB.

EDIT: That link that UltimaX provided seems to point to some code that uses a very old version of SlimDX. DirectInput in SlimDX has been quite different for a few releases now.
Mike Popoloski | Journal | SlimDX
Device is a generic class ("Of DataFormat" is a big clue here). You cannot construct the class without providing a generic type parameter. On generic types in VB.

You need to supply the type of some class that represents the data format you're going to use. See the DirectInput sample that is included with SlimDX, that probably does it (although it'll be in C#, you'll have to adapt).
Hi,
Thanks for your help, especially the VB article on generic classes. I was able to get the code working by doing this:
Imports SlimDX.DirectInput
public diDev as Device(of KeyboardState)
public sub DInputInit()
DirectInput.Initialize()
diDev=new Device(of KeyboardState)(SystemGuid.Keyboard)
'...
end sub

Again thanks for the article and the quick response!
Munawar

This topic is closed to new replies.

Advertisement