2002-06-14 02:39:44 +02:00
|
|
|
/* DirectInput 8
|
|
|
|
*
|
|
|
|
* Copyright 2002 TransGaming Technologies Inc.
|
2006-05-06 20:45:11 +02:00
|
|
|
* Copyright 2006 Roderick Colenbrander
|
2002-06-14 02:39:44 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-14 02:39:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-06-14 02:39:44 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2006-05-06 20:45:11 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-06-14 02:39:44 +02:00
|
|
|
#include "wine/debug.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-06-14 02:39:44 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2010-12-07 12:45:13 +01:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "rpcproxy.h"
|
2002-06-14 02:39:44 +02:00
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
2010-12-07 12:45:13 +01:00
|
|
|
|
|
|
|
static HINSTANCE instance;
|
2006-05-06 20:45:11 +02:00
|
|
|
static LONG dll_count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dll lifetime tracking declaration
|
|
|
|
*/
|
|
|
|
static void LockModule(void)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&dll_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnlockModule(void)
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&dll_count);
|
|
|
|
}
|
2002-06-14 02:39:44 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DirectInput8Create (DINPUT8.@)
|
|
|
|
*/
|
2009-09-12 14:18:32 +02:00
|
|
|
HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) {
|
2011-07-05 14:19:26 +02:00
|
|
|
IDirectInputA *pDI;
|
2009-10-14 19:47:45 +02:00
|
|
|
HRESULT hr, hrCo;
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2014-02-12 18:53:52 +01:00
|
|
|
TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p)\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2011-07-05 14:19:26 +02:00
|
|
|
if (!ppDI)
|
|
|
|
return E_POINTER;
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2011-07-05 14:19:26 +02:00
|
|
|
if (!IsEqualGUID(&IID_IDirectInput8A, riid) &&
|
|
|
|
!IsEqualGUID(&IID_IDirectInput8W, riid) &&
|
|
|
|
!IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
{
|
|
|
|
*ppDI = NULL;
|
|
|
|
return DIERR_NOINTERFACE;
|
|
|
|
}
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2009-10-14 19:47:45 +02:00
|
|
|
hrCo = CoInitialize(NULL);
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2011-07-05 14:19:26 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
|
|
|
|
|
|
|
|
/* Ensure balance of calls. */
|
|
|
|
if (SUCCEEDED(hrCo))
|
2009-10-14 19:47:45 +02:00
|
|
|
CoUninitialize();
|
2006-07-20 12:42:23 +02:00
|
|
|
|
2011-07-05 14:19:26 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
ERR("CoCreateInstance failed with hr = 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirectInput_QueryInterface(pDI, riid, ppDI);
|
|
|
|
IDirectInput_Release(pDI);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2006-07-20 12:42:23 +02:00
|
|
|
/* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */
|
|
|
|
if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) {
|
2011-07-05 14:19:26 +02:00
|
|
|
IDirectInput8A *DI = *ppDI;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IDirectInput8_Release(DI);
|
|
|
|
*ppDI = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2006-07-20 12:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8W, riid)) {
|
2011-07-05 14:19:26 +02:00
|
|
|
IDirectInput8W *DI = *ppDI;
|
|
|
|
|
|
|
|
hr = IDirectInput8_Initialize(DI, hinst, dwVersion);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IDirectInput8_Release(DI);
|
|
|
|
*ppDI = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
2006-07-20 12:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-05-06 20:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* DirectInput8 ClassFactory
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
2010-12-05 15:15:10 +01:00
|
|
|
IClassFactory IClassFactory_iface;
|
2006-05-06 20:45:11 +02:00
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
2010-12-05 15:15:10 +01:00
|
|
|
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
|
|
|
|
}
|
|
|
|
|
2006-05-06 20:45:11 +02:00
|
|
|
static HRESULT WINAPI DI8CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
|
2010-12-05 15:15:10 +01:00
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2006-05-06 20:45:11 +02:00
|
|
|
FIXME("%p %s %p\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DI8CF_AddRef(LPCLASSFACTORY iface) {
|
|
|
|
LockModule();
|
|
|
|
return 2;
|
2002-06-14 02:39:44 +02:00
|
|
|
}
|
|
|
|
|
2006-05-06 20:45:11 +02:00
|
|
|
static ULONG WINAPI DI8CF_Release(LPCLASSFACTORY iface) {
|
|
|
|
UnlockModule();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DI8CF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
|
2010-12-05 15:15:10 +01:00
|
|
|
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2006-05-06 20:45:11 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
|
2006-07-20 12:42:23 +02:00
|
|
|
if( IsEqualGUID( &IID_IDirectInput8A, riid ) || IsEqualGUID( &IID_IDirectInput8W, riid ) || IsEqualGUID( &IID_IUnknown, riid )) {
|
2011-07-05 14:19:17 +02:00
|
|
|
IDirectInputA *ppDI;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&ppDI);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IDirectInput_QueryInterface(ppDI, riid, ppobj);
|
|
|
|
IDirectInput_Release(ppDI);
|
|
|
|
|
|
|
|
return hr;
|
2006-05-06 20:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ERR("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DI8CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
|
|
|
|
TRACE("(%p)->(%d)\n", iface, dolock);
|
|
|
|
|
|
|
|
if(dolock)
|
|
|
|
LockModule();
|
|
|
|
else
|
|
|
|
UnlockModule();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl DI8CF_Vtbl = {
|
|
|
|
DI8CF_QueryInterface,
|
|
|
|
DI8CF_AddRef,
|
|
|
|
DI8CF_Release,
|
|
|
|
DI8CF_CreateInstance,
|
|
|
|
DI8CF_LockServer
|
|
|
|
};
|
2010-12-05 15:15:10 +01:00
|
|
|
static IClassFactoryImpl DINPUT8_CF = { { &DI8CF_Vtbl } };
|
2006-05-06 20:45:11 +02:00
|
|
|
|
|
|
|
|
2002-06-14 02:39:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllCanUnloadNow (DINPUT8.@)
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
2002-06-14 02:39:44 +02:00
|
|
|
{
|
2006-05-06 20:45:11 +02:00
|
|
|
return dll_count == 0 ? S_OK : S_FALSE;
|
2002-06-14 02:39:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllGetClassObject (DINPUT8.@)
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
2002-06-14 02:39:44 +02:00
|
|
|
{
|
2006-05-06 20:45:11 +02:00
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
|
|
|
if ( IsEqualCLSID( &IID_IClassFactory, riid ) ) {
|
2009-01-23 10:36:48 +01:00
|
|
|
*ppv = &DINPUT8_CF;
|
2006-05-06 20:45:11 +02:00
|
|
|
IClassFactory_AddRef((IClassFactory*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-14 02:39:44 +02:00
|
|
|
|
2006-05-06 20:45:11 +02:00
|
|
|
FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
2002-06-14 02:39:44 +02:00
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
2010-12-07 12:45:13 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID lpv)
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
instance = hInstDLL;
|
|
|
|
DisableThreadLibraryCalls( hInstDLL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (DINPUT8.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_register_resources( instance );
|
2010-12-07 12:45:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (DINPUT8.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_unregister_resources( instance );
|
2010-12-07 12:45:13 +01:00
|
|
|
}
|