wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comsvcs / main.c
blob3023783bdf5f84d93dbcb5c187683b49403584b9
1 /*
2 * COM+ Services
4 * Copyright 2013 Alistair Leslie-Hughes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28 #include "rpcproxy.h"
29 #include "comsvcs.h"
30 #include "wine/heap.h"
31 #include "wine/debug.h"
32 #include "initguid.h"
33 #include "comsvcs_classes.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(comsvcs);
37 static HINSTANCE COMSVCS_hInstance;
39 typedef struct dispensermanager
41 IDispenserManager IDispenserManager_iface;
42 LONG ref;
43 CO_MTA_USAGE_COOKIE mta_cookie;
44 } dispensermanager;
46 typedef struct holder
48 IHolder IHolder_iface;
49 LONG ref;
51 IDispenserDriver *driver;
52 } holder;
54 struct new_moniker
56 IMoniker IMoniker_iface;
57 IROTData IROTData_iface;
58 LONG refcount;
59 CLSID clsid;
60 WCHAR *progid;
63 static HRESULT new_moniker_parse_displayname(IBindCtx *pbc, LPOLESTR name, ULONG *eaten, IMoniker **ret);
65 static inline dispensermanager *impl_from_IDispenserManager(IDispenserManager *iface)
67 return CONTAINING_RECORD(iface, dispensermanager, IDispenserManager_iface);
70 static inline holder *impl_from_IHolder(IHolder *iface)
72 return CONTAINING_RECORD(iface, holder, IHolder_iface);
75 static struct new_moniker *impl_from_IMoniker(IMoniker *iface)
77 return CONTAINING_RECORD(iface, struct new_moniker, IMoniker_iface);
80 static struct new_moniker *impl_from_IROTData(IROTData *iface)
82 return CONTAINING_RECORD(iface, struct new_moniker, IROTData_iface);
85 static HRESULT WINAPI holder_QueryInterface(IHolder *iface, REFIID riid, void **object)
87 holder *This = impl_from_IHolder(iface);
89 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), object);
91 *object = NULL;
93 if (IsEqualGUID(riid, &IID_IUnknown) ||
94 IsEqualGUID(riid, &IID_IHolder))
96 *object = &This->IHolder_iface;
97 IUnknown_AddRef( (IUnknown*)*object);
99 return S_OK;
102 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),object);
103 return E_NOINTERFACE;
106 static ULONG WINAPI holder_AddRef(IHolder *iface)
108 holder *This = impl_from_IHolder(iface);
109 ULONG ref = InterlockedIncrement(&This->ref);
110 TRACE("(%p)->(%d)\n", This, ref);
111 return ref;
114 static ULONG WINAPI holder_Release(IHolder *iface)
116 holder *This = impl_from_IHolder(iface);
117 ULONG ref = InterlockedDecrement(&This->ref);
118 TRACE("(%p)->(%d)\n", This, ref);
120 if (!ref)
122 heap_free(This);
125 return ref;
128 static HRESULT WINAPI holder_AllocResource(IHolder *iface, const RESTYPID typeid, RESID *resid)
130 holder *This = impl_from_IHolder(iface);
131 HRESULT hr;
132 TIMEINSECS secs;
134 TRACE("(%p)->(%08lx, %p) stub\n", This, typeid, resid);
136 hr = IDispenserDriver_CreateResource(This->driver, typeid, resid, &secs);
138 TRACE("<- 0x%08x\n", hr);
139 return hr;
142 static HRESULT WINAPI holder_FreeResource(IHolder *iface, const RESID resid)
144 holder *This = impl_from_IHolder(iface);
145 HRESULT hr;
147 TRACE("(%p)->(%08lx) stub\n", This, resid);
149 hr = IDispenserDriver_DestroyResource(This->driver, resid);
151 TRACE("<- 0x%08x\n", hr);
153 return hr;
156 static HRESULT WINAPI holder_TrackResource(IHolder *iface, const RESID resid)
158 holder *This = impl_from_IHolder(iface);
160 FIXME("(%p)->(%08lx) stub\n", This, resid);
162 return E_NOTIMPL;
165 static HRESULT WINAPI holder_TrackResourceS(IHolder *iface, const SRESID resid)
167 holder *This = impl_from_IHolder(iface);
169 FIXME("(%p)->(%s) stub\n", This, debugstr_w(resid));
171 return E_NOTIMPL;
174 static HRESULT WINAPI holder_UntrackResource(IHolder *iface, const RESID resid, const BOOL value)
176 holder *This = impl_from_IHolder(iface);
178 FIXME("(%p)->(%08lx, %d) stub\n", This, resid, value);
180 return E_NOTIMPL;
183 static HRESULT WINAPI holder_UntrackResourceS(IHolder *iface, const SRESID resid, const BOOL value)
185 holder *This = impl_from_IHolder(iface);
187 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(resid), value);
189 return E_NOTIMPL;
192 static HRESULT WINAPI holder_Close(IHolder *iface)
194 holder *This = impl_from_IHolder(iface);
196 FIXME("(%p) stub\n", This);
198 IDispenserDriver_Release(This->driver);
200 return S_OK;
203 static HRESULT WINAPI holder_RequestDestroyResource(IHolder *iface, const RESID resid)
205 holder *This = impl_from_IHolder(iface);
207 FIXME("(%p)->(%08lx) stub\n", This, resid);
209 return E_NOTIMPL;
212 struct IHolderVtbl holder_vtbl =
214 holder_QueryInterface,
215 holder_AddRef,
216 holder_Release,
217 holder_AllocResource,
218 holder_FreeResource,
219 holder_TrackResource,
220 holder_TrackResourceS,
221 holder_UntrackResource,
222 holder_UntrackResourceS,
223 holder_Close,
224 holder_RequestDestroyResource
227 static HRESULT create_holder(IDispenserDriver *driver, IHolder **object)
229 holder *hold;
230 HRESULT ret;
232 TRACE("(%p)\n", object);
234 hold = heap_alloc(sizeof(*hold));
235 if (!hold)
237 *object = NULL;
238 return E_OUTOFMEMORY;
241 hold->IHolder_iface.lpVtbl = &holder_vtbl;
242 hold->ref = 1;
243 hold->driver = driver;
245 ret = holder_QueryInterface(&hold->IHolder_iface, &IID_IHolder, (void**)object);
246 holder_Release(&hold->IHolder_iface);
248 return ret;
251 static HRESULT WINAPI dismanager_QueryInterface(IDispenserManager *iface, REFIID riid, void **object)
253 dispensermanager *This = impl_from_IDispenserManager(iface);
255 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), object);
257 *object = NULL;
259 if (IsEqualGUID(riid, &IID_IUnknown) ||
260 IsEqualGUID(riid, &IID_IDispenserManager))
262 *object = &This->IDispenserManager_iface;
263 IUnknown_AddRef( (IUnknown*)*object);
265 return S_OK;
268 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),object);
269 return E_NOINTERFACE;
272 static ULONG WINAPI dismanager_AddRef(IDispenserManager *iface)
274 dispensermanager *This = impl_from_IDispenserManager(iface);
275 ULONG ref = InterlockedIncrement(&This->ref);
276 TRACE("(%p)->(%d)\n", This, ref);
277 return ref;
280 static ULONG WINAPI dismanager_Release(IDispenserManager *iface)
282 dispensermanager *This = impl_from_IDispenserManager(iface);
283 ULONG ref = InterlockedDecrement(&This->ref);
284 TRACE("(%p)->(%d)\n", This, ref);
286 if (!ref)
288 if (This->mta_cookie)
289 CoDecrementMTAUsage(This->mta_cookie);
290 heap_free(This);
293 return ref;
296 static HRESULT WINAPI dismanager_RegisterDispenser(IDispenserManager *iface, IDispenserDriver *driver,
297 LPCOLESTR name, IHolder **dispenser)
299 dispensermanager *This = impl_from_IDispenserManager(iface);
300 HRESULT hr;
302 TRACE("(%p)->(%p, %s, %p)\n", This, driver, debugstr_w(name), dispenser);
304 if(!dispenser)
305 return E_INVALIDARG;
307 hr = create_holder(driver, dispenser);
309 if (!This->mta_cookie)
310 CoIncrementMTAUsage(&This->mta_cookie);
312 TRACE("<-- 0x%08x, %p\n", hr, *dispenser);
314 return hr;
317 static HRESULT WINAPI dismanager_GetContext(IDispenserManager *iface, INSTID *id, TRANSID *transid)
319 dispensermanager *This = impl_from_IDispenserManager(iface);
321 FIXME("(%p)->(%p, %p) stub\n", This, id, transid);
323 return E_NOTIMPL;
326 struct IDispenserManagerVtbl dismanager_vtbl =
328 dismanager_QueryInterface,
329 dismanager_AddRef,
330 dismanager_Release,
331 dismanager_RegisterDispenser,
332 dismanager_GetContext
335 static HRESULT WINAPI dispenser_manager_cf_CreateInstance(IClassFactory *iface, IUnknown* outer, REFIID riid,
336 void **object)
338 dispensermanager *dismanager;
339 HRESULT ret;
341 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), object);
343 dismanager = heap_alloc_zero(sizeof(*dismanager));
344 if (!dismanager)
346 *object = NULL;
347 return E_OUTOFMEMORY;
350 dismanager->IDispenserManager_iface.lpVtbl = &dismanager_vtbl;
351 dismanager->ref = 1;
353 ret = dismanager_QueryInterface(&dismanager->IDispenserManager_iface, riid, object);
354 dismanager_Release(&dismanager->IDispenserManager_iface);
356 return ret;
359 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID lpv)
361 switch(reason)
363 case DLL_PROCESS_ATTACH:
364 COMSVCS_hInstance = hinst;
365 DisableThreadLibraryCalls(hinst);
366 break;
368 return TRUE;
371 static HRESULT WINAPI comsvcscf_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv )
373 *ppv = NULL;
375 if(IsEqualGUID(&IID_IUnknown, riid)) {
376 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
377 *ppv = iface;
378 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
379 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
380 *ppv = iface;
383 if(*ppv) {
384 IUnknown_AddRef((IUnknown*)*ppv);
385 return S_OK;
388 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
389 return E_NOINTERFACE;
392 static ULONG WINAPI comsvcscf_AddRef(IClassFactory *iface )
394 TRACE("(%p)\n", iface);
395 return 2;
398 static ULONG WINAPI comsvcscf_Release(IClassFactory *iface )
400 TRACE("(%p)\n", iface);
401 return 1;
404 static HRESULT WINAPI comsvcscf_LockServer(IClassFactory *iface, BOOL fLock)
406 TRACE("(%p)->(%x)\n", iface, fLock);
407 return S_OK;
410 static const IClassFactoryVtbl comsvcscf_vtbl =
412 comsvcscf_QueryInterface,
413 comsvcscf_AddRef,
414 comsvcscf_Release,
415 dispenser_manager_cf_CreateInstance,
416 comsvcscf_LockServer
419 static HRESULT WINAPI new_moniker_QueryInterface(IMoniker* iface, REFIID riid, void **obj)
421 struct new_moniker *moniker = impl_from_IMoniker(iface);
423 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
425 *obj = NULL;
427 if (IsEqualIID(&IID_IUnknown, riid) ||
428 IsEqualIID(&IID_IPersist, riid) ||
429 IsEqualIID(&IID_IPersistStream, riid) ||
430 IsEqualIID(&IID_IMoniker, riid))
432 *obj = iface;
434 else if (IsEqualIID(&IID_IROTData, riid))
436 *obj = &moniker->IROTData_iface;
439 if (*obj)
441 IUnknown_AddRef((IUnknown *)*obj);
442 return S_OK;
445 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
446 return E_NOINTERFACE;
449 static ULONG WINAPI new_moniker_AddRef(IMoniker* iface)
451 struct new_moniker *moniker = impl_from_IMoniker(iface);
452 ULONG refcount = InterlockedIncrement(&moniker->refcount);
454 TRACE("%p, refcount %u.\n", iface, refcount);
456 return refcount;
459 static ULONG WINAPI new_moniker_Release(IMoniker* iface)
461 struct new_moniker *moniker = impl_from_IMoniker(iface);
462 ULONG refcount = InterlockedDecrement(&moniker->refcount);
464 TRACE("%p, refcount %u.\n", iface, refcount);
466 if (!refcount)
468 heap_free(moniker->progid);
469 heap_free(moniker);
472 return refcount;
475 static HRESULT WINAPI new_moniker_GetClassID(IMoniker *iface, CLSID *clsid)
477 TRACE("%p, %p.\n", iface, clsid);
479 if (!clsid)
480 return E_POINTER;
482 *clsid = CLSID_NewMoniker;
484 return S_OK;
487 static HRESULT WINAPI new_moniker_IsDirty(IMoniker* iface)
489 TRACE("%p.\n", iface);
491 return S_FALSE;
494 static HRESULT WINAPI new_moniker_Load(IMoniker *iface, IStream *stream)
496 struct new_moniker *moniker = impl_from_IMoniker(iface);
497 DWORD progid_len = 0, len, pad = ~0u;
498 WCHAR *progid = NULL;
499 CLSID clsid;
500 HRESULT hr;
502 TRACE("%p, %p.\n", iface, stream);
504 hr = IStream_Read(stream, &clsid, sizeof(clsid), &len);
505 if (FAILED(hr))
506 return hr;
508 if (SUCCEEDED(hr))
509 hr = IStream_Read(stream, &progid_len, sizeof(progid_len), &len);
511 if (SUCCEEDED(hr) && progid_len)
513 if (!(progid = heap_alloc(progid_len)))
514 return E_OUTOFMEMORY;
515 hr = IStream_Read(stream, progid, progid_len, &len);
518 /* Skip terminator. */
519 if (SUCCEEDED(hr))
520 hr = IStream_Read(stream, &pad, sizeof(pad), &len);
522 if (SUCCEEDED(hr) && pad == 0)
524 moniker->clsid = clsid;
525 heap_free(moniker->progid);
526 moniker->progid = progid;
527 progid = NULL;
530 heap_free(progid);
532 return hr;
535 static HRESULT WINAPI new_moniker_Save(IMoniker *iface, IStream *stream, BOOL clear_dirty)
537 struct new_moniker *moniker = impl_from_IMoniker(iface);
538 ULONG written, pad = 0, progid_len = 0;
539 HRESULT hr;
541 TRACE("%p, %p, %d.\n", iface, stream, clear_dirty);
543 if (moniker->progid)
544 progid_len = lstrlenW(moniker->progid) * sizeof(WCHAR);
546 hr = IStream_Write(stream, &moniker->clsid, sizeof(moniker->clsid), &written);
547 if (SUCCEEDED(hr))
548 hr = IStream_Write(stream, &progid_len, sizeof(progid_len), &written);
549 if (SUCCEEDED(hr) && progid_len)
550 hr = IStream_Write(stream, moniker->progid, progid_len, &written);
551 if (SUCCEEDED(hr))
552 hr = IStream_Write(stream, &pad, sizeof(pad), &written);
554 return hr;
557 static HRESULT WINAPI new_moniker_GetSizeMax(IMoniker *iface, ULARGE_INTEGER *size)
559 struct new_moniker *moniker = impl_from_IMoniker(iface);
561 TRACE("%p, %p.\n", iface, size);
563 if (!size)
564 return E_POINTER;
566 size->QuadPart = sizeof(CLSID) + 2 * sizeof(DWORD);
567 if (moniker->progid)
568 size->QuadPart += lstrlenW(moniker->progid) * sizeof(WCHAR);
570 return S_OK;
573 static HRESULT WINAPI new_moniker_BindToObject(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
574 REFIID riid, void **ret)
576 struct new_moniker *moniker = impl_from_IMoniker(iface);
577 IClassActivator *activator;
578 IClassFactory *factory;
579 BIND_OPTS2 bindopts;
580 MULTI_QI qi;
581 HRESULT hr;
583 TRACE("%p, %p, %p, %s, %p.\n", iface, pbc, pmkToLeft, debugstr_guid(riid), ret);
585 bindopts.cbStruct = sizeof(bindopts);
586 if (FAILED(hr = IBindCtx_GetBindOptions(pbc, (BIND_OPTS *)&bindopts)))
587 return hr;
589 if (!pmkToLeft)
591 qi.pIID = riid;
592 qi.pItf = NULL;
593 qi.hr = S_OK;
594 hr = CoCreateInstanceEx(&moniker->clsid, NULL, bindopts.dwClassContext, bindopts.pServerInfo, 1, &qi);
595 *ret = qi.pItf;
597 else
599 if (SUCCEEDED(hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IClassActivator, (void **)&activator)))
601 hr = IClassActivator_GetClassObject(activator, &moniker->clsid, bindopts.dwClassContext, bindopts.locale, riid, ret);
602 IClassActivator_Release(activator);
604 else if (SUCCEEDED(hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IClassFactory, (void **)&factory)))
606 hr = IClassFactory_CreateInstance(factory, NULL, riid, ret);
607 IClassFactory_Release(factory);
611 return hr;
614 static HRESULT WINAPI new_moniker_BindToStorage(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, REFIID riid,
615 void **ret)
617 FIXME("%p, %p, %p, %s, %p.\n", iface, pbc, pmkToLeft, debugstr_guid(riid), ret);
619 return E_NOTIMPL;
622 static HRESULT WINAPI new_moniker_Reduce(IMoniker *iface, IBindCtx *pbc, DWORD flags, IMoniker **ppmkToLeft,
623 IMoniker **ret)
625 TRACE("%p, %p, %d, %p, %p.\n", iface, pbc, flags, ppmkToLeft, ret);
627 if (!ret)
628 return E_POINTER;
630 *ret = iface;
631 IMoniker_AddRef(iface);
633 return MK_S_REDUCED_TO_SELF;
636 static HRESULT WINAPI new_moniker_ComposeWith(IMoniker *iface, IMoniker *mkRight, BOOL fOnlyIfNotGeneric,
637 IMoniker **ret)
639 FIXME("%p, %p, %d, %p.\n", iface, mkRight, fOnlyIfNotGeneric, ret);
641 return E_NOTIMPL;
644 static HRESULT WINAPI new_moniker_Enum(IMoniker *iface, BOOL forward, IEnumMoniker **enum_moniker)
646 TRACE("%p, %d, %p.\n", iface, forward, enum_moniker);
648 if (!enum_moniker)
649 return E_POINTER;
651 *enum_moniker = NULL;
653 return S_OK;
656 static HRESULT WINAPI new_moniker_IsEqual(IMoniker *iface, IMoniker *other_moniker)
658 FIXME("%p, %p.\n", iface, other_moniker);
660 return E_NOTIMPL;
663 static HRESULT WINAPI new_moniker_Hash(IMoniker *iface, DWORD *hash)
665 struct new_moniker *moniker = impl_from_IMoniker(iface);
667 TRACE("%p, %p.\n", iface, hash);
669 *hash = moniker->clsid.Data1;
671 return S_OK;
674 static HRESULT WINAPI new_moniker_IsRunning(IMoniker* iface, IBindCtx *pbc, IMoniker *pmkToLeft,
675 IMoniker *pmkNewlyRunning)
677 FIXME("%p, %p, %p, %p.\n", iface, pbc, pmkToLeft, pmkNewlyRunning);
679 return E_NOTIMPL;
682 static HRESULT WINAPI new_moniker_GetTimeOfLastChange(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
683 FILETIME *itemtime)
685 TRACE("%p, %p, %p, %p.\n", iface, pbc, pmkToLeft, itemtime);
687 return MK_E_UNAVAILABLE;
690 static HRESULT WINAPI new_moniker_Inverse(IMoniker *iface, IMoniker **inverse)
692 TRACE("%p, %p.\n", iface, inverse);
694 return CreateAntiMoniker(inverse);
697 static HRESULT WINAPI new_moniker_CommonPrefixWith(IMoniker *iface, IMoniker *other, IMoniker **ret)
699 FIXME("%p, %p, %p.\n", iface, other, ret);
701 return E_NOTIMPL;
704 static HRESULT WINAPI new_moniker_RelativePathTo(IMoniker *iface, IMoniker *other, IMoniker **ret)
706 FIXME("%p, %p, %p.\n", iface, other, ret);
708 return E_NOTIMPL;
711 static HRESULT WINAPI new_moniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
712 LPOLESTR *name)
714 FIXME("%p, %p, %p, %p.\n", iface, pbc, pmkToLeft, name);
716 return E_NOTIMPL;
719 static HRESULT WINAPI new_moniker_ParseDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
720 LPOLESTR name, ULONG *eaten, IMoniker **ret)
722 TRACE("%p, %p, %p, %s, %p, %p.\n", iface, pbc, pmkToLeft, debugstr_w(name), eaten, ret);
724 return new_moniker_parse_displayname(pbc, name, eaten, ret);
727 static HRESULT WINAPI new_moniker_IsSystemMoniker(IMoniker *iface, DWORD *moniker_type)
729 TRACE("%p, %p.\n", iface, moniker_type);
731 *moniker_type = MKSYS_NONE;
733 return S_FALSE;
736 static const IMonikerVtbl new_moniker_vtbl =
738 new_moniker_QueryInterface,
739 new_moniker_AddRef,
740 new_moniker_Release,
741 new_moniker_GetClassID,
742 new_moniker_IsDirty,
743 new_moniker_Load,
744 new_moniker_Save,
745 new_moniker_GetSizeMax,
746 new_moniker_BindToObject,
747 new_moniker_BindToStorage,
748 new_moniker_Reduce,
749 new_moniker_ComposeWith,
750 new_moniker_Enum,
751 new_moniker_IsEqual,
752 new_moniker_Hash,
753 new_moniker_IsRunning,
754 new_moniker_GetTimeOfLastChange,
755 new_moniker_Inverse,
756 new_moniker_CommonPrefixWith,
757 new_moniker_RelativePathTo,
758 new_moniker_GetDisplayName,
759 new_moniker_ParseDisplayName,
760 new_moniker_IsSystemMoniker
763 static HRESULT WINAPI new_moniker_rotdata_QueryInterface(IROTData *iface, REFIID riid, void **obj)
765 struct new_moniker *moniker = impl_from_IROTData(iface);
766 return IMoniker_QueryInterface(&moniker->IMoniker_iface, riid, obj);
769 static ULONG WINAPI new_moniker_rotdata_AddRef(IROTData *iface)
771 struct new_moniker *moniker = impl_from_IROTData(iface);
772 return IMoniker_AddRef(&moniker->IMoniker_iface);
775 static ULONG WINAPI new_moniker_rotdata_Release(IROTData *iface)
777 struct new_moniker *moniker = impl_from_IROTData(iface);
778 return IMoniker_Release(&moniker->IMoniker_iface);
781 static HRESULT WINAPI new_moniker_rotdata_GetComparisonData(IROTData *iface, byte *data, ULONG data_len, ULONG *length)
783 FIXME("%p, %p, %u, %p.\n", iface, data, data_len, length);
785 return E_NOTIMPL;
788 static const IROTDataVtbl new_moniker_rotdata_vtbl =
790 new_moniker_rotdata_QueryInterface,
791 new_moniker_rotdata_AddRef,
792 new_moniker_rotdata_Release,
793 new_moniker_rotdata_GetComparisonData,
796 static const BYTE guid_conv_table[256] =
798 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
799 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
800 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
801 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
802 0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 */
803 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
804 0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* 0x60 */
807 static BOOL is_valid_hex(WCHAR c)
809 return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
810 (c >= 'A' && c <= 'F');
813 static HRESULT guid_from_string(const WCHAR *s, GUID *ret)
815 BOOL has_brackets;
816 GUID guid = { 0 };
817 int i;
819 memset(ret, 0, sizeof(*ret));
821 /* Curly brackets are optional. */
822 has_brackets = s[0] == '{';
824 if (has_brackets)
825 s++;
827 for (i = 0; i < 8; i++)
829 if (!is_valid_hex(s[i])) return FALSE;
830 guid.Data1 = (guid.Data1 << 4) | guid_conv_table[s[i]];
832 s += 8;
834 if (s[0] != '-') return FALSE;
835 s++;
837 for (i = 0; i < 4; i++)
839 if (!is_valid_hex(s[0])) return FALSE;
840 guid.Data2 = (guid.Data2 << 4) | guid_conv_table[s[i]];
842 s += 4;
844 if (s[0] != '-') return FALSE;
845 s++;
847 for (i = 0; i < 4; i++)
849 if (!is_valid_hex(s[i])) return FALSE;
850 guid.Data3 = (guid.Data3 << 4) | guid_conv_table[s[i]];
852 s += 4;
854 if (s[0] != '-') return FALSE;
855 s++;
857 for (i = 0; i < 17; i += 2)
859 if (i == 4)
861 if (s[i] != '-') return FALSE;
862 i++;
864 if (!is_valid_hex(s[i]) || !is_valid_hex(s[i+1])) return FALSE;
865 guid.Data4[i / 2] = guid_conv_table[s[i]] << 4 | guid_conv_table[s[i+1]];
867 s += 17;
869 if (has_brackets && s[0] != '}')
870 return FALSE;
872 *ret = guid;
874 return TRUE;
877 static HRESULT new_moniker_parse_displayname(IBindCtx *pbc, LPOLESTR name, ULONG *eaten, IMoniker **ret)
879 struct new_moniker *moniker;
880 WCHAR *progid = NULL, *str;
881 GUID guid;
883 *ret = NULL;
885 if (wcsnicmp(name, L"new:", 4))
886 return MK_E_SYNTAX;
887 str = name + 4;
889 if (!guid_from_string(str, &guid))
891 if (FAILED(CLSIDFromProgID(str, &guid)))
892 return MK_E_SYNTAX;
893 progid = str;
896 moniker = heap_alloc_zero(sizeof(*moniker));
897 if (!moniker)
898 return E_OUTOFMEMORY;
900 moniker->IMoniker_iface.lpVtbl = &new_moniker_vtbl;
901 moniker->IROTData_iface.lpVtbl = &new_moniker_rotdata_vtbl;
902 moniker->refcount = 1;
903 moniker->clsid = guid;
904 if (progid)
906 if (!(moniker->progid = heap_alloc((lstrlenW(progid) + 1) * sizeof(WCHAR))))
908 IMoniker_Release(&moniker->IMoniker_iface);
909 return E_OUTOFMEMORY;
911 lstrcpyW(moniker->progid, progid);
914 *ret = &moniker->IMoniker_iface;
916 if (eaten)
917 *eaten = lstrlenW(name);
919 return S_OK;
922 static HRESULT WINAPI new_moniker_parse_QueryInterface(IParseDisplayName *iface, REFIID riid, void **obj)
924 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
926 if (IsEqualIID(riid, &IID_IParseDisplayName) ||
927 IsEqualIID(riid, &IID_IUnknown))
929 *obj = iface;
930 IParseDisplayName_AddRef(iface);
931 return S_OK;
934 *obj = NULL;
935 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
936 return E_NOINTERFACE;
939 static ULONG WINAPI new_moniker_parse_AddRef(IParseDisplayName *iface)
941 return 2;
944 static ULONG WINAPI new_moniker_parse_Release(IParseDisplayName *iface)
946 return 1;
949 static HRESULT WINAPI new_moniker_parse_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR name,
950 ULONG *eaten, IMoniker **ret)
952 TRACE("%p, %p, %s, %p, %p.\n", iface, pbc, debugstr_w(name), eaten, ret);
954 return new_moniker_parse_displayname(pbc, name, eaten, ret);
957 static const IParseDisplayNameVtbl new_moniker_parse_vtbl =
959 new_moniker_parse_QueryInterface,
960 new_moniker_parse_AddRef,
961 new_moniker_parse_Release,
962 new_moniker_parse_ParseDisplayName,
965 static IParseDisplayName new_moniker_parse = { &new_moniker_parse_vtbl };
967 static HRESULT WINAPI new_moniker_cf_QueryInterface(IClassFactory *iface, REFIID riid, void **obj)
969 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
971 *obj = NULL;
973 if (IsEqualGUID(&IID_IUnknown, riid) ||
974 IsEqualGUID(&IID_IClassFactory, riid))
976 *obj = iface;
978 else if (IsEqualIID(&IID_IParseDisplayName, riid))
980 *obj = &new_moniker_parse;
983 if (*obj)
985 IUnknown_AddRef((IUnknown *)*obj);
986 return S_OK;
989 WARN("Unsupported interface %s.\n", debugstr_guid(riid));
990 return E_NOINTERFACE;
993 static HRESULT WINAPI new_moniker_cf_CreateInstance(IClassFactory *iface, IUnknown* outer, REFIID riid, void **object)
995 TRACE("%p, %p, %s, %p.\n", iface, outer, debugstr_guid(riid), object);
997 if (outer)
998 FIXME("Aggregation is not supported.\n");
1000 return IParseDisplayName_QueryInterface(&new_moniker_parse, riid, object);
1003 static const IClassFactoryVtbl newmoniker_cf_vtbl =
1005 new_moniker_cf_QueryInterface,
1006 comsvcscf_AddRef,
1007 comsvcscf_Release,
1008 new_moniker_cf_CreateInstance,
1009 comsvcscf_LockServer
1012 static IClassFactory DispenserManageFactory = { &comsvcscf_vtbl };
1013 static IClassFactory NewMonikerFactory = { &newmoniker_cf_vtbl };
1015 /******************************************************************
1016 * DllGetClassObject
1018 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
1020 if(IsEqualGUID(&CLSID_DispenserManager, rclsid))
1022 TRACE("(CLSID_DispenserManager %s %p)\n", debugstr_guid(riid), ppv);
1023 return IClassFactory_QueryInterface(&DispenserManageFactory, riid, ppv);
1025 else if (IsEqualGUID(&CLSID_NewMoniker, rclsid))
1027 TRACE("(CLSID_NewMoniker %s %p)\n", debugstr_guid(riid), ppv);
1028 return IClassFactory_QueryInterface(&NewMonikerFactory, riid, ppv);
1031 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1032 return CLASS_E_CLASSNOTAVAILABLE;
1035 /******************************************************************
1036 * DllCanUnloadNow
1038 HRESULT WINAPI DllCanUnloadNow(void)
1040 return S_FALSE;
1043 /***********************************************************************
1044 * DllRegisterServer (comsvcs.@)
1046 HRESULT WINAPI DllRegisterServer(void)
1048 return __wine_register_resources( COMSVCS_hInstance );
1051 /***********************************************************************
1052 * DllUnregisterServer (comsvcs.@)
1054 HRESULT WINAPI DllUnregisterServer(void)
1056 return __wine_unregister_resources( COMSVCS_hInstance );