antimoniker.c 20.9 KB
Newer Older
1
/*
Noomen Hamza's avatar
Noomen Hamza committed
2 3 4
 *	                      AntiMonikers implementation
 *
 *               Copyright 1999  Noomen Hamza
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18 19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
Noomen Hamza's avatar
Noomen Hamza committed
20 21

#include <assert.h>
22
#include <stdarg.h>
23
#include <string.h>
24

25
#define COBJMACROS
26 27
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
28

29
#include "windef.h"
30
#include "winbase.h"
Noomen Hamza's avatar
Noomen Hamza committed
31
#include "winerror.h"
32
#include "objbase.h"
33
#include "wine/debug.h"
34
#include "moniker.h"
Noomen Hamza's avatar
Noomen Hamza committed
35

36
WINE_DEFAULT_DEBUG_CHANNEL(ole);
37

Noomen Hamza's avatar
Noomen Hamza committed
38 39 40
/* AntiMoniker data structure */
typedef struct AntiMonikerImpl{

41
    const IMonikerVtbl*  lpvtbl1;  /* VTable relative to the IMoniker interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
42

43
    /* The ROT (RunningObjectTable implementation) uses the IROTData interface to test whether
Noomen Hamza's avatar
Noomen Hamza committed
44 45
     * two monikers are equal. That's whay IROTData interface is implemented by monikers.
     */
46
    const IROTDataVtbl*  lpvtbl2;  /* VTable relative to the IROTData interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
47

48
    LONG ref; /* reference counter for this object */
Noomen Hamza's avatar
Noomen Hamza committed
49

50
    IUnknown *pMarshal; /* custom marshaler */
Noomen Hamza's avatar
Noomen Hamza committed
51 52
} AntiMonikerImpl;

53 54 55 56 57
static inline IMoniker *impl_from_IROTData( IROTData *iface )
{
    return (IMoniker *)((char*)iface - FIELD_OFFSET(AntiMonikerImpl, lpvtbl2));
}

Noomen Hamza's avatar
Noomen Hamza committed
58 59 60 61

/*******************************************************************************
 *        AntiMoniker_QueryInterface
 *******************************************************************************/
62 63
static HRESULT WINAPI
AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
64
{
65
    AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
66

67
    TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
68

69
    /* Perform a sanity check on the parameters.*/
Noomen Hamza's avatar
Noomen Hamza committed
70 71
    if ( (This==0) || (ppvObject==0) )
	return E_INVALIDARG;
72

73 74
    /* Initialize the return parameter */
    *ppvObject = 0;
Noomen Hamza's avatar
Noomen Hamza committed
75

76 77 78 79 80 81
    /* Compare the riid with the interface IDs implemented by this object.*/
    if (IsEqualIID(&IID_IUnknown, riid) ||
        IsEqualIID(&IID_IPersist, riid) ||
        IsEqualIID(&IID_IPersistStream, riid) ||
        IsEqualIID(&IID_IMoniker, riid))
        *ppvObject = iface;
Noomen Hamza's avatar
Noomen Hamza committed
82
    else if (IsEqualIID(&IID_IROTData, riid))
83
        *ppvObject = &This->lpvtbl2;
84 85 86 87 88 89 90 91 92
    else if (IsEqualIID(&IID_IMarshal, riid))
    {
        HRESULT hr = S_OK;
        if (!This->pMarshal)
            hr = MonikerMarshal_Create(iface, &This->pMarshal);
        if (hr != S_OK)
            return hr;
        return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
    }
Noomen Hamza's avatar
Noomen Hamza committed
93

94
    /* Check that we obtained an interface.*/
Noomen Hamza's avatar
Noomen Hamza committed
95 96
    if ((*ppvObject)==0)
        return E_NOINTERFACE;
97

98 99
    /* always increase the reference count by one when it is successful */
    IMoniker_AddRef(iface);
Noomen Hamza's avatar
Noomen Hamza committed
100

101
    return S_OK;
Noomen Hamza's avatar
Noomen Hamza committed
102 103 104 105 106
}

