We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 358

Summary: some improvements for the new windows DirectInput joystick code
Product: SDL Reporter: David Gravereaux <davygrvy>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: trivial    
Priority: P2 CC: davygrvy
Version: 2.0.0   
Hardware: x86   
OS: Windows (XP)   
Attachments: patch file
latest

Description David Gravereaux 2006-11-06 19:27:21 UTC
Here's a patch for joystick/win32/SDL_dxjoystick.c

It does the following:
  - No reliance on DX5_Load() and DX5_Unload() found over in dx5video by using CoCreateInstance() rather than dynamically loading dinput.dll and grabbing the proc address of the help function DirectInputCreate().  Much simpler this way.
  - For joystick's that support ForceFeedback, it turns on auto-centering.
  - HRESULT COM errors check with the FAILED() macro rather than hresult!=DI_OK.  Error message descriptions grabbed with FormatMessage, rather than a short static short list.

How do I attach a file?  Will hit commit and see if can after..
Comment 1 David Gravereaux 2006-11-06 19:29:35 UTC
Created attachment 180 [details]
patch file

patch file
Comment 2 David Gravereaux 2006-11-07 01:24:48 UTC
you might want to push this through prettyprint after applying.  And I think SVN messed up CRLF on checkout for me..

Tnks.
Comment 3 David Gravereaux 2006-11-07 01:41:11 UTC
I forgot.

dinput.lib needs to be added to the link in the build scripts.  We don't actually, need an implicit link to dinput.dll (no calls are made to any of the functions it exports), but there's a symbol (a constant structure) in it we need.
Comment 4 David Gravereaux 2006-11-07 13:32:13 UTC
Please disregard the attached patch as it stands.  I'll attach a new one when I solve some problems I found using a Saitek Cybork EVO Force joystick.
Comment 5 David Gravereaux 2006-11-07 15:48:10 UTC
Created attachment 181 [details]
latest

Ok, error messages all fixed and tested with a force joystick.  A sample error message is the following:

Couldn't initialize SDL: IDirectInput::Initialize() [ERROR_OLD_WIN_VERSION & DIERR_OLDDIRECTINPUTVERSION]: The application requires a newer version of DirectInput.

To get proper error messages I had to use DXGetErrorString9() and DXGetErrorDescription9() which are found in the static library dxerr9.lib of the DirectX v9c SDK.

I'm not sure if this passes the mustard test for you guys.  Please contact me regarding this change.  SDL never had to use DX SDK stuff before, but this was only way I could find to get good error messages as bone minimum VC++6 only supports DirectX v5
Comment 6 Ryan C. Gordon 2007-06-02 13:58:58 UTC
Bumping a bunch of bugs to Priority 1 for consideration for the 1.2.12 release.

--ryan.

Comment 7 Ryan C. Gordon 2007-07-07 18:10:22 UTC
Dropping to Priority 2 (that is, not for the 1.2.12 release) since this changes some basic assumptions and requirements (directinput linking, etc). We'll talk about this again for the 1.3 branch, though.

--ryan.

Comment 8 Sam Lantinga 2007-07-07 20:42:50 UTC
I already have this in my 1.3 working tree, pending some cleanup.
Comment 9 Sam Lantinga 2009-12-15 17:22:02 UTC
These changes have been in for a long time, and I forgot to close the bug.  Whoops! :)

Thanks!
Comment 10 David Gravereaux 2009-12-16 09:57:02 UTC
statically linking with dx9err.lib not possible to get better error messages through DXGetErrorString9() and DXGetErrorDescription9() ?
Comment 11 Sam Lantinga 2010-01-26 21:20:54 UTC
Yes, it is, but I'm trying to avoid requiring you to link with any DirectX static libs.