Dinput8: DirectInput8Create rewrite

Roderick Colenbrander thunderbird2k at gmx.net
Wed May 17 13:59:03 CDT 2006


--
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

> Ok, I did that and also called DirectInputCreateA,W so I get the DI
> structure properly allocated? I don't know how it is supposed to be
> cleaned up later. The following version of the patch works when linked
> to ole32 and has the registry stuff.
> 
> Jesse
> 

Does the attached version work? I tried a few test apps and it works fine here but I don't have games that directly call DirectInput8Create.

Regards,
Roderick
-- 


Bis zu 70% Ihrer Onlinekosten sparen: GMX SmartSurfer!
      Kostenlos downloaden: http://www.gmx.net/de/go/smartsurfer
    

--
Content-Type: text/x-patch;
 charset="iso-8859-15";
 name="dinput8_create.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="dinput8_create.patch"

Index: dlls/dinput8/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/dinput8/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- dlls/dinput8/Makefile.in	8 May 2006 20:39:17 -0000	1.7
+++ dlls/dinput8/Makefile.in	17 May 2006 18:44:17 -0000
@@ -4,11 +4,11 @@
 VPATH     = @srcdir@
 MODULE    = dinput8.dll
 IMPORTLIB = libdinput8.$(IMPLIBEXT)
-IMPORTS   = dinput kernel32
-EXTRALIBS = -luuid -ldxguid
+IMPORTS   = dinput ole32 advapi32 kernel32
+EXTRALIBS = -luuid
 
 C_SRCS = \
-	dinput8_main.c
+	dinput8_main.c regsvr.c
 
 RC_SRCS = version.rc
 
Index: dlls/dinput8/dinput8_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput8/dinput8_main.c,v
retrieving revision 1.4
diff -u -r1.4 dinput8_main.c
--- dlls/dinput8/dinput8_main.c	8 May 2006 20:39:17 -0000	1.4
+++ dlls/dinput8/dinput8_main.c	17 May 2006 18:44:18 -0000
@@ -51,8 +51,39 @@
  *	DirectInput8Create (DINPUT8.@)
  */
 HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) {
-    /* TODO: Create the interface using CoCreateInstance as that's what windows does too and check if the version number >= 0x800 */
-    return DirectInputCreateEx(hinst, dwVersion, riid, ppDI, punkOuter);
+    HRESULT hr;
+
+    TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p))\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
+
+    /* The specified version needs to be dinput8 (0x800) or higher */
+    if(dwVersion < 0x800)
+        return DIERR_OLDDIRECTINPUTVERSION;
+
+    if( !(IsEqualGUID(&IID_IDirectInput8A, riid) || IsEqualGUID(&IID_IDirectInput8W, riid) || IsEqualGUID(&IID_IUnknown, riid)) )
+        return DIERR_INVALIDPARAM;
+
+    CoInitialize(NULL);
+    
+    hr = CoCreateInstance( &CLSID_DirectInput8, punkOuter, CLSCTX_INPROC_SERVER, riid, ppDI);
+    if(FAILED(hr)) {
+        ERR("CoCreateInstance failed with hr = %ld\n", hr);
+        return DIERR_INVALIDPARAM;
+    }
+
+    CoUninitialize();
+
+    /* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */
+    if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) {
+        LPDIRECTINPUTA DI = (LPDIRECTINPUTA)*ppDI;
+        IDirectInput8_Initialize(DI, hinst, dwVersion);
+    }
+
+    if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) {
+        LPDIRECTINPUTW DI = (LPDIRECTINPUTW)*ppDI;
+        IDirectInput8_Initialize(DI, hinst, dwVersion);
+    }
+
+    return S_OK;
 }
 
 /*******************************************************************************
@@ -84,8 +115,8 @@
     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
 
     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
-    if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) ) {
-        return DirectInput8Create(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter);
+    if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) {
+        return DirectInputCreateEx(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter);
     }
 
     ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);    

----



More information about the wine-devel mailing list