/******************************************************************************
 *        AntiMoniker_AddRef
 ******************************************************************************/
107 108
static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
109
{
110
    AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
111

112
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
113

114
    return InterlockedIncrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
115 116 117 118 119
}

/******************************************************************************
 *        AntiMoniker_Release
 ******************************************************************************/
120 121
static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
122
{
123
    AntiMonikerImpl *This = (AntiMonikerImpl *)iface;
124
    ULONG ref;
Noomen Hamza's avatar
Noomen Hamza committed
125

126
    TRACE("(%p)\n",This);
Noomen Hamza's avatar
Noomen Hamza committed
127

128
    ref = InterlockedDecrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
129 130

    /* destroy the object if there's no more reference on it */
131 132 133 134 135
    if (ref == 0)
    {
        if (This->pMarshal) IUnknown_Release(This->pMarshal);
        HeapFree(GetProcessHeap(),0,This);
    }
Noomen Hamza's avatar
Noomen Hamza committed
136

137
    return ref;
Noomen Hamza's avatar
Noomen Hamza committed
138 139 140 141 142
}

/******************************************************************************
 *        AntiMoniker_GetClassID
 ******************************************************************************/
143 144
static HRESULT WINAPI
AntiMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
Noomen Hamza's avatar
Noomen Hamza committed
145
{
146
    TRACE("(%p,%p)\n",iface,pClassID);
Noomen Hamza's avatar
Noomen Hamza committed
147 148 149

    if (pClassID==NULL)
        return E_POINTER;
150

Noomen Hamza's avatar
Noomen Hamza committed
151
    *pClassID = CLSID_AntiMoniker;
152

Noomen Hamza's avatar
Noomen Hamza committed
153 154 155 156 157 158
    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsDirty
 ******************************************************************************/
159 160
static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
161 162 163 164 165
{
    /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
       method in the OLE-provided moniker interfaces always return S_FALSE because
       their internal state never changes. */

166
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
167 168 169 170 171 172 173

    return S_FALSE;
}

/******************************************************************************
 *        AntiMoniker_Load
 ******************************************************************************/
174 175
static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
Noomen Hamza's avatar
Noomen Hamza committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
{
    DWORD constant=1,dwbuffer;
    HRESULT res;

    /* data read by this function is only a DWORD constant (must be 1) ! */
    res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),NULL);

    if (SUCCEEDED(res)&& dwbuffer!=constant)
        return E_FAIL;

    return res;
}

/******************************************************************************
 *        AntiMoniker_Save
 ******************************************************************************/
192 193
static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
Noomen Hamza's avatar
Noomen Hamza committed
194 195 196
{
    DWORD constant=1;
    HRESULT res;
197

Francois Gouget's avatar
Francois Gouget committed
198
    /* data written by this function is only a DWORD constant set to 1 ! */
Noomen Hamza's avatar
Noomen Hamza committed
199 200 201 202 203 204 205
    res=IStream_Write(pStm,&constant,sizeof(constant),NULL);

    return res;
}

/******************************************************************************
 *        AntiMoniker_GetSizeMax
206 207 208
 *
 * PARAMS
 * pcbSize [out] Pointer to size of stream needed to save object
Noomen Hamza's avatar
Noomen Hamza committed
209
 ******************************************************************************/
210 211
static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
Noomen Hamza's avatar
Noomen Hamza committed
212
{
213
    TRACE("(%p,%p)\n",iface,pcbSize);
Noomen Hamza's avatar
Noomen Hamza committed
214

215
    if (!pcbSize)
Noomen Hamza's avatar
Noomen Hamza committed
216 217
        return E_POINTER;

Austin English's avatar
Austin English committed
218
    /* for more details see AntiMonikerImpl_Save comments */
219

220 221 222 223 224
    /*
     * Normally the sizemax must be sizeof DWORD, but
     * I tested this function it usually return 16 bytes
     * more than the number of bytes used by AntiMoniker::Save function
     */
225
    pcbSize->u.LowPart =  sizeof(DWORD)+16;
Noomen Hamza's avatar
Noomen Hamza committed
226

227
    pcbSize->u.HighPart=0;
Noomen Hamza's avatar
Noomen Hamza committed
228 229 230 231 232 233 234

    return S_OK;
}

