include/wine/test.h: Fix tests compilation with a PSDK compiler.
[wine/multimedia.git] / dlls / ole32 / classmoniker.c
blobd220d91ec7179bf406f0925ac9b8308484fe864a
1 /*
2 * Class Monikers
4 * Copyright 1999 Noomen Hamza
5 * Copyright 2005-2007 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "wine/debug.h"
35 #include "ole2.h"
36 #include "wine/unicode.h"
37 #include "moniker.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 #define CHARS_IN_GUID 39
43 /* ClassMoniker data structure */
44 typedef struct ClassMoniker
46 IMoniker IMoniker_iface;
47 IROTData IROTData_iface;
48 LONG ref;
49 CLSID clsid; /* clsid identified by this moniker */
50 IUnknown *pMarshal; /* custom marshaler */
51 } ClassMoniker;
53 static inline ClassMoniker *impl_from_IMoniker(IMoniker *iface)
55 return CONTAINING_RECORD(iface, ClassMoniker, IMoniker_iface);
58 static inline ClassMoniker *impl_from_IROTData(IROTData *iface)
60 return CONTAINING_RECORD(iface, ClassMoniker, IROTData_iface);
63 /*******************************************************************************
64 * ClassMoniker_QueryInterface
65 *******************************************************************************/
66 static HRESULT WINAPI ClassMoniker_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
68 ClassMoniker *This = impl_from_IMoniker(iface);
70 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
72 /* Perform a sanity check on the parameters.*/
73 if (!ppvObject)
74 return E_POINTER;
76 /* Initialize the return parameter */
77 *ppvObject = 0;
79 /* Compare the riid with the interface IDs implemented by this object.*/
80 if (IsEqualIID(&IID_IUnknown, riid) ||
81 IsEqualIID(&IID_IPersist, riid) ||
82 IsEqualIID(&IID_IPersistStream, riid) ||
83 IsEqualIID(&IID_IMoniker, riid))
85 *ppvObject = iface;
87 else if (IsEqualIID(&IID_IROTData, riid))
88 *ppvObject = &This->IROTData_iface;
89 else if (IsEqualIID(&IID_IMarshal, riid))
91 HRESULT hr = S_OK;
92 if (!This->pMarshal)
93 hr = MonikerMarshal_Create(iface, &This->pMarshal);
94 if (hr != S_OK)
95 return hr;
96 return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
99 /* Check that we obtained an interface.*/
100 if (!*ppvObject)
101 return E_NOINTERFACE;
103 /* Query Interface always increases the reference count by one when it is successful */
104 IMoniker_AddRef(iface);
106 return S_OK;
109 /******************************************************************************
110 * ClassMoniker_AddRef
111 ******************************************************************************/
112 static ULONG WINAPI ClassMoniker_AddRef(IMoniker* iface)
114 ClassMoniker *This = impl_from_IMoniker(iface);
116 TRACE("(%p)\n",This);
118 return InterlockedIncrement(&This->ref);
121 /******************************************************************************
122 * ClassMoniker_Destroy (local function)
123 *******************************************************************************/
124 static HRESULT ClassMoniker_Destroy(ClassMoniker* This)
126 TRACE("(%p)\n",This);
128 if (This->pMarshal) IUnknown_Release(This->pMarshal);
130 HeapFree(GetProcessHeap(),0,This);
132 return S_OK;
135 /******************************************************************************
136 * ClassMoniker_Release
137 ******************************************************************************/
138 static ULONG WINAPI ClassMoniker_Release(IMoniker* iface)
140 ClassMoniker *This = impl_from_IMoniker(iface);
141 ULONG ref;
143 TRACE("(%p)\n",This);
145 ref = InterlockedDecrement(&This->ref);
147 /* destroy the object if there's no more reference on it */
148 if (ref == 0) ClassMoniker_Destroy(This);
150 return ref;
153 /******************************************************************************
154 * ClassMoniker_GetClassID
155 ******************************************************************************/
156 static HRESULT WINAPI ClassMoniker_GetClassID(IMoniker* iface,CLSID *pClassID)
158 TRACE("(%p,%p),stub!\n",iface,pClassID);
160 if (pClassID==NULL)
161 return E_POINTER;
163 *pClassID = CLSID_ClassMoniker;
165 return S_OK;
168 /******************************************************************************
169 * ClassMoniker_IsDirty
170 ******************************************************************************/
171 static HRESULT WINAPI ClassMoniker_IsDirty(IMoniker* iface)
173 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
174 method in the OLE-provided moniker interfaces always return S_FALSE because
175 their internal state never changes. */
177 TRACE("(%p)\n",iface);
179 return S_FALSE;
182 /******************************************************************************
183 * ClassMoniker_Load
184 ******************************************************************************/
185 static HRESULT WINAPI ClassMoniker_Load(IMoniker* iface,IStream* pStm)
187 ClassMoniker *This = impl_from_IMoniker(iface);
188 HRESULT hr;
189 DWORD zero;
191 TRACE("(%p)\n", pStm);
193 hr = IStream_Read(pStm, &This->clsid, sizeof(This->clsid), NULL);
194 if (hr != S_OK) return STG_E_READFAULT;
196 hr = IStream_Read(pStm, &zero, sizeof(zero), NULL);
197 if ((hr != S_OK) || (zero != 0)) return STG_E_READFAULT;
199 return S_OK;
202 /******************************************************************************
203 * ClassMoniker_Save
204 ******************************************************************************/
205 static HRESULT WINAPI ClassMoniker_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty)
207 ClassMoniker *This = impl_from_IMoniker(iface);
208 HRESULT hr;
209 DWORD zero = 0;
211 TRACE("(%p, %s)\n", pStm, fClearDirty ? "TRUE" : "FALSE");
213 hr = IStream_Write(pStm, &This->clsid, sizeof(This->clsid), NULL);
214 if (FAILED(hr)) return hr;
216 return IStream_Write(pStm, &zero, sizeof(zero), NULL);
219 /******************************************************************************
220 * ClassMoniker_GetSizeMax
221 ******************************************************************************/
222 static HRESULT WINAPI ClassMoniker_GetSizeMax(IMoniker* iface,
223 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
225 TRACE("(%p)\n", pcbSize);
227 pcbSize->QuadPart = sizeof(CLSID) + sizeof(DWORD);
229 return S_OK;
232 /******************************************************************************
233 * ClassMoniker_BindToObject
234 ******************************************************************************/
235 static HRESULT WINAPI ClassMoniker_BindToObject(IMoniker* iface,
236 IBindCtx* pbc,
237 IMoniker* pmkToLeft,
238 REFIID riid,
239 VOID** ppvResult)
241 ClassMoniker *This = impl_from_IMoniker(iface);
242 BIND_OPTS2 bindopts;
243 IClassActivator *pActivator;
244 HRESULT hr;
246 TRACE("(%p,%p,%p,%p)\n", pbc, pmkToLeft, riid, ppvResult);
248 bindopts.cbStruct = sizeof(bindopts);
249 IBindCtx_GetBindOptions(pbc, (BIND_OPTS *)&bindopts);
251 if (!pmkToLeft)
252 return CoGetClassObject(&This->clsid, bindopts.dwClassContext, NULL,
253 riid, ppvResult);
254 else
256 hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IClassActivator,
257 (void **)&pActivator);
258 if (FAILED(hr)) return hr;
260 hr = IClassActivator_GetClassObject(pActivator, &This->clsid,
261 bindopts.dwClassContext,
262 bindopts.locale, riid, ppvResult);
264 IClassActivator_Release(pActivator);
266 return hr;
270 /******************************************************************************
271 * ClassMoniker_BindToStorage
272 ******************************************************************************/
273 static HRESULT WINAPI ClassMoniker_BindToStorage(IMoniker* iface,
274 IBindCtx* pbc,
275 IMoniker* pmkToLeft,
276 REFIID riid,
277 VOID** ppvResult)
279 TRACE("(%p,%p,%p,%p)\n",pbc, pmkToLeft, riid, ppvResult);
280 return ClassMoniker_BindToObject(iface, pbc, pmkToLeft, riid, ppvResult);
283 /******************************************************************************
284 * ClassMoniker_Reduce
285 ******************************************************************************/
286 static HRESULT WINAPI ClassMoniker_Reduce(IMoniker* iface,
287 IBindCtx* pbc,
288 DWORD dwReduceHowFar,
289 IMoniker** ppmkToLeft,
290 IMoniker** ppmkReduced)
292 TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
294 if (!ppmkReduced)
295 return E_POINTER;
297 ClassMoniker_AddRef(iface);
299 *ppmkReduced = iface;
301 return MK_S_REDUCED_TO_SELF;
303 /******************************************************************************
304 * ClassMoniker_ComposeWith
305 ******************************************************************************/
306 static HRESULT WINAPI ClassMoniker_ComposeWith(IMoniker* iface,
307 IMoniker* pmkRight,
308 BOOL fOnlyIfNotGeneric,
309 IMoniker** ppmkComposite)
311 HRESULT res=S_OK;
312 DWORD mkSys,mkSys2;
313 IEnumMoniker* penumMk=0;
314 IMoniker *pmostLeftMk=0;
315 IMoniker* tempMkComposite=0;
317 TRACE("(%p,%d,%p)\n", pmkRight, fOnlyIfNotGeneric, ppmkComposite);
319 if ((ppmkComposite==NULL)||(pmkRight==NULL))
320 return E_POINTER;
322 *ppmkComposite=0;
324 IMoniker_IsSystemMoniker(pmkRight,&mkSys);
326 /* If pmkRight is an anti-moniker, the returned moniker is NULL */
327 if(mkSys==MKSYS_ANTIMONIKER)
328 return res;
330 else
331 /* if pmkRight is a composite whose leftmost component is an anti-moniker, */
332 /* the returned moniker is the composite after the leftmost anti-moniker is removed. */
334 if(mkSys==MKSYS_GENERICCOMPOSITE){
336 res=IMoniker_Enum(pmkRight,TRUE,&penumMk);
338 if (FAILED(res))
339 return res;
341 res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL);
343 IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2);
345 if(mkSys2==MKSYS_ANTIMONIKER){
347 IMoniker_Release(pmostLeftMk);
349 tempMkComposite=iface;
350 IMoniker_AddRef(iface);
352 while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){
354 res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite);
356 IMoniker_Release(tempMkComposite);
357 IMoniker_Release(pmostLeftMk);
359 tempMkComposite=*ppmkComposite;
360 IMoniker_AddRef(tempMkComposite);
362 return res;
364 else
365 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
367 /* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
368 composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
369 a NULL moniker and a return value of MK_E_NEEDGENERIC */
370 else
371 if (!fOnlyIfNotGeneric)
372 return CreateGenericComposite(iface,pmkRight,ppmkComposite);
374 else
375 return MK_E_NEEDGENERIC;
378 /******************************************************************************
379 * ClassMoniker_Enum
380 ******************************************************************************/
381 static HRESULT WINAPI ClassMoniker_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
383 TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
385 if (ppenumMoniker == NULL)
386 return E_POINTER;
388 *ppenumMoniker = NULL;
390 return S_OK;
393 /******************************************************************************
394 * ClassMoniker_IsEqual
395 ******************************************************************************/
396 static HRESULT WINAPI ClassMoniker_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
399 CLSID clsid;
400 LPOLESTR dispName1,dispName2;
401 IBindCtx* bind;
402 HRESULT res = S_FALSE;
404 TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
406 if (!pmkOtherMoniker) return S_FALSE;
409 /* check if both are ClassMoniker */
410 if(FAILED (IMoniker_GetClassID(pmkOtherMoniker,&clsid))) return S_FALSE;
411 if(!IsEqualCLSID(&clsid,&CLSID_ClassMoniker)) return S_FALSE;
413 /* check if both displaynames are the same */
414 if(SUCCEEDED ((res = CreateBindCtx(0,&bind)))) {
415 if(SUCCEEDED (IMoniker_GetDisplayName(iface,bind,NULL,&dispName1))) {
416 if(SUCCEEDED (IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&dispName2))) {
417 if(lstrcmpW(dispName1,dispName2)==0) res = S_OK;
418 CoTaskMemFree(dispName2);
420 CoTaskMemFree(dispName1);
423 return res;
426 /******************************************************************************
427 * ClassMoniker_Hash
428 ******************************************************************************/
429 static HRESULT WINAPI ClassMoniker_Hash(IMoniker* iface,DWORD* pdwHash)
431 ClassMoniker *This = impl_from_IMoniker(iface);
433 TRACE("(%p)\n", pdwHash);
435 *pdwHash = This->clsid.Data1;
437 return S_OK;
440 /******************************************************************************
441 * ClassMoniker_IsRunning
442 ******************************************************************************/
443 static HRESULT WINAPI ClassMoniker_IsRunning(IMoniker* iface,
444 IBindCtx* pbc,
445 IMoniker* pmkToLeft,
446 IMoniker* pmkNewlyRunning)
448 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, pmkNewlyRunning);
450 /* as in native */
451 return E_NOTIMPL;
454 /******************************************************************************
455 * ClassMoniker_GetTimeOfLastChange
456 ******************************************************************************/
457 static HRESULT WINAPI ClassMoniker_GetTimeOfLastChange(IMoniker* iface,
458 IBindCtx* pbc,
459 IMoniker* pmkToLeft,
460 FILETIME* pItemTime)
462 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, pItemTime);
464 return MK_E_UNAVAILABLE;
467 /******************************************************************************
468 * ClassMoniker_Inverse
469 ******************************************************************************/
470 static HRESULT WINAPI ClassMoniker_Inverse(IMoniker* iface,IMoniker** ppmk)
472 TRACE("(%p)\n",ppmk);
474 if (!ppmk)
475 return E_POINTER;
477 return CreateAntiMoniker(ppmk);
480 /******************************************************************************
481 * ClassMoniker_CommonPrefixWith
482 ******************************************************************************/
483 static HRESULT WINAPI ClassMoniker_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
485 DWORD mkSys;
487 TRACE("(%p, %p)\n", pmkOther, ppmkPrefix);
489 *ppmkPrefix = NULL;
491 IMoniker_IsSystemMoniker(pmkOther, &mkSys);
493 /* If the other moniker is an class moniker that is equal to this moniker, this method sets *ppmkPrefix */
494 /* to this moniker and returns MK_S_US */
496 if (mkSys == MKSYS_CLASSMONIKER)
498 if (IMoniker_IsEqual(iface, pmkOther) == S_OK)
500 *ppmkPrefix = iface;
502 IMoniker_AddRef(iface);
504 return MK_S_US;
506 else
507 return MK_E_NOPREFIX;
509 else
510 /* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
511 /* the case where the other moniker is a generic composite. */
512 return MonikerCommonPrefixWith(iface, pmkOther, ppmkPrefix);
515 /******************************************************************************
516 * ClassMoniker_RelativePathTo
517 ******************************************************************************/
518 static HRESULT WINAPI ClassMoniker_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
520 TRACE("(%p, %p)\n",pmOther,ppmkRelPath);
522 if (!ppmkRelPath)
523 return E_POINTER;
525 *ppmkRelPath = NULL;
527 return MK_E_NOTBINDABLE;
530 /******************************************************************************
531 * ClassMoniker_GetDisplayName
532 ******************************************************************************/
533 static HRESULT WINAPI ClassMoniker_GetDisplayName(IMoniker* iface,
534 IBindCtx* pbc,
535 IMoniker* pmkToLeft,
536 LPOLESTR *ppszDisplayName)
538 ClassMoniker *This = impl_from_IMoniker(iface);
539 static const WCHAR wszClsidPrefix[] = {'c','l','s','i','d',':',0};
541 TRACE("(%p, %p, %p)\n", pbc, pmkToLeft, ppszDisplayName);
543 if (!ppszDisplayName)
544 return E_POINTER;
546 if (pmkToLeft)
547 return E_INVALIDARG;
549 *ppszDisplayName = CoTaskMemAlloc(sizeof(wszClsidPrefix) + (CHARS_IN_GUID-2) * sizeof(WCHAR));
551 StringFromGUID2(&This->clsid, *ppszDisplayName+sizeof(wszClsidPrefix)/sizeof(WCHAR)-2, CHARS_IN_GUID);
553 /* note: this overwrites the opening curly bracket of the CLSID string generated above */
554 memcpy(*ppszDisplayName, wszClsidPrefix, sizeof(wszClsidPrefix)-sizeof(WCHAR));
556 /* note: this overwrites the closing curly bracket of the CLSID string generated above */
557 (*ppszDisplayName)[sizeof(wszClsidPrefix)/sizeof(WCHAR)-2+CHARS_IN_GUID-2] = ':';
558 (*ppszDisplayName)[sizeof(wszClsidPrefix)/sizeof(WCHAR)-2+CHARS_IN_GUID-1] = '\0';
560 TRACE("string is %s\n", debugstr_w(*ppszDisplayName));
561 return S_OK;
564 /******************************************************************************
565 * ClassMoniker_ParseDisplayName
566 ******************************************************************************/
567 static HRESULT WINAPI ClassMoniker_ParseDisplayName(IMoniker* iface,
568 IBindCtx* pbc,
569 IMoniker* pmkToLeft,
570 LPOLESTR pszDisplayName,
571 ULONG* pchEaten,
572 IMoniker** ppmkOut)
574 FIXME("(%p, %p, %s, %p, %p)\n", pbc, pmkToLeft, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
575 return E_NOTIMPL;
578 /******************************************************************************
579 * ClassMoniker_IsSystemMoniker
580 ******************************************************************************/
581 static HRESULT WINAPI ClassMoniker_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
583 TRACE("(%p,%p)\n",iface,pwdMksys);
585 if (!pwdMksys)
586 return E_POINTER;
588 *pwdMksys = MKSYS_CLASSMONIKER;
590 return S_OK;
593 /*******************************************************************************
594 * ClassMonikerIROTData_QueryInterface
595 *******************************************************************************/
596 static HRESULT WINAPI ClassMonikerROTData_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
599 ClassMoniker *This = impl_from_IROTData(iface);
601 TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
603 return ClassMoniker_QueryInterface(&This->IMoniker_iface, riid, ppvObject);
606 /***********************************************************************
607 * ClassMonikerIROTData_AddRef
609 static ULONG WINAPI ClassMonikerROTData_AddRef(IROTData *iface)
611 ClassMoniker *This = impl_from_IROTData(iface);
613 TRACE("(%p)\n",iface);
615 return ClassMoniker_AddRef(&This->IMoniker_iface);
618 /***********************************************************************
619 * ClassMonikerIROTData_Release
621 static ULONG WINAPI ClassMonikerROTData_Release(IROTData* iface)
623 ClassMoniker *This = impl_from_IROTData(iface);
625 TRACE("(%p)\n",iface);
627 return ClassMoniker_Release(&This->IMoniker_iface);
630 /******************************************************************************
631 * ClassMonikerIROTData_GetComparisonData
632 ******************************************************************************/
633 static HRESULT WINAPI ClassMonikerROTData_GetComparisonData(IROTData* iface,
634 BYTE* pbData,
635 ULONG cbMax,
636 ULONG* pcbData)
638 ClassMoniker *This = impl_from_IROTData(iface);
640 TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
642 *pcbData = 2*sizeof(CLSID);
643 if (cbMax < *pcbData)
644 return E_OUTOFMEMORY;
646 /* write CLSID of the moniker */
647 memcpy(pbData, &CLSID_ClassMoniker, sizeof(CLSID));
648 /* write CLSID the moniker represents */
649 memcpy(pbData+sizeof(CLSID), &This->clsid, sizeof(CLSID));
651 return S_OK;
654 /********************************************************************************/
655 /* Virtual function table for the ClassMoniker class which include IPersist,*/
656 /* IPersistStream and IMoniker functions. */
657 static const IMonikerVtbl ClassMonikerVtbl =
659 ClassMoniker_QueryInterface,
660 ClassMoniker_AddRef,
661 ClassMoniker_Release,
662 ClassMoniker_GetClassID,
663 ClassMoniker_IsDirty,
664 ClassMoniker_Load,
665 ClassMoniker_Save,
666 ClassMoniker_GetSizeMax,
667 ClassMoniker_BindToObject,
668 ClassMoniker_BindToStorage,
669 ClassMoniker_Reduce,
670 ClassMoniker_ComposeWith,
671 ClassMoniker_Enum,
672 ClassMoniker_IsEqual,
673 ClassMoniker_Hash,
674 ClassMoniker_IsRunning,
675 ClassMoniker_GetTimeOfLastChange,
676 ClassMoniker_Inverse,
677 ClassMoniker_CommonPrefixWith,
678 ClassMoniker_RelativePathTo,
679 ClassMoniker_GetDisplayName,
680 ClassMoniker_ParseDisplayName,
681 ClassMoniker_IsSystemMoniker
684 /********************************************************************************/
685 /* Virtual function table for the IROTData class. */
686 static const IROTDataVtbl ROTDataVtbl =
688 ClassMonikerROTData_QueryInterface,
689 ClassMonikerROTData_AddRef,
690 ClassMonikerROTData_Release,
691 ClassMonikerROTData_GetComparisonData
694 /******************************************************************************
695 * ClassMoniker_Construct (local function)
696 *******************************************************************************/
697 static HRESULT ClassMoniker_Construct(ClassMoniker* This, REFCLSID rclsid)
699 TRACE("(%p,%s)\n",This,debugstr_guid(rclsid));
701 /* Initialize the virtual function table. */
702 This->IMoniker_iface.lpVtbl = &ClassMonikerVtbl;
703 This->IROTData_iface.lpVtbl = &ROTDataVtbl;
704 This->ref = 0;
705 This->clsid = *rclsid;
706 This->pMarshal = NULL;
708 return S_OK;
711 /******************************************************************************
712 * CreateClassMoniker [OLE32.@]
713 ******************************************************************************/
714 HRESULT WINAPI CreateClassMoniker(REFCLSID rclsid, IMoniker **ppmk)
716 ClassMoniker* newClassMoniker;
717 HRESULT hr;
719 TRACE("(%s,%p)\n", debugstr_guid(rclsid), ppmk);
721 newClassMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassMoniker));
723 if (!newClassMoniker)
724 return STG_E_INSUFFICIENTMEMORY;
726 hr = ClassMoniker_Construct(newClassMoniker, rclsid);
728 if (FAILED(hr))
730 HeapFree(GetProcessHeap(), 0, newClassMoniker);
731 return hr;
734 return ClassMoniker_QueryInterface(&newClassMoniker->IMoniker_iface, &IID_IMoniker,
735 (void**)ppmk);
738 HRESULT ClassMoniker_CreateFromDisplayName(LPBC pbc, LPCOLESTR szDisplayName, LPDWORD pchEaten,
739 IMoniker **ppmk)
741 HRESULT hr;
742 LPCWSTR s = strchrW(szDisplayName, ':');
743 LPCWSTR end;
744 CLSID clsid;
745 BYTE table[256];
746 int i;
748 if (!s)
749 return MK_E_SYNTAX;
751 s++;
753 for (end = s; *end && (*end != ':'); end++)
756 TRACE("parsing %s\n", debugstr_wn(s, end - s));
758 /* validate the CLSID string */
759 if (s[0] == '{')
761 if ((end - s != 38) || (s[37] != '}'))
762 return MK_E_SYNTAX;
763 s++;
765 else
767 if (end - s != 36)
768 return MK_E_SYNTAX;
771 for (i=0; i<36; i++)
773 if ((i == 8)||(i == 13)||(i == 18)||(i == 23))
775 if (s[i] != '-')
776 return MK_E_SYNTAX;
777 continue;
779 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
780 ((s[i] >= 'a') && (s[i] <= 'f')) ||
781 ((s[i] >= 'A') && (s[i] <= 'F'))))
782 return MK_E_SYNTAX;
785 /* quick lookup table */
786 memset(table, 0, 256);
788 for (i = 0; i < 10; i++)
789 table['0' + i] = i;
790 for (i = 0; i < 6; i++)
792 table['A' + i] = i+10;
793 table['a' + i] = i+10;
796 /* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */
798 clsid.Data1 = (table[s[0]] << 28 | table[s[1]] << 24 | table[s[2]] << 20 | table[s[3]] << 16 |
799 table[s[4]] << 12 | table[s[5]] << 8 | table[s[6]] << 4 | table[s[7]]);
800 clsid.Data2 = table[s[9]] << 12 | table[s[10]] << 8 | table[s[11]] << 4 | table[s[12]];
801 clsid.Data3 = table[s[14]] << 12 | table[s[15]] << 8 | table[s[16]] << 4 | table[s[17]];
803 /* these are just sequential bytes */
804 clsid.Data4[0] = table[s[19]] << 4 | table[s[20]];
805 clsid.Data4[1] = table[s[21]] << 4 | table[s[22]];
806 clsid.Data4[2] = table[s[24]] << 4 | table[s[25]];
807 clsid.Data4[3] = table[s[26]] << 4 | table[s[27]];
808 clsid.Data4[4] = table[s[28]] << 4 | table[s[29]];
809 clsid.Data4[5] = table[s[30]] << 4 | table[s[31]];
810 clsid.Data4[6] = table[s[32]] << 4 | table[s[33]];
811 clsid.Data4[7] = table[s[34]] << 4 | table[s[35]];
813 hr = CreateClassMoniker(&clsid, ppmk);
814 if (SUCCEEDED(hr))
815 *pchEaten = (*end == ':' ? end + 1 : end) - szDisplayName;
816 return hr;
819 static HRESULT WINAPI ClassMonikerCF_QueryInterface(LPCLASSFACTORY iface,
820 REFIID riid, LPVOID *ppv)
822 *ppv = NULL;
823 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
825 *ppv = iface;
826 IUnknown_AddRef(iface);
827 return S_OK;
829 return E_NOINTERFACE;
832 static ULONG WINAPI ClassMonikerCF_AddRef(LPCLASSFACTORY iface)
834 return 2; /* non-heap based object */
837 static ULONG WINAPI ClassMonikerCF_Release(LPCLASSFACTORY iface)
839 return 1; /* non-heap based object */
842 static HRESULT WINAPI ClassMonikerCF_CreateInstance(LPCLASSFACTORY iface,
843 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
845 HRESULT hr;
846 IMoniker *pmk;
848 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
850 *ppv = NULL;
852 if (pUnk)
853 return CLASS_E_NOAGGREGATION;
855 hr = CreateClassMoniker(&CLSID_NULL, &pmk);
856 if (FAILED(hr)) return hr;
858 hr = IMoniker_QueryInterface(pmk, riid, ppv);
859 IMoniker_Release(pmk);
861 return hr;
864 static HRESULT WINAPI ClassMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
866 FIXME("(%d), stub!\n",fLock);
867 return S_OK;
870 static const IClassFactoryVtbl ClassMonikerCFVtbl =
872 ClassMonikerCF_QueryInterface,
873 ClassMonikerCF_AddRef,
874 ClassMonikerCF_Release,
875 ClassMonikerCF_CreateInstance,
876 ClassMonikerCF_LockServer
878 static const IClassFactoryVtbl *ClassMonikerCF = &ClassMonikerCFVtbl;
880 HRESULT ClassMonikerCF_Create(REFIID riid, LPVOID *ppv)
882 return IClassFactory_QueryInterface((IClassFactory *)&ClassMonikerCF, riid, ppv);