From 085be22a308b2836bd03a2c71299e91d51aa5959 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 10 Feb 2009 03:12:41 +0000 Subject: [PATCH] - Changed I_InitInput() to acquire the IDirectInput8A interface by using DirectInput8Create() instead of CoCreateInstance(). This allows the Steam GameOverlayRenderer.dll to properly hook it. SVN r1422 (trunk) --- docs/rh-log.txt | 3 ++ src/win32/i_input.cpp | 84 ++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 49 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 04e6e4f4a5..f1bf6066d1 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,7 @@ February 9, 2009 +- Changed I_InitInput() to acquire the IDirectInput8A interface by using + DirectInput8Create() instead of CoCreateInstance(). This allows the Steam + GameOverlayRenderer.dll to properly hook it. - Stopped sending double the number of wheel events as appropriate to the console under Linux. - Added middle mouse button selection pasting for X systems. diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 15beaa2e9b..446c40d11b 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -97,6 +97,7 @@ #include "templates.h" #include "cmdlib.h" #include "d_event.h" +#include "v_text.h" #define DINPUT_BUFFERSIZE 32 @@ -1451,65 +1452,50 @@ bool I_InitInput (void *hwnd) // Try for DirectInput 8 first, then DirectInput 3 for NT 4's benefit. - hr = CoCreateInstance (CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectInput8A, (void**)&g_pdi); - if (FAILED(hr)) + DInputDLL = LoadLibrary("dinput8.dll"); + if (DInputDLL != NULL) { - g_pdi = NULL; - } - else - { - hr = g_pdi->Initialize (g_hInst, 0x0800); - if (FAILED (hr)) + typedef HRESULT (*blah)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN); + blah di8c = (blah)GetProcAddress(DInputDLL, "DirectInput8Create"); + if (di8c != NULL) { - g_pdi->Release (); - g_pdi = NULL; + hr = di8c(g_hInst, DIRECTINPUT_VERSION, IID_IDirectInput8A, (void **)&g_pdi, NULL); + if (FAILED(hr)) + { + Printf(TEXTCOLOR_ORANGE "DirectInput8Create failed: %08lx", hr); + g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it + } + } + else + { + Printf(TEXTCOLOR_ORANGE "Could not find DirectInput8Create in dinput8.dll\n"); } } if (g_pdi == NULL) { - hr = CoCreateInstance (CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, IID_IDirectInputA, (void**)&g_pdi3); - if (hr == REGDB_E_CLASSNOTREG) + if (DInputDLL != NULL) { - // NT 4 has the wrong GUID in the registry for CLSID_DirectInput unless somebody has already - // used "regsvr32 dinput.dll" to properly register the class. This means the only sure way to - // obtain an IDirectInputA interface under NT 4 is to actually load the DLL and use - // the function it provides. Grrr. - DInputDLL = LoadLibrary ("dinput.dll"); - if (DInputDLL == NULL) - { - I_FatalError ("Could not load dinput.dll: %08lx", GetLastError()); - } - - typedef HRESULT (*blah)(HINSTANCE, DWORD, LPDIRECTINPUT*, LPUNKNOWN); - blah dic = (blah)GetProcAddress (DInputDLL, "DirectInputCreateA"); - - if (dic == NULL) - { - I_FatalError ("dinput.dll is corrupt"); - } - - hr = dic (g_hInst, 0x0300, &g_pdi3, NULL); - if (FAILED(hr)) - { - I_FatalError ("DirectInputCreate failed: %08lx", hr); - } - - Printf ("Tip for NT 4: \"regsvr32 dinput.dll\"\n"); + FreeLibrary(DInputDLL); } - else + DInputDLL = LoadLibrary ("dinput.dll"); + if (DInputDLL == NULL) { - if (FAILED(hr)) - { - I_FatalError ("Could not create DirectInput interface: %08lx", hr); - } - hr = g_pdi3->Initialize (g_hInst, 0x0300); - if (FAILED(hr)) - { - g_pdi3->Release (); - g_pdi3 = NULL; - I_FatalError ("Could not initialize DirectInput interface: %08lx", hr); - } + I_FatalError ("Could not load dinput.dll: %08lx", GetLastError()); + } + + typedef HRESULT (*blah)(HINSTANCE, DWORD, LPDIRECTINPUT*, LPUNKNOWN); + blah dic = (blah)GetProcAddress (DInputDLL, "DirectInputCreateA"); + + if (dic == NULL) + { + I_FatalError ("dinput.dll is corrupt"); + } + + hr = dic (g_hInst, 0x0300, &g_pdi3, NULL); + if (FAILED(hr)) + { + I_FatalError ("DirectInputCreate failed: %08lx", hr); } }