antimoniker.c 19.6 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
#define NONAMELESSUNION
27

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

35
WINE_DEFAULT_DEBUG_CHANNEL(ole);
36

Noomen Hamza's avatar
Noomen Hamza committed
37 38
/* AntiMoniker data structure */
typedef struct AntiMonikerImpl{
39 40 41
    IMoniker IMoniker_iface;
    IROTData IROTData_iface;
    LONG ref;
42
    IUnknown *pMarshal; /* custom marshaler */
Noomen Hamza's avatar
Noomen Hamza committed
43 44
} AntiMonikerImpl;

45 46 47 48 49 50
static inline AntiMonikerImpl *impl_from_IMoniker(IMoniker *iface)
{
    return CONTAINING_RECORD(iface, AntiMonikerImpl, IMoniker_iface);
}

static inline AntiMonikerImpl *impl_from_IROTData(IROTData *iface)
51
{
52
    return CONTAINING_RECORD(iface, AntiMonikerImpl, IROTData_iface);
53 54
}

Noomen Hamza's avatar
Noomen Hamza committed
55 56 57 58

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

64
    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
65

66
    /* Perform a sanity check on the parameters.*/
67
    if ( ppvObject==0 )
Noomen Hamza's avatar
Noomen Hamza committed
68
	return E_INVALIDARG;
69

70 71
    /* Initialize the return parameter */
    *ppvObject = 0;
Noomen Hamza's avatar
Noomen Hamza committed
72

73 74 75 76 77 78
    /* 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
79
    else if (IsEqualIID(&IID_IROTData, riid))
80
        *ppvObject = &This->IROTData_iface;
81 82 83 84 85 86 87 88 89
    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
90

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

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

98
    return S_OK;
Noomen Hamza's avatar
Noomen Hamza committed
99 100 101 102 103
}

/******************************************************************************
 *        AntiMoniker_AddRef
 ******************************************************************************/
104 105
static ULONG WINAPI
AntiMonikerImpl_AddRef(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
106
{
107
    AntiMonikerImpl *This = impl_from_IMoniker(iface);
Noomen Hamza's avatar
Noomen Hamza committed
108

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

111
    return InterlockedIncrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
112 113 114 115 116
}

/******************************************************************************
 *        AntiMoniker_Release
 ******************************************************************************/
117 118
static ULONG WINAPI
AntiMonikerImpl_Release(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
119
{
120
    AntiMonikerImpl *This = impl_from_IMoniker(iface);
121
    ULONG ref;
Noomen Hamza's avatar
Noomen Hamza committed
122

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

125
    ref = InterlockedDecrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
126

127
    /* destroy the object if there are no more references to it */
128 129 130 131 132
    if (ref == 0)
    {
        if (This->pMarshal) IUnknown_Release(This->pMarshal);
        HeapFree(GetProcessHeap(),0,This);
    }
Noomen Hamza's avatar
Noomen Hamza committed
133

134
    return ref;
Noomen Hamza's avatar
Noomen Hamza committed
135 136 137 138 139
}

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

    if (pClassID==NULL)
        return E_POINTER;
147

Noomen Hamza's avatar
Noomen Hamza committed
148
    *pClassID = CLSID_AntiMoniker;
149

Noomen Hamza's avatar
Noomen Hamza committed
150 151 152 153 154 155
    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsDirty
 ******************************************************************************/
156 157
static HRESULT WINAPI
AntiMonikerImpl_IsDirty(IMoniker* iface)
Noomen Hamza's avatar
Noomen Hamza committed
158 159 160 161 162
{
    /* 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. */

163
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
164 165 166 167 168 169 170

    return S_FALSE;
}

/******************************************************************************
 *        AntiMoniker_Load
 ******************************************************************************/
171 172
static HRESULT WINAPI
AntiMonikerImpl_Load(IMoniker* iface,IStream* pStm)
Noomen Hamza's avatar
Noomen Hamza committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
{
    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
 ******************************************************************************/
189 190
static HRESULT WINAPI
AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty)
Noomen Hamza's avatar
Noomen Hamza committed
191
{
192
    static const DWORD constant = 1;
Francois Gouget's avatar
Francois Gouget committed
193
    /* data written by this function is only a DWORD constant set to 1 ! */
194
    return IStream_Write(pStm,&constant,sizeof(constant),NULL);
Noomen Hamza's avatar
Noomen Hamza committed
195 196 197 198
}

/******************************************************************************
 *        AntiMoniker_GetSizeMax
199 200 201
 *
 * PARAMS
 * pcbSize [out] Pointer to size of stream needed to save object
Noomen Hamza's avatar
Noomen Hamza committed
202
 ******************************************************************************/
203 204
static HRESULT WINAPI
AntiMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
Noomen Hamza's avatar
Noomen Hamza committed
205
{
206
    TRACE("(%p,%p)\n",iface,pcbSize);
Noomen Hamza's avatar
Noomen Hamza committed
207

208
    if (!pcbSize)
Noomen Hamza's avatar
Noomen Hamza committed
209 210
        return E_POINTER;

Austin English's avatar
Austin English committed
211
    /* for more details see AntiMonikerImpl_Save comments */
212

213 214 215 216 217
    /*
     * 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
     */
218
    pcbSize->u.LowPart =  sizeof(DWORD)+16;
Noomen Hamza's avatar
Noomen Hamza committed
219

220
    pcbSize->u.HighPart=0;
Noomen Hamza's avatar
Noomen Hamza committed
221 222 223 224 225 226 227

    return S_OK;
}

/******************************************************************************
 *                  AntiMoniker_BindToObject
 ******************************************************************************/
228 229 230
static HRESULT WINAPI
AntiMonikerImpl_BindToObject(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                             REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
231
{
232
    TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
233 234 235 236 237 238
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_BindToStorage
 ******************************************************************************/
239 240 241
static HRESULT WINAPI
AntiMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                              REFIID riid, VOID** ppvResult)
Noomen Hamza's avatar
Noomen Hamza committed
242
{
243
    TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
Noomen Hamza's avatar
Noomen Hamza committed
244 245 246 247 248 249
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_Reduce
 ******************************************************************************/
250 251 252
static HRESULT WINAPI
AntiMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
                       IMoniker** ppmkToLeft, IMoniker** ppmkReduced)
Noomen Hamza's avatar
Noomen Hamza committed
253
{
254
    TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
Noomen Hamza's avatar
Noomen Hamza committed
255 256 257 258 259 260 261

    if (ppmkReduced==NULL)
        return E_POINTER;

    AntiMonikerImpl_AddRef(iface);

    *ppmkReduced=iface;
262

Noomen Hamza's avatar
Noomen Hamza committed
263 264 265 266 267
    return MK_S_REDUCED_TO_SELF;
}
/******************************************************************************
 *        AntiMoniker_ComposeWith
 ******************************************************************************/
268 269 270
static HRESULT WINAPI
AntiMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
                            BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite)
Noomen Hamza's avatar
Noomen Hamza committed
271 272
{

273
    TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
Noomen Hamza's avatar
Noomen Hamza committed
274 275 276 277 278

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

    *ppmkComposite=0;
279

Noomen Hamza's avatar
Noomen Hamza committed
280 281 282 283 284 285 286 287 288
    if (fOnlyIfNotGeneric)
        return MK_E_NEEDGENERIC;
    else
        return CreateGenericComposite(iface,pmkRight,ppmkComposite);
}

/******************************************************************************
 *        AntiMoniker_Enum
 ******************************************************************************/
289 290
static HRESULT WINAPI
AntiMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
291
{
292
    TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
293 294 295

    if (ppenumMoniker == NULL)
        return E_POINTER;
296

Noomen Hamza's avatar
Noomen Hamza committed
297 298 299 300 301 302 303 304
    *ppenumMoniker = NULL;

    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsEqual
 ******************************************************************************/
305 306
static HRESULT WINAPI
AntiMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
307 308
{
    DWORD mkSys;
309

310
    TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
311 312 313

    if (pmkOtherMoniker==NULL)
        return S_FALSE;
314

Noomen Hamza's avatar
Noomen Hamza committed
315 316 317 318 319 320 321 322 323 324 325
    IMoniker_IsSystemMoniker(pmkOtherMoniker,&mkSys);

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

/******************************************************************************
 *        AntiMoniker_Hash
 ******************************************************************************/
326
static HRESULT WINAPI AntiMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
Noomen Hamza's avatar
Noomen Hamza committed
327 328 329 330
{
    if (pdwHash==NULL)
        return E_POINTER;

331
    *pdwHash = 0x80000001;
Noomen Hamza's avatar
Noomen Hamza committed
332 333 334 335 336 337 338

    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_IsRunning
 ******************************************************************************/
339 340 341
static HRESULT WINAPI
AntiMonikerImpl_IsRunning(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft,
                          IMoniker* pmkNewlyRunning)
Noomen Hamza's avatar
Noomen Hamza committed
342 343 344 345
{
    IRunningObjectTable* rot;
    HRESULT res;

346
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
Noomen Hamza's avatar
Noomen Hamza committed
347 348 349 350 351 352 353

    if (pbc==NULL)
        return E_INVALIDARG;

    res=IBindCtx_GetRunningObjectTable(pbc,&rot);

    if (FAILED(res))
354
        return res;
Noomen Hamza's avatar
Noomen Hamza committed
355 356 357 358 359 360 361 362 363 364 365

    res = IRunningObjectTable_IsRunning(rot,iface);

    IRunningObjectTable_Release(rot);

    return res;
}

/******************************************************************************
 *        AntiMoniker_GetTimeOfLastChange
 ******************************************************************************/
366
static HRESULT WINAPI AntiMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
Noomen Hamza's avatar
Noomen Hamza committed
367 368 369 370
                                                   IBindCtx* pbc,
                                                   IMoniker* pmkToLeft,
                                                   FILETIME* pAntiTime)
{
371
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pAntiTime);
Noomen Hamza's avatar
Noomen Hamza committed
372 373 374 375 376 377
    return E_NOTIMPL;
}

/******************************************************************************
 *        AntiMoniker_Inverse
 ******************************************************************************/
378 379
static HRESULT WINAPI
AntiMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
Noomen Hamza's avatar
Noomen Hamza committed
380
{
381
    TRACE("(%p,%p)\n",iface,ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
382 383 384 385 386 387 388 389 390 391 392 393

    if (ppmk==NULL)
        return E_POINTER;

    *ppmk=0;

    return MK_E_NOINVERSE;
}

/******************************************************************************
 *        AntiMoniker_CommonPrefixWith
 ******************************************************************************/
394 395
static HRESULT WINAPI
AntiMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
Noomen Hamza's avatar
Noomen Hamza committed
396 397
{
    DWORD mkSys;
398

Noomen Hamza's avatar
Noomen Hamza committed
399 400
    IMoniker_IsSystemMoniker(pmkOther,&mkSys);

401
    if(mkSys==MKSYS_ANTIMONIKER){
Noomen Hamza's avatar
Noomen Hamza committed
402 403 404 405 406 407

        IMoniker_AddRef(iface);

        *ppmkPrefix=iface;

        IMoniker_AddRef(iface);
408

Noomen Hamza's avatar
Noomen Hamza committed
409 410 411 412 413 414 415 416 417
        return MK_S_US;
    }
    else
        return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
}

/******************************************************************************
 *        AntiMoniker_RelativePathTo
 ******************************************************************************/
418 419
static HRESULT WINAPI
AntiMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
Noomen Hamza's avatar
Noomen Hamza committed
420
{
421
    TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
Noomen Hamza's avatar
Noomen Hamza committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435

    if (ppmkRelPath==NULL)
        return E_POINTER;

    IMoniker_AddRef(pmOther);

    *ppmkRelPath=pmOther;

    return MK_S_HIM;
}

/******************************************************************************
 *        AntiMoniker_GetDisplayName
 ******************************************************************************/
436 437 438
static HRESULT WINAPI
AntiMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc,
                               IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName)
Noomen Hamza's avatar
Noomen Hamza committed
439
{
440
    static const WCHAR back[]={'\\','.','.',0};
441

442
    TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
Noomen Hamza's avatar
Noomen Hamza committed
443 444 445 446 447

    if (ppszDisplayName==NULL)
        return E_POINTER;

    if (pmkToLeft!=NULL){
448
        FIXME("() pmkToLeft!=NULL not implemented\n");
Noomen Hamza's avatar
Noomen Hamza committed
449 450 451 452 453 454 455 456
        return E_NOTIMPL;
    }

    *ppszDisplayName=CoTaskMemAlloc(sizeof(back));

    if (*ppszDisplayName==NULL)
        return E_OUTOFMEMORY;

457
    lstrcpyW(*ppszDisplayName,back);
458

Noomen Hamza's avatar
Noomen Hamza committed
459 460 461 462 463 464
    return S_OK;
}

/******************************************************************************
 *        AntiMoniker_ParseDisplayName
 ******************************************************************************/
465 466 467 468
static HRESULT WINAPI
AntiMonikerImpl_ParseDisplayName(IMoniker* iface, IBindCtx* pbc,
                                 IMoniker* pmkToLeft, LPOLESTR pszDisplayName,
                                 ULONG* pchEaten, IMoniker** ppmkOut)
Noomen Hamza's avatar
Noomen Hamza committed
469
{
470
    TRACE("(%p,%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
Noomen Hamza's avatar
Noomen Hamza committed
471 472 473 474
    return E_NOTIMPL;
}

/******************************************************************************
Andreas Mohr's avatar
Andreas Mohr committed
475
 *        AntiMoniker_IsSystemMoniker
Noomen Hamza's avatar
Noomen Hamza committed
476
 ******************************************************************************/
477 478
static HRESULT WINAPI
AntiMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
Noomen Hamza's avatar
Noomen Hamza committed
479
{
480
    TRACE("(%p,%p)\n",iface,pwdMksys);
Noomen Hamza's avatar
Noomen Hamza committed
481 482 483

    if (!pwdMksys)
        return E_POINTER;
484

Noomen Hamza's avatar
Noomen Hamza committed
485 486 487 488 489 490 491 492
    (*pwdMksys)=MKSYS_ANTIMONIKER;

    return S_OK;
}

/*******************************************************************************
 *        AntiMonikerIROTData_QueryInterface
 *******************************************************************************/
493 494
static HRESULT WINAPI
AntiMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
495
{
496
    AntiMonikerImpl *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
497

498
    TRACE("(%p,%s,%p)\n",iface,debugstr_guid(riid),ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
499

500
    return AntiMonikerImpl_QueryInterface(&This->IMoniker_iface, riid, ppvObject);
Noomen Hamza's avatar
Noomen Hamza committed
501 502 503 504 505
}

/***********************************************************************
 *        AntiMonikerIROTData_AddRef
 */
506
static ULONG WINAPI AntiMonikerROTDataImpl_AddRef(IROTData *iface)
Noomen Hamza's avatar
Noomen Hamza committed
507
{
508
    AntiMonikerImpl *This = impl_from_IROTData(iface);
Noomen Hamza's avatar
Noomen Hamza committed
509

510
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
511

512
    return AntiMonikerImpl_AddRef(&This->IMoniker_iface);
Noomen Hamza's avatar
Noomen Hamza committed
513 514 515 516 517
}

/***********************************************************************
 *        AntiMonikerIROTData_Release
 */
518
static ULONG WINAPI AntiMonikerROTDataImpl_Release(IROTData* iface)
Noomen Hamza's avatar
Noomen Hamza committed
519
{
520
    AntiMonikerImpl *This = impl_from_IROTData(iface);
521

522
    TRACE("(%p)\n",iface);
Noomen Hamza's avatar
Noomen Hamza committed
523

524
    return AntiMonikerImpl_Release(&This->IMoniker_iface);
Noomen Hamza's avatar
Noomen Hamza committed
525 526 527
}

/******************************************************************************
528
 *        AntiMonikerIROTData_GetComparisonData
Noomen Hamza's avatar
Noomen Hamza committed
529
 ******************************************************************************/
530
static HRESULT WINAPI
531
AntiMonikerROTDataImpl_GetComparisonData(IROTData* iface, BYTE* pbData,
532
                                          ULONG cbMax, ULONG* pcbData)
Noomen Hamza's avatar
Noomen Hamza committed
533
{
534 535
    DWORD constant = 1;

536
    TRACE("(%p, %u, %p)\n", pbData, cbMax, pcbData);
537 538 539 540 541 542 543 544 545

    *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
546 547
}

548 549 550
/********************************************************************************/
/* Virtual function table for the AntiMonikerImpl class which  include IPersist,*/
/* IPersistStream and IMoniker functions.                                       */
551
static const IMonikerVtbl VT_AntiMonikerImpl =
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
{
    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.                               */
580
static const IROTDataVtbl VT_ROTDataImpl =
581 582 583 584
{
    AntiMonikerROTDataImpl_QueryInterface,
    AntiMonikerROTDataImpl_AddRef,
    AntiMonikerROTDataImpl_Release,
585
    AntiMonikerROTDataImpl_GetComparisonData
586 587 588 589 590 591 592 593 594 595
};

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

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

Austin English's avatar
Austin English committed
596
    /* Initialize the virtual function table. */
597 598
    This->IMoniker_iface.lpVtbl = &VT_AntiMonikerImpl;
    This->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
599
    This->ref          = 0;
600
    This->pMarshal     = NULL;
601 602 603 604

    return S_OK;
}

Noomen Hamza's avatar
Noomen Hamza committed
605
/******************************************************************************
606
 *        CreateAntiMoniker	[OLE32.@]
Noomen Hamza's avatar
Noomen Hamza committed
607
 ******************************************************************************/
608
HRESULT WINAPI CreateAntiMoniker(IMoniker **ppmk)
Noomen Hamza's avatar
Noomen Hamza committed
609
{
610 611
    AntiMonikerImpl* newAntiMoniker;
    HRESULT hr;
612

613
    TRACE("(%p)\n",ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
614 615 616 617 618 619 620

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

    if (newAntiMoniker == 0)
        return STG_E_INSUFFICIENTMEMORY;

    hr = AntiMonikerImpl_Construct(newAntiMoniker);
621 622
    if (FAILED(hr))
    {
Noomen Hamza's avatar
Noomen Hamza committed
623 624 625 626
        HeapFree(GetProcessHeap(),0,newAntiMoniker);
        return hr;
    }

627 628
    return AntiMonikerImpl_QueryInterface(&newAntiMoniker->IMoniker_iface, &IID_IMoniker,
            (void**)ppmk);
Noomen Hamza's avatar
Noomen Hamza committed
629
}
630

631 632
HRESULT WINAPI AntiMoniker_CreateInstance(IClassFactory *iface,
    IUnknown *pUnk, REFIID riid, void **ppv)
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
{
    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;

648
    hr = IMoniker_QueryInterface(pMoniker, riid, ppv);
649 650 651 652 653 654

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

    return hr;
}