/******************************************************************************
 *                  AntiMoniker_BindToObject
 ******************************************************************************/
235 236 237
static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                             REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
238
{
239
    TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
240 241 242 243 244 245
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_BindToStorage
 ******************************************************************************/
246 247 248
static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                              REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
249
{
250
    TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
251 252 253 254 255 256
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_Reduce
 ******************************************************************************/
257 258 259
static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
                       IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
Noomen Hamza's avatar
Noomen Hamza committed
260
{
261
    TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
Noomen Hamza's avatar
Noomen Hamza committed
262 263 264 265 266 267 268

    if (ppmkReduced==NULL)
        return E_POINTER;

    AntiMonikerImpl_AddRef(iface);

    *ppmkReduced=iface;
269

Noomen Hamza's avatar
Noomen Hamza committed
270 271 272 273 274
    return MK_S_REDUCED_TO_SELF;
}
/******************************************************************************
 *        AntiMoniker_ComposeWith
 ******************************************************************************/
275 276 277
static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
                            BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
Noomen Hamza's avatar
Noomen Hamza committed
278 279
{

280
    TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
Noomen Hamza's avatar
Noomen Hamza committed
281 282 283 284 285

    if ((ppmkComposite==NULL)||(pmkRight==NULL))
	return E_POINTER;

    *ppmkComposite=0;
286

Noomen Hamza's avatar
Noomen Hamza committed
287 288 289 290 291 292 293 294 295
    if (fOnlyIfNotGeneric)
        return MK_E_NEEDGENERIC;
    else
        return CreateGenericComposite(iface,pmkRight,ppmkComposite);
}

/******************************************************************************
 *        AntiMoniker_Enum
 ******************************************************************************/
296 297
static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
298
{
299
    TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
300 301 302

    if (ppenumMoniker == NULL)
        return E_POINTER;
303

Noomen Hamza's avatar
Noomen Hamza committed
304 305 306 307 308 309 310 311
    *ppenumMoniker = NULL;

    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsEqual
 ******************************************************************************/
312 313
static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
314 315
{
    DWORD mkSys;
316

317
    TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
318 319 320

    if (pmkOtherMoniker==NULL)
        return S_FALSE;
321

Noomen Hamza's avatar
Noomen Hamza committed
322 323 324 325 326 327 328 329 330 331 332
    IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);

    if (mkSys==MKSYS_ANTIMONIKER)
        return S_OK;
    else
        return S_FALSE;
}

/******************************************************************************
 *        AntiMoniker_Hash
 ******************************************************************************/
333
static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
Noomen Hamza's avatar
Noomen Hamza committed
334 335 336 337
{
    if (pdwHash==NULL)
        return E_POINTER;

338
    *pdwHash = 0x80000001;
Noomen Hamza's avatar
Noomen Hamza committed
339 340 341 342 343 344 345

    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsRunning
 ******************************************************************************/
346 347 348
static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                          IMoniker* pmkNewlyRunning)
Noomen Hamza's avatar
Noomen Hamza committed
349 350 351 352
{
    IRunningObjectTable* rot;
    HRESULT res;

353
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
Noomen Hamza's avatar
Noomen Hamza committed
354 355 356 357 358 359 360

    if (pbc==NULL)
        return E_INVALIDARG;

    res=IBindCtx_GetRunningObjectTable(pbc,&rot);

    if (FAILED(res))
361
        return res;
Noomen Hamza's avatar
Noomen Hamza committed
362 363 364 365 366 367 368 369 370 371 372

    res = IRunningObjectTable_IsRunning(rot,iface);

    IRunningObjectTable_Release(rot);

    return res;
}

/******************************************************************************
 *        AntiMoniker_GetTimeOfLastChange
 ******************************************************************************/
373
static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
Noomen Hamza's avatar
Noomen Hamza committed
374 375 376 377
                                                   IBindCtx* pbc,
                                                   IMoniker* pmkToLeft,
                                                   FILETIME* pAntiTime)
{
378
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
Noomen Hamza's avatar
Noomen Hamza committed
379 380 381 382 383 384
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_Inverse
 ******************************************************************************/
385 386
static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
Noomen Hamza's avatar
Noomen Hamza committed
387
{
388
    TRACE("(%p,%p)\n",iface,ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
389 390 391 392 393 394 395 396 397 398 399 400

    if (ppmk==NULL)
        return E_POINTER;

    *ppmk=0;

    return MK_E_NOINVERSE;
}

/******************************************************************************
 *        AntiMoniker_CommonPrefixWith
 ******************************************************************************/
401 402
static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
Noomen Hamza's avatar
Noomen Hamza committed
403 404
{
    DWORD mkSys;
405

Noomen Hamza's avatar
Noomen Hamza committed
406 407
    IMoniker_IsSystemMoniker(pmkOther,&mkSys);

408
    if(mkSys==MKSYS_ANTIMONIKER){
Noomen Hamza's avatar
Noomen Hamza committed
409 410 411 412 413 414

        IMoniker_AddRef(iface);

        *ppmkPrefix=iface;

        IMoniker_AddRef(iface);
415

Noomen Hamza's avatar
Noomen Hamza committed
416 417 418 419 420 421 422 423 424
        return MK_S_US;
    }
    else
        return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
}

/******************************************************************************
 *        AntiMoniker_RelativePathTo
 ******************************************************************************/
425 426
static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
Noomen Hamza's avatar
Noomen Hamza committed
427
{
428
    TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
Noomen Hamza's avatar
Noomen Hamza committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442

    if (ppmkRelPath==NULL)
        return E_POINTER;

    IMoniker_AddRef(pmOther);

    *ppmkRelPath=pmOther;

    return MK_S_HIM;
}

/******************************************************************************
 *        AntiMoniker_GetDisplayName
 ******************************************************************************/
443 444 445
static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
                               IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
Noomen Hamza's avatar
Noomen Hamza committed
446
{
447
    static const WCHAR back[]={'\\','.','.',0};
448

449
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
Noomen Hamza's avatar
Noomen Hamza committed
450 451 452 453 454

    if (ppszDisplayName==NULL)
        return E_POINTER;

    if (pmkToLeft!=NULL){
455
        FIXME("() pmkToLeft!=NULL not implemented\n");
Noomen Hamza's avatar
Noomen Hamza committed
456 457 458 459 460 461 462 463
        return E_NOTIMPL;
    }

    *ppszDisplayName=CoTaskMemAlloc(sizeof(back));

    if (*ppszDisplayName==NULL)
        return E_OUTOFMEMORY;

464
    lstrcpyW(*ppszDisplayName,back);
465

Noomen Hamza's avatar
Noomen Hamza committed
466 467 468 469 470 471
    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_ParseDisplayName
 ******************************************************************************/
472 473 474 475
static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
                                 IMoniker* pmkToLeft, LPOLESTR pszDisplayName,
                                 ULONG* pchEaten, IMoniker** ppmkOut)
Noomen Hamza's avatar
Noomen Hamza committed
476
{
477
    TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
Noomen Hamza's avatar
Noomen Hamza committed
478 479 480 481
    return E_NOTIMPL;
}

/******************************************************************************
Andreas Mohr's avatar
Andreas Mohr committed
482
 *        AntiMoniker_IsSystemMoniker
Noomen Hamza's avatar
Noomen Hamza committed
483
 ******************************************************************************/
484 485
static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
Noomen Hamza's avatar
Noomen Hamza committed
486
{
487
    TRACE("(%p,%p)\n",iface,pwdMksys);
Noomen Hamza's avatar
Noomen Hamza committed
488 489 490

    if (!pwdMksys)
        return E_POINTER;
491

Noomen Hamza's avatar
Noomen Hamza committed
492 493 494 495 496 497 498 499
    (*pwdMksys)=MKSYS_ANTIMONIKER;

    return S_OK;
}

/*******************************************************************************
 *        AntiMonikerIROTData_QueryInterface
 *******************************************************************************/
500 501
static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
502
{
503
    IMoniker *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
504

505
    TRACE("(%p,%p,%p)\n",iface,riid,ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
506 507 508 509 510 511 512

    return AntiMonikerImpl_QueryInterface(This, riid, ppvObject);
}

/***********************************************************************
 *        AntiMonikerIROTData_AddRef
 */
513
static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
Noomen Hamza's avatar
Noomen Hamza committed
514
{
515
    IMoniker *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
516

517
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
518 519 520 521 522 523 524

    return AntiMonikerImpl_AddRef(This);
}

/***********************************************************************
 *        AntiMonikerIROTData_Release
 */
525
static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
Noomen Hamza's avatar
Noomen Hamza committed
526
{
527
    IMoniker *This = impl_from_IROTData(iface);
528

529
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
530 531 532 533 534

    return AntiMonikerImpl_Release(This);
}

/******************************************************************************
535
 *        AntiMonikerIROTData_GetComparisonData
Noomen Hamza's avatar
Noomen Hamza committed
536
 ******************************************************************************/
537
static HRESULT WINAPI
538
AntiMonikerROTDataImpl_GetComparisonData(IROTData* iface, BYTE* pbData,
539
                                          ULONG cbMax, ULONG* pcbData)
Noomen Hamza's avatar
Noomen Hamza committed
540
{
541 542
    DWORD constant = 1;

543
    TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
544 545 546 547 548 549 550 551 552

    *pcbData = sizeof(CLSID) + sizeof(DWORD);
    if (cbMax < *pcbData)
        return E_OUTOFMEMORY;

    memcpy(pbData, &CLSID_AntiMoniker, sizeof(CLSID));
    memcpy(pbData+sizeof(CLSID), &constant, sizeof(DWORD));

    return S_OK;
Noomen Hamza's avatar
Noomen Hamza committed
553 554
}

555 556 557
/********************************************************************************/
/* Virtual function table for the AntiMonikerImpl class which  include IPersist,*/
/* IPersistStream and IMoniker functions.                                       */
558
static const IMonikerVtbl VT_AntiMonikerImpl =
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
{
    AntiMonikerImpl_QueryInterface,
    AntiMonikerImpl_AddRef,
    AntiMonikerImpl_Release,
    AntiMonikerImpl_GetClassID,
    AntiMonikerImpl_IsDirty,
    AntiMonikerImpl_Load,
    AntiMonikerImpl_Save,
    AntiMonikerImpl_GetSizeMax,
    AntiMonikerImpl_BindToObject,
    AntiMonikerImpl_BindToStorage,
    AntiMonikerImpl_Reduce,
    AntiMonikerImpl_ComposeWith,
    AntiMonikerImpl_Enum,
    AntiMonikerImpl_IsEqual,
    AntiMonikerImpl_Hash,
    AntiMonikerImpl_IsRunning,
    AntiMonikerImpl_GetTimeOfLastChange,
    AntiMonikerImpl_Inverse,
    AntiMonikerImpl_CommonPrefixWith,
    AntiMonikerImpl_RelativePathTo,
    AntiMonikerImpl_GetDisplayName,
    AntiMonikerImpl_ParseDisplayName,
    AntiMonikerImpl_IsSystemMoniker
};

/********************************************************************************/
/* Virtual function table for the IROTData class.                               */
587
static const IROTDataVtbl VT_ROTDataImpl =
588 589 590 591
{
    AntiMonikerROTDataImpl_QueryInterface,
    AntiMonikerROTDataImpl_AddRef,
    AntiMonikerROTDataImpl_Release,
592
    AntiMonikerROTDataImpl_GetComparisonData
593 594 595 596 597 598 599 600 601 602
};

/******************************************************************************
 *         AntiMoniker_Construct (local function)
 *******************************************************************************/
static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
{

    TRACE("(%p)\n",This);

Austin English's avatar
Austin English committed
603
    /* Initialize the virtual function table. */
604 605 606
    This->lpvtbl1      = &VT_AntiMonikerImpl;
    This->lpvtbl2      = &VT_ROTDataImpl;
    This->ref          = 0;
607
    This->pMarshal     = NULL;
608 609 610 611

    return S_OK;
}

Noomen Hamza's avatar
Noomen Hamza committed
612
/******************************************************************************
613
 *        CreateAntiMoniker	[OLE32.@]
Noomen Hamza's avatar
Noomen Hamza committed
614 615 616 617 618 619
 ******************************************************************************/
HRESULT WINAPI CreateAntiMoniker(LPMONIKER * ppmk)
{
    AntiMonikerImpl* newAntiMoniker = 0;
    HRESULT        hr = S_OK;
    IID riid=IID_IMoniker;
620

621
    TRACE("(%p)\n",ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
622 623 624 625 626 627 628

    newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));

    if (newAntiMoniker == 0)
        return STG_E_INSUFFICIENTMEMORY;

    hr = AntiMonikerImpl_Construct(newAntiMoniker);
629 630
    if (FAILED(hr))
    {
Noomen Hamza's avatar
Noomen Hamza committed
631 632 633 634 635 636 637 638
        HeapFree(GetProcessHeap(),0,newAntiMoniker);
        return hr;
    }

    hr = AntiMonikerImpl_QueryInterface((IMoniker*)newAntiMoniker,&riid,(void**)ppmk);

    return hr;
}
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707

static HRESULT WINAPI AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface,
                                                  REFIID riid, LPVOID *ppv)
{
    *ppv = NULL;
    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
    {
        *ppv = iface;
        IUnknown_AddRef(iface);
        return S_OK;
    }
    return E_NOINTERFACE;
}

static ULONG WINAPI AntiMonikerCF_AddRef(LPCLASSFACTORY iface)
{
    return 2; /* non-heap based object */
}

static ULONG WINAPI AntiMonikerCF_Release(LPCLASSFACTORY iface)
{
    return 1; /* non-heap based object */
}

static HRESULT WINAPI AntiMonikerCF_CreateInstance(LPCLASSFACTORY iface,
    LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
{
    IMoniker *pMoniker;
    HRESULT  hr;

    TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);

    *ppv = NULL;

    if (pUnk)
        return CLASS_E_NOAGGREGATION;

    hr = CreateAntiMoniker(&pMoniker);
    if (FAILED(hr))
        return hr;

  	hr = IMoniker_QueryInterface(pMoniker, riid, ppv);

    if (FAILED(hr))
        IMoniker_Release(pMoniker);

    return hr;
}

static HRESULT WINAPI AntiMonikerCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
{
    FIXME("(%d), stub!\n",fLock);
    return S_OK;
}

static const IClassFactoryVtbl AntiMonikerCFVtbl =
{
    AntiMonikerCF_QueryInterface,
    AntiMonikerCF_AddRef,
    AntiMonikerCF_Release,
    AntiMonikerCF_CreateInstance,
    AntiMonikerCF_LockServer
};
static const IClassFactoryVtbl *AntiMonikerCF = &AntiMonikerCFVtbl;

HRESULT AntiMonikerCF_Create(REFIID riid, LPVOID *ppv)
{
    return IClassFactory_QueryInterface((IClassFactory *)&AntiMonikerCF, riid, ppv);
}