Sweden-Number/dlls/ddrawex/main.c

281 lines
7.6 KiB
C
Raw Normal View History

2006-12-14 16:39:42 +01:00
/* DirectDrawEx
*
* Copyright 2006 Ulrich Czekalla
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/debug.h"
#define COBJMACROS
#include "winbase.h"
#include "wingdi.h"
#include "objbase.h"
#include "rpcproxy.h"
2006-12-14 16:39:42 +01:00
#include "ddraw.h"
#include "initguid.h"
#include "ddrawex_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
2006-12-14 16:39:42 +01:00
static HINSTANCE instance;
2006-12-14 16:39:42 +01:00
struct ddrawex_class_factory
{
IClassFactory IClassFactory_iface;
LONG ref;
2013-09-12 09:20:54 +02:00
HRESULT (*pfnCreateInstance)(IUnknown *outer, REFIID iid, void **out);
};
static inline struct ddrawex_class_factory *impl_from_IClassFactory(IClassFactory *iface)
{
return CONTAINING_RECORD(iface, struct ddrawex_class_factory, IClassFactory_iface);
}
static HRESULT WINAPI ddrawex_class_factory_QueryInterface(IClassFactory *iface, REFIID riid, void **out)
2006-12-14 16:39:42 +01:00
{
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
2006-12-14 16:39:42 +01:00
if (IsEqualGUID(riid, &IID_IClassFactory)
|| IsEqualGUID(riid, &IID_IUnknown))
2006-12-14 16:39:42 +01:00
{
IClassFactory_AddRef(iface);
*out = iface;
2006-12-14 16:39:42 +01:00
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
*out = NULL;
2006-12-14 16:39:42 +01:00
return E_NOINTERFACE;
}
static ULONG WINAPI ddrawex_class_factory_AddRef(IClassFactory *iface)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
ULONG refcount = InterlockedIncrement(&factory->ref);
2006-12-14 16:39:42 +01:00
TRACE("%p increasing refcount to %u.\n", iface, refcount);
2006-12-14 16:39:42 +01:00
return refcount;
2006-12-14 16:39:42 +01:00
}
static ULONG WINAPI ddrawex_class_factory_Release(IClassFactory *iface)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
ULONG refcount = InterlockedDecrement(&factory->ref);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
2006-12-14 16:39:42 +01:00
if (!refcount)
heap_free(factory);
2006-12-14 16:39:42 +01:00
return refcount;
2006-12-14 16:39:42 +01:00
}
static HRESULT WINAPI ddrawex_class_factory_CreateInstance(IClassFactory *iface,
IUnknown *outer_unknown, REFIID riid, void **out)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_class_factory *factory = impl_from_IClassFactory(iface);
2006-12-14 16:39:42 +01:00
TRACE("iface %p, outer_unknown %p, riid %s, out %p.\n",
iface, outer_unknown, debugstr_guid(riid), out);
2006-12-14 16:39:42 +01:00
return factory->pfnCreateInstance(outer_unknown, riid, out);
2006-12-14 16:39:42 +01:00
}
static HRESULT WINAPI ddrawex_class_factory_LockServer(IClassFactory *iface, BOOL dolock)
2006-12-14 16:39:42 +01:00
{
FIXME("iface %p, dolock %#x stub!\n", iface, dolock);
2006-12-14 16:39:42 +01:00
return S_OK;
}
static const IClassFactoryVtbl ddrawex_class_factory_vtbl =
2006-12-14 16:39:42 +01:00
{
ddrawex_class_factory_QueryInterface,
ddrawex_class_factory_AddRef,
ddrawex_class_factory_Release,
ddrawex_class_factory_CreateInstance,
ddrawex_class_factory_LockServer,
2006-12-14 16:39:42 +01:00
};
struct ddrawex_factory
{
IDirectDrawFactory IDirectDrawFactory_iface;
LONG ref;
};
static inline struct ddrawex_factory *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
{
return CONTAINING_RECORD(iface, struct ddrawex_factory, IDirectDrawFactory_iface);
}
static HRESULT WINAPI ddrawex_factory_QueryInterface(IDirectDrawFactory *iface, REFIID riid, void **out)
2006-12-14 16:39:42 +01:00
{
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
2006-12-14 16:39:42 +01:00
if (IsEqualGUID(riid, &IID_IDirectDrawFactory)
|| IsEqualGUID(riid, &IID_IUnknown))
2006-12-14 16:39:42 +01:00
{
IDirectDrawFactory_AddRef(iface);
*out = iface;
2006-12-14 16:39:42 +01:00
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
*out = NULL;
2006-12-14 16:39:42 +01:00
return E_NOINTERFACE;
}
static ULONG WINAPI ddrawex_factory_AddRef(IDirectDrawFactory *iface)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_factory *factory = impl_from_IDirectDrawFactory(iface);
ULONG refcount = InterlockedIncrement(&factory->ref);
2006-12-14 16:39:42 +01:00
TRACE("%p increasing refcount to %u.\n", iface, refcount);
2006-12-14 16:39:42 +01:00
return refcount;
2006-12-14 16:39:42 +01:00
}
static ULONG WINAPI ddrawex_factory_Release(IDirectDrawFactory *iface)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_factory *factory = impl_from_IDirectDrawFactory(iface);
ULONG refcount = InterlockedDecrement(&factory->ref);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
2006-12-14 16:39:42 +01:00
if (!refcount)
heap_free(factory);
2006-12-14 16:39:42 +01:00
return refcount;
2006-12-14 16:39:42 +01:00
}
static HRESULT WINAPI ddrawex_factory_DirectDrawEnumerate(IDirectDrawFactory *iface,
2013-09-12 09:20:54 +02:00
LPDDENUMCALLBACKW cb, void *ctx)
2006-12-14 16:39:42 +01:00
{
FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
2006-12-14 16:39:42 +01:00
return E_FAIL;
}
static const IDirectDrawFactoryVtbl ddrawex_factory_vtbl =
2006-12-14 16:39:42 +01:00
{
ddrawex_factory_QueryInterface,
ddrawex_factory_AddRef,
ddrawex_factory_Release,
ddrawex_factory_CreateDirectDraw,
ddrawex_factory_DirectDrawEnumerate,
2006-12-14 16:39:42 +01:00
};
static HRESULT ddrawex_factory_create(IUnknown *outer_unknown, REFIID riid, void **out)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_factory *factory;
2006-12-14 16:39:42 +01:00
HRESULT hr;
TRACE("outer_unknown %p, riid %s, out %p.\n", outer_unknown, debugstr_guid(riid), out);
2006-12-14 16:39:42 +01:00
if (outer_unknown)
2006-12-14 16:39:42 +01:00
return CLASS_E_NOAGGREGATION;
if (!(factory = heap_alloc_zero(sizeof(*factory))))
2006-12-14 16:39:42 +01:00
return E_OUTOFMEMORY;
factory->IDirectDrawFactory_iface.lpVtbl = &ddrawex_factory_vtbl;
2006-12-14 16:39:42 +01:00
if (FAILED(hr = ddrawex_factory_QueryInterface(&factory->IDirectDrawFactory_iface, riid, out)))
heap_free(factory);
2006-12-14 16:39:42 +01:00
return hr;
}
/*******************************************************************************
* DllCanUnloadNow [DDRAWEX.@] Determines whether the DLL is in use.
*/
HRESULT WINAPI DllCanUnloadNow(void)
{
return S_FALSE;
}
/*******************************************************************************
* DllGetClassObject [DDRAWEX.@]
*/
2013-09-12 09:20:54 +02:00
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **out)
2006-12-14 16:39:42 +01:00
{
struct ddrawex_class_factory *factory;
2006-12-14 16:39:42 +01:00
2013-09-12 09:20:54 +02:00
TRACE("rclsid %s, riid %s, out %p.\n", debugstr_guid(rclsid), debugstr_guid(riid), out);
2006-12-14 16:39:42 +01:00
if (!IsEqualGUID( &IID_IClassFactory, riid)
&& !IsEqualGUID( &IID_IUnknown, riid))
return E_NOINTERFACE;
if (!IsEqualGUID(&CLSID_DirectDrawFactory, rclsid))
{
FIXME("%s: no class found.\n", debugstr_guid(rclsid));
return CLASS_E_CLASSNOTAVAILABLE;
}
if (!(factory = heap_alloc_zero(sizeof(*factory))))
return E_OUTOFMEMORY;
2006-12-14 16:39:42 +01:00
factory->IClassFactory_iface.lpVtbl = &ddrawex_class_factory_vtbl;
2006-12-14 16:39:42 +01:00
factory->ref = 1;
factory->pfnCreateInstance = ddrawex_factory_create;
2006-12-14 16:39:42 +01:00
2013-09-12 09:20:54 +02:00
*out = factory;
2006-12-14 16:39:42 +01:00
return S_OK;
}
/***********************************************************************
* DllMain
*/
2013-09-12 09:20:54 +02:00
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
2006-12-14 16:39:42 +01:00
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
2013-09-12 09:20:54 +02:00
instance = inst;
DisableThreadLibraryCalls( inst );
break;
}
2006-12-14 16:39:42 +01:00
return TRUE;
}
/***********************************************************************
* DllRegisterServer (DDRAWEX.@)
*/
HRESULT WINAPI DllRegisterServer(void)
{
return __wine_register_resources( instance );
}
/***********************************************************************
* DllUnregisterServer (DDRAWEX.@)
*/
HRESULT WINAPI DllUnregisterServer(void)
{
return __wine_unregister_resources( instance );
}