• 12
• 27
• 9
• 20
• 33

# SlimDX: DirectInput - Exception when setting CooperativeLevel

This topic is 3406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi folks, i have a problem when tyring to set the cooperative level of a DirectInput device using SlimDX. This is my code in the constructor of a Form class:
   DirectInput.Initialize();
keyboard = new Device<KeyboardState>(SystemGuid.Keyboard);
>> keyboard.SetCooperativeLevel(this, CooperativeLevel.Nonexclusive); <<
keyboard.Acquire();

It compiles, but when I run it, a DirectInputException is thrown on the marked line:
E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

I tried any combination of flags. I first found this issue in the September 2008 release. I then upgraded to the November 2008 release, but it it didn't work either. I'm working with Visual Studio 2005 Professional on a Windows Server 2008 Enterprise x64 machine. I tried the x64 and x86 version of SlimDX. Am i making a mistake or is this a bug in SlimDX? Thanks in advance for any answers. BertaS

##### Share on other sites
I believe you need to specify both Foreground or Background and Exclusive or Nonexclusive. You need one of each. From the DX SDK docs:
Quote:
 Applications must specify either DISCL_FOREGROUND or DISCL_BACKGROUND; it is an error to specify both or neither. Similarly, applications must specify either DISCL_EXCLUSIVE or DISCL_NONEXCLUSIVE.

##### Share on other sites
That actually works! Thank you.
Maybe I should read the DX SDK Docs next time.

##### Share on other sites
I'm not sure quite how much of this applies to SlimDX, but you really shouldn't use DirectInput for keyboard or mouse input.

Going off topic: Is it just me, or has there been an unusually high volume of DirectInput related threads recently?

##### Share on other sites
Quote:
 I'm not sure quite how much of this applies to SlimDX

Everything that applies to DirectX applies to SlimDX, in almost all cases. Think of SlimDX as a copy of DirectX with the names changed to match the .NET naming scheme. All of your advice that would apply to DirectX also applies to SlimDX.

Quote:
 Is it just me, or has there been an unusually high volume of DirectInput related threads recently?

I haven't noticed it, but then, I haven't made it my personal crusade to speak out against the evils of DirectInput [grin]

On the other hand, I have seen a lot of SlimDX threads in the past few months. I think that's a good thing, but I'm not entirely sure.

##### Share on other sites
Quote:
 Original post by Evil SteveGoing off topic: Is it just me, or has there been an unusually high volume of DirectInput related threads recently?

Since the topic is pretty much done, I can derail us further. Notice how topics usually pop up in groups? That is, if a question about, say Point Sprites would be posted, within the next few days there are usually about 2 more questions about them, some even within hours of the original? Then you could get months of 0 questions about Point Sprites all until the next question pops up?

I've always found it very odd. It's kind of like a herd effect, but I doubt people go off to use DirectInput just because they read a DI related question.