Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendinput8_main.c
Go to the documentation of this file.
00001 /* DirectInput 8 00002 * 00003 * Copyright 2002 TransGaming Technologies Inc. 00004 * Copyright 2006 Roderick Colenbrander 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "config.h" 00022 #include <assert.h> 00023 #include <stdarg.h> 00024 #include <string.h> 00025 00026 #define COBJMACROS 00027 00028 #include "wine/debug.h" 00029 #include "windef.h" 00030 #include "winbase.h" 00031 #include "winerror.h" 00032 #include "dinput.h" 00033 00034 WINE_DEFAULT_DEBUG_CHANNEL(dinput); 00035 static LONG dll_count; 00036 00037 /* 00038 * Dll lifetime tracking declaration 00039 */ 00040 static void LockModule(void) 00041 { 00042 InterlockedIncrement(&dll_count); 00043 } 00044 00045 static void UnlockModule(void) 00046 { 00047 InterlockedDecrement(&dll_count); 00048 } 00049 00050 /****************************************************************************** 00051 * DirectInput8Create (DINPUT8.@) 00052 */ 00053 HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) { 00054 HRESULT hr; 00055 00056 TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p))\n", hinst, dwVersion, debugstr_guid(riid), punkOuter); 00057 00058 /* The specified version needs to be dinput8 (0x800) or higher */ 00059 if(dwVersion < 0x800) 00060 return DIERR_OLDDIRECTINPUTVERSION; 00061 00062 if( !(IsEqualGUID(&IID_IDirectInput8A, riid) || IsEqualGUID(&IID_IDirectInput8W, riid) || IsEqualGUID(&IID_IUnknown, riid)) ) 00063 return DIERR_INVALIDPARAM; 00064 00065 CoInitialize(NULL); 00066 00067 hr = CoCreateInstance( &CLSID_DirectInput8, punkOuter, CLSCTX_INPROC_SERVER, riid, ppDI); 00068 if(FAILED(hr)) { 00069 ERR("CoCreateInstance failed with hr = %d; Try running wineprefixcreate to fix it.\n", hr); 00070 return DIERR_INVALIDPARAM; 00071 } 00072 00073 CoUninitialize(); 00074 00075 /* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */ 00076 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) { 00077 LPDIRECTINPUTA DI = *ppDI; 00078 IDirectInput8_Initialize(DI, hinst, dwVersion); 00079 } 00080 00081 if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) { 00082 LPDIRECTINPUTW DI = *ppDI; 00083 IDirectInput8_Initialize(DI, hinst, dwVersion); 00084 } 00085 00086 return S_OK; 00087 } 00088 00089 /******************************************************************************* 00090 * DirectInput8 ClassFactory 00091 */ 00092 typedef struct 00093 { 00094 /* IUnknown fields */ 00095 const IClassFactoryVtbl *lpVtbl; 00096 } IClassFactoryImpl; 00097 00098 static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) { 00099 IClassFactoryImpl *This = (IClassFactoryImpl *)iface; 00100 FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj); 00101 return E_NOINTERFACE; 00102 } 00103 00104 static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) { 00105 LockModule(); 00106 return 2; 00107 } 00108 00109 static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) { 00110 UnlockModule(); 00111 return 1; 00112 } 00113 00114 static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) { 00115 IClassFactoryImpl *This = (IClassFactoryImpl *)iface; 00116 00117 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj); 00118 if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) { 00119 return DirectInputCreateEx(0, DIRECTINPUT_VERSION, riid, ppobj, pOuter); 00120 } 00121 00122 ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj); 00123 return E_NOINTERFACE; 00124 } 00125 00126 static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) { 00127 TRACE("(%p)->(%d)\n", iface, dolock); 00128 00129 if(dolock) 00130 LockModule(); 00131 else 00132 UnlockModule(); 00133 00134 return S_OK; 00135 } 00136 00137 static const IClassFactoryVtbl DI8CF_Vtbl = { 00138 DI8CF_QueryInterface, 00139 DI8CF_AddRef, 00140 DI8CF_Release, 00141 DI8CF_CreateInstance, 00142 DI8CF_LockServer 00143 }; 00144 static IClassFactoryImpl DINPUT8_CF = { &DI8CF_Vtbl }; 00145 00146 00147 /*********************************************************************** 00148 * DllCanUnloadNow (DINPUT8.@) 00149 */ 00150 HRESULT WINAPI DllCanUnloadNow(void) 00151 { 00152 return dll_count == 0 ? S_OK : S_FALSE; 00153 } 00154 00155 /*********************************************************************** 00156 * DllGetClassObject (DINPUT8.@) 00157 */ 00158 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) 00159 { 00160 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00161 if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) { 00162 *ppv = &DINPUT8_CF; 00163 IClassFactory_AddRef((IClassFactory*)*ppv); 00164 return S_OK; 00165 } 00166 00167 FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00168 return CLASS_E_CLASSNOTAVAILABLE; 00169 } Generated on Fri May 25 2012 04:19:29 for ReactOS by
1.7.6.1
|