2 * Copyright (C) 2015 Austin English
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(evr
);
35 static HINSTANCE instance_evr
;
37 BOOL WINAPI
DllMain(HINSTANCE instance
, DWORD reason
, LPVOID reserved
)
39 TRACE("(%p, %d, %p)\n", instance
, reason
, reserved
);
43 case DLL_WINE_PREATTACH
:
44 return FALSE
; /* prefer native version */
45 case DLL_PROCESS_ATTACH
:
46 instance_evr
= instance
;
47 DisableThreadLibraryCalls(instance
);
55 IClassFactory IClassFactory_iface
;
58 HRESULT (*pfnCreateInstance
)(IUnknown
*unk_outer
, void **ppobj
);
61 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
63 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
66 struct object_creation_info
69 HRESULT (*pfnCreateInstance
)(IUnknown
*unk_outer
, void **ppobj
);
72 static const struct object_creation_info object_creation
[] =
77 static HRESULT WINAPI
classfactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppobj
)
79 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
81 if (IsEqualGUID(riid
, &IID_IUnknown
)
82 || IsEqualGUID(riid
, &IID_IClassFactory
))
84 IClassFactory_AddRef(iface
);
85 *ppobj
= &This
->IClassFactory_iface
;
89 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
93 static ULONG WINAPI
classfactory_AddRef(IClassFactory
*iface
)
95 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
96 return InterlockedIncrement(&This
->ref
);
99 static ULONG WINAPI
classfactory_Release(IClassFactory
*iface
)
101 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
102 ULONG ref
= InterlockedDecrement(&This
->ref
);
105 HeapFree(GetProcessHeap(), 0, This
);
110 static HRESULT WINAPI
classfactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer_unk
, REFIID riid
, void **ppobj
)
112 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
116 TRACE("(%p)->(%p,%s,%p)\n", This
, outer_unk
, debugstr_guid(riid
), ppobj
);
119 hres
= This
->pfnCreateInstance(outer_unk
, (void **) &unk
);
122 hres
= IUnknown_QueryInterface(unk
, riid
, ppobj
);
123 IUnknown_Release(unk
);
128 static HRESULT WINAPI
classfactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
130 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
131 FIXME("(%p)->(%d), stub!\n", This
, dolock
);
135 static const IClassFactoryVtbl classfactory_Vtbl
=
137 classfactory_QueryInterface
,
139 classfactory_Release
,
140 classfactory_CreateInstance
,
141 classfactory_LockServer
144 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
147 IClassFactoryImpl
*factory
;
149 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
151 if (!IsEqualGUID(&IID_IClassFactory
, riid
)
152 && !IsEqualGUID( &IID_IUnknown
, riid
))
153 return E_NOINTERFACE
;
155 for (i
= 0; i
< sizeof(object_creation
)/sizeof(object_creation
[0]); i
++)
157 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
161 if (i
== sizeof(object_creation
)/sizeof(object_creation
[0]))
163 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
164 return CLASS_E_CLASSNOTAVAILABLE
;
167 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*factory
));
169 return E_OUTOFMEMORY
;
171 factory
->IClassFactory_iface
.lpVtbl
= &classfactory_Vtbl
;
174 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
176 *ppv
= &(factory
->IClassFactory_iface
);
180 HRESULT WINAPI
DllCanUnloadNow(void)
185 HRESULT WINAPI
DllRegisterServer(void)
187 return __wine_register_resources(instance_evr
);
190 HRESULT WINAPI
DllUnregisterServer(void)
192 return __wine_unregister_resources(instance_evr
);