moniker.c 33.5 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 *	Monikers
 *
 *	Copyright 1998	Marcus Meissner
5
 *      Copyright 1999  Noomen Hamza
6
 *      Copyright 2005  Robert Shearman (for CodeWeavers)
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 22 23 24 25
 *
 * TODO:
 * - IRunningObjectTable should work interprocess, but currently doesn't.
 *   Native (on Win2k at least) uses an undocumented RPC interface, IROT, to
 *   communicate with RPCSS which contains the table of marshalled data.
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28
 */

#include <assert.h>
29
#include <stdarg.h>
30
#include <string.h>
31

32 33
#define COBJMACROS

Alexandre Julliard's avatar
Alexandre Julliard committed
34
#include "winerror.h"
35
#include "windef.h"
36
#include "winbase.h"
37
#include "winuser.h"
38
#include "wtypes.h"
Patrik Stridvall's avatar
Patrik Stridvall committed
39
#include "ole2.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
40

41 42 43
#include "wine/list.h"
#include "wine/debug.h"

44 45
#include "compobj_private.h"

46
WINE_DEFAULT_DEBUG_CHANNEL(ole);
47

Noomen Hamza's avatar
Noomen Hamza committed
48
/* define the structure of the running object table elements */
49 50 51 52 53 54 55 56 57
struct rot_entry
{
    struct list        entry;
    MInterfacePointer* object; /* marshaled running object*/
    MInterfacePointer* moniker; /* marshaled moniker that identifies this object */
    MInterfacePointer* moniker_data; /* moniker comparison data that identifies this object */
    DWORD              cookie; /* cookie identifying this object */
    FILETIME           last_modified;
};
Noomen Hamza's avatar
Noomen Hamza committed
58

59
/* define the RunningObjectTableImpl structure */
60 61 62
typedef struct RunningObjectTableImpl
{
    const IRunningObjectTableVtbl *lpVtbl;
63
    LONG ref;
64

65 66
    struct list rot; /* list of ROT entries */
    CRITICAL_SECTION lock;
Noomen Hamza's avatar
Noomen Hamza committed
67 68
} RunningObjectTableImpl;

69
static RunningObjectTableImpl* runningObjectTableInstance = NULL;
Noomen Hamza's avatar
Noomen Hamza committed
70 71


72

73 74 75
static inline HRESULT WINAPI
IrotRegister(DWORD *cookie)
{
76
    static LONG last_cookie = 1;
77 78 79
    *cookie = InterlockedIncrement(&last_cookie);
    return S_OK;
}
80

81 82 83 84
/* define the EnumMonikerImpl structure */
typedef struct EnumMonikerImpl
{
    const IEnumMonikerVtbl *lpVtbl;
85
    LONG ref;
86

87 88 89
    MInterfacePointer **monikers;
    ULONG moniker_count;
    ULONG pos;
90 91 92 93
} EnumMonikerImpl;


/* IEnumMoniker Local functions*/
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(MInterfacePointer **monikers,
    ULONG moniker_count, ULONG pos, IEnumMoniker **ppenumMoniker);

static HRESULT create_stream_on_mip_ro(const MInterfacePointer *mip, IStream **stream)
{
    HGLOBAL hglobal = GlobalAlloc(0, mip->ulCntData);
    void *pv = GlobalLock(hglobal);
    memcpy(pv, mip->abData, mip->ulCntData);
    GlobalUnlock(hglobal);
    return CreateStreamOnHGlobal(hglobal, TRUE, stream);
}

static inline void rot_entry_delete(struct rot_entry *rot_entry)
{
    /* FIXME: revoke entry from rpcss's copy of the ROT */
    if (rot_entry->object)
    {
        IStream *stream;
        HRESULT hr;
        hr = create_stream_on_mip_ro(rot_entry->object, &stream);
        if (hr == S_OK)
        {
            CoReleaseMarshalData(stream);
            IUnknown_Release(stream);
        }
    }
    if (rot_entry->moniker)
    {
        IStream *stream;
        HRESULT hr;
        hr = create_stream_on_mip_ro(rot_entry->moniker, &stream);
        if (hr == S_OK)
        {
            CoReleaseMarshalData(stream);
            IUnknown_Release(stream);
        }
    }
    HeapFree(GetProcessHeap(), 0, rot_entry->object);
    HeapFree(GetProcessHeap(), 0, rot_entry->moniker);
    HeapFree(GetProcessHeap(), 0, rot_entry->moniker_data);
    HeapFree(GetProcessHeap(), 0, rot_entry);
}

/* moniker_data must be freed with HeapFree when no longer in use */
static HRESULT get_moniker_comparison_data(IMoniker *pMoniker, MInterfacePointer **moniker_data)
{
    HRESULT hr;
    IROTData *pROTData = NULL;
    ULONG size = 0;
    hr = IMoniker_QueryInterface(pMoniker, &IID_IROTData, (void *)&pROTData);
    if (hr != S_OK)
    {
        ERR("Failed to query moniker for IROTData interface, hr = 0x%08lx\n", hr);
        return hr;
    }
    IROTData_GetComparisonData(pROTData, NULL, 0, &size);
    *moniker_data = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MInterfacePointer, abData[size]));
    (*moniker_data)->ulCntData = size;
    hr = IROTData_GetComparisonData(pROTData, (*moniker_data)->abData, size, &size);
    if (hr != S_OK)
    {
        ERR("Failed to copy comparison data into buffer, hr = 0x%08lx\n", hr);
        HeapFree(GetProcessHeap(), 0, *moniker_data);
        return hr;
    }
    return S_OK;
}

Noomen Hamza's avatar
Noomen Hamza committed
162 163
/***********************************************************************
 *        RunningObjectTable_QueryInterface
Alexandre Julliard's avatar
Alexandre Julliard committed
164
 */
165 166 167
static HRESULT WINAPI
RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,
                                      REFIID riid,void** ppvObject)
Noomen Hamza's avatar
Noomen Hamza committed
168
{
169
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
170

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

173
    /* validate arguments */
Noomen Hamza's avatar
Noomen Hamza committed
174 175 176 177 178 179

    if (ppvObject==0)
        return E_INVALIDARG;

    *ppvObject = 0;

180 181
    if (IsEqualIID(&IID_IUnknown, riid) ||
        IsEqualIID(&IID_IRunningObjectTable, riid))
Noomen Hamza's avatar
Noomen Hamza committed
182 183 184 185 186
        *ppvObject = (IRunningObjectTable*)This;

    if ((*ppvObject)==0)
        return E_NOINTERFACE;

187
    IRunningObjectTable_AddRef(iface);
Noomen Hamza's avatar
Noomen Hamza committed
188 189 190 191 192 193 194

    return S_OK;
}

/***********************************************************************
 *        RunningObjectTable_AddRef
 */
195 196
static ULONG WINAPI
RunningObjectTableImpl_AddRef(IRunningObjectTable* iface)
Noomen Hamza's avatar
Noomen Hamza committed
197
{
198
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
Noomen Hamza's avatar
Noomen Hamza committed
199

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

202
    return InterlockedIncrement(&This->ref);
Noomen Hamza's avatar
Noomen Hamza committed
203 204 205 206 207
}

/***********************************************************************
 *        RunningObjectTable_Initialize
 */
208 209
static HRESULT WINAPI
RunningObjectTableImpl_Destroy(void)
Noomen Hamza's avatar
Noomen Hamza committed
210
{
211 212
    struct list *cursor, *cursor2;

213
    TRACE("()\n");
214

Noomen Hamza's avatar
Noomen Hamza committed
215 216 217 218
    if (runningObjectTableInstance==NULL)
        return E_INVALIDARG;

    /* free the ROT table memory */
219 220 221 222 223 224
    LIST_FOR_EACH_SAFE(cursor, cursor2, &runningObjectTableInstance->rot)
    {
        struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
        list_remove(&rot_entry->entry);
        rot_entry_delete(rot_entry);
    }
Noomen Hamza's avatar
Noomen Hamza committed
225 226 227

    /* free the ROT structure memory */
    HeapFree(GetProcessHeap(),0,runningObjectTableInstance);
228
    runningObjectTableInstance = NULL;
Noomen Hamza's avatar
Noomen Hamza committed
229 230 231 232 233 234 235

    return S_OK;
}

/***********************************************************************
 *        RunningObjectTable_Release
 */
236 237
static ULONG WINAPI
RunningObjectTableImpl_Release(IRunningObjectTable* iface)
Noomen Hamza's avatar
Noomen Hamza committed
238
{
239
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
240
    ULONG ref;
Noomen Hamza's avatar
Noomen Hamza committed
241

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

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

246 247 248 249 250
    /* uninitialize ROT structure if there's no more references to it */
    if (ref == 0)
    {
        struct list *cursor, *cursor2;
        LIST_FOR_EACH_SAFE(cursor, cursor2, &This->rot)
Noomen Hamza's avatar
Noomen Hamza committed
251
        {
252 253 254
            struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
            list_remove(&rot_entry->entry);
            rot_entry_delete(rot_entry);
Noomen Hamza's avatar
Noomen Hamza committed
255
        }
256 257 258
        /*  RunningObjectTable data structure will be not destroyed here ! the destruction will be done only
         *  when RunningObjectTableImpl_UnInitialize function is called
         */
Noomen Hamza's avatar
Noomen Hamza committed
259 260
    }

261
    return ref;
Noomen Hamza's avatar
Noomen Hamza committed
262 263 264 265
}

/***********************************************************************
 *        RunningObjectTable_Register
266 267 268 269 270 271
 *
 * PARAMS
 * grfFlags       [in] Registration options 
 * punkObject     [in] the object being registered
 * pmkObjectName  [in] the moniker of the object being registered
 * pdwRegister    [in] the value identifying the registration
Noomen Hamza's avatar
Noomen Hamza committed
272
 */
273 274 275
static HRESULT WINAPI
RunningObjectTableImpl_Register(IRunningObjectTable* iface, DWORD grfFlags,
               IUnknown *punkObject, IMoniker *pmkObjectName, DWORD *pdwRegister)
Noomen Hamza's avatar
Noomen Hamza committed
276
{
277
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
278 279 280 281
    struct rot_entry *rot_entry;
    HRESULT hr = S_OK;
    IStream *pStream = NULL;
    DWORD mshlflags;
Noomen Hamza's avatar
Noomen Hamza committed
282

283
    TRACE("(%p,%ld,%p,%p,%p)\n",This,grfFlags,punkObject,pmkObjectName,pdwRegister);
Noomen Hamza's avatar
Noomen Hamza committed
284

285 286 287 288
    /*
     * there's only two types of register : strong and or weak registration
     * (only one must be passed on parameter)
     */
Noomen Hamza's avatar
Noomen Hamza committed
289 290 291
    if ( ( (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || !(grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
         (!(grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) ||  (grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
         (grfFlags) )
292 293
    {
        ERR("Invalid combination of ROTFLAGS: %lx\n", grfFlags);
Noomen Hamza's avatar
Noomen Hamza committed
294
        return E_INVALIDARG;
295
    }
Noomen Hamza's avatar
Noomen Hamza committed
296 297 298 299

    if (punkObject==NULL || pmkObjectName==NULL || pdwRegister==NULL)
        return E_INVALIDARG;

300 301 302
    rot_entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rot_entry));
    if (!rot_entry)
        return E_OUTOFMEMORY;
Noomen Hamza's avatar
Noomen Hamza committed
303

304
    CoFileTimeNow(&rot_entry->last_modified);
Noomen Hamza's avatar
Noomen Hamza committed
305

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    /* marshal object */
    hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
    }
    mshlflags = (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) ? MSHLFLAGS_TABLESTRONG : MSHLFLAGS_TABLEWEAK;
    hr = CoMarshalInterface(pStream, &IID_IUnknown, punkObject, MSHCTX_LOCAL | MSHCTX_NOSHAREDMEM, NULL, mshlflags);
    /* FIXME: a cleaner way would be to create an IStream class that writes
     * directly to an MInterfacePointer */
    if (hr == S_OK)
    {
        HGLOBAL hglobal;
        hr = GetHGlobalFromStream(pStream, &hglobal);
        if (hr == S_OK)
        {
            SIZE_T size = GlobalSize(hglobal);
            const void *pv = GlobalLock(hglobal);
            rot_entry->object = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MInterfacePointer, abData[size]));
            rot_entry->object->ulCntData = size;
            memcpy(&rot_entry->object->abData, pv, size);
            GlobalUnlock(hglobal);
        }
    }
    IStream_Release(pStream);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
336
    }
337

338 339 340 341 342 343
    hr = get_moniker_comparison_data(pmkObjectName, &rot_entry->moniker_data);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
    }
Noomen Hamza's avatar
Noomen Hamza committed
344

345 346 347 348 349
    hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
Noomen Hamza's avatar
Noomen Hamza committed
350
    }
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    /* marshal moniker */
    hr = CoMarshalInterface(pStream, &IID_IMoniker, (IUnknown *)pmkObjectName, MSHCTX_LOCAL | MSHCTX_NOSHAREDMEM, NULL, MSHLFLAGS_TABLESTRONG);
    /* FIXME: a cleaner way would be to create an IStream class that writes
     * directly to an MInterfacePointer */
    if (hr == S_OK)
    {
        HGLOBAL hglobal;
        hr = GetHGlobalFromStream(pStream, &hglobal);
        if (hr == S_OK)
        {
            SIZE_T size = GlobalSize(hglobal);
            const void *pv = GlobalLock(hglobal);
            rot_entry->moniker = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MInterfacePointer, abData[size]));
            rot_entry->moniker->ulCntData = size;
            memcpy(&rot_entry->moniker->abData, pv, size);
            GlobalUnlock(hglobal);
        }
    }
    IStream_Release(pStream);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
374
    }
375

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
    /* FIXME: not the right signature of IrotRegister function */
    hr = IrotRegister(&rot_entry->cookie);
    if (hr != S_OK)
    {
        rot_entry_delete(rot_entry);
        return hr;
    }

    /* gives a registration identifier to the registered object*/
    *pdwRegister = rot_entry->cookie;

    EnterCriticalSection(&This->lock);
    /* FIXME: see if object was registered before and return MK_S_MONIKERALREADYREGISTERED */
    list_add_tail(&This->rot, &rot_entry->entry);
    LeaveCriticalSection(&This->lock);

    return hr;
Noomen Hamza's avatar
Noomen Hamza committed
393 394 395 396
}

/***********************************************************************
 *        RunningObjectTable_Revoke
397 398 399
 *
 * PARAMS
 *  dwRegister [in] Value identifying registration to be revoked
Noomen Hamza's avatar
Noomen Hamza committed
400
 */
401 402
static HRESULT WINAPI
RunningObjectTableImpl_Revoke( IRunningObjectTable* iface, DWORD dwRegister) 
Noomen Hamza's avatar
Noomen Hamza committed
403
{
404
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
405
    struct rot_entry *rot_entry;
Noomen Hamza's avatar
Noomen Hamza committed
406

407
    TRACE("(%p,%ld)\n",This,dwRegister);
Noomen Hamza's avatar
Noomen Hamza committed
408

409 410 411 412 413 414 415
    EnterCriticalSection(&This->lock);
    LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
    {
        if (rot_entry->cookie == dwRegister)
        {
            list_remove(&rot_entry->entry);
            LeaveCriticalSection(&This->lock);
Noomen Hamza's avatar
Noomen Hamza committed
416

417 418 419
            rot_entry_delete(rot_entry);
            return S_OK;
        }
420
    }
421
    LeaveCriticalSection(&This->lock);
422

423
    return E_INVALIDARG;
Noomen Hamza's avatar
Noomen Hamza committed
424
}
425

Noomen Hamza's avatar
Noomen Hamza committed
426 427
/***********************************************************************
 *        RunningObjectTable_IsRunning
428 429 430
 *
 * PARAMS
 *  pmkObjectName [in]  moniker of the object whose status is desired 
Noomen Hamza's avatar
Noomen Hamza committed
431
 */
432 433
static HRESULT WINAPI
RunningObjectTableImpl_IsRunning( IRunningObjectTable* iface, IMoniker *pmkObjectName)
434
{
435
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
436 437 438
    MInterfacePointer *moniker_data;
    HRESULT hr;
    struct rot_entry *rot_entry;
Noomen Hamza's avatar
Noomen Hamza committed
439

440
    TRACE("(%p,%p)\n",This,pmkObjectName);
Noomen Hamza's avatar
Noomen Hamza committed
441

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
    hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
    if (hr != S_OK)
        return hr;

    hr = S_FALSE;
    EnterCriticalSection(&This->lock);
    LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
    {
        if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
            !memcmp(moniker_data, rot_entry->moniker_data, moniker_data->ulCntData))
        {
            hr = S_OK;
            break;
        }
    }
    LeaveCriticalSection(&This->lock);

    /* FIXME: call IrotIsRunning */

    HeapFree(GetProcessHeap(), 0, moniker_data);

    return hr;
Noomen Hamza's avatar
Noomen Hamza committed
464 465 466 467
}

/***********************************************************************
 *        RunningObjectTable_GetObject
468 469 470 471
 *
 * PARAMS
 * pmkObjectName [in] Pointer to the moniker on the object 
 * ppunkObject   [out] variable that receives the IUnknown interface pointer
Noomen Hamza's avatar
Noomen Hamza committed
472
 */
473 474 475
static HRESULT WINAPI
RunningObjectTableImpl_GetObject( IRunningObjectTable* iface,
                     IMoniker *pmkObjectName, IUnknown **ppunkObject)
Noomen Hamza's avatar
Noomen Hamza committed
476
{
477
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
478 479 480
    MInterfacePointer *moniker_data;
    HRESULT hr;
    struct rot_entry *rot_entry;
Noomen Hamza's avatar
Noomen Hamza committed
481

482
    TRACE("(%p,%p,%p)\n",This,pmkObjectName,ppunkObject);
Noomen Hamza's avatar
Noomen Hamza committed
483

484
    if (ppunkObject == NULL)
Noomen Hamza's avatar
Noomen Hamza committed
485
        return E_POINTER;
486

487
    *ppunkObject = NULL;
Noomen Hamza's avatar
Noomen Hamza committed
488

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
    if (hr != S_OK)
        return hr;

    EnterCriticalSection(&This->lock);
    LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
    {
        if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
            !memcmp(moniker_data, rot_entry->moniker_data, moniker_data->ulCntData))
        {
            IStream *pStream;
            hr = create_stream_on_mip_ro(rot_entry->object, &pStream);
            if (hr == S_OK)
            {
                hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)ppunkObject);
                IStream_Release(pStream);
            }

            LeaveCriticalSection(&This->lock);
            HeapFree(GetProcessHeap(), 0, moniker_data);

            return hr;
        }
512
    }
513
    LeaveCriticalSection(&This->lock);
Noomen Hamza's avatar
Noomen Hamza committed
514

515 516 517
    /* FIXME: call IrotGetObject */
    WARN("Moniker unavailable - app may require interprocess running object table\n");
    hr = MK_E_UNAVAILABLE;
Noomen Hamza's avatar
Noomen Hamza committed
518

519 520 521
    HeapFree(GetProcessHeap(), 0, moniker_data);

    return hr;
Noomen Hamza's avatar
Noomen Hamza committed
522
}
523

524
/***********************************************************************
Noomen Hamza's avatar
Noomen Hamza committed
525
 *        RunningObjectTable_NoteChangeTime
526 527 528 529
 *
 * PARAMS
 *  dwRegister [in] Value identifying registration being updated
 *  pfiletime  [in] Pointer to structure containing object's last change time
530
 */
531 532 533
static HRESULT WINAPI
RunningObjectTableImpl_NoteChangeTime(IRunningObjectTable* iface,
                                      DWORD dwRegister, FILETIME *pfiletime)
Noomen Hamza's avatar
Noomen Hamza committed
534
{
535
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
536
    struct rot_entry *rot_entry;
Noomen Hamza's avatar
Noomen Hamza committed
537

538
    TRACE("(%p,%ld,%p)\n",This,dwRegister,pfiletime);
Noomen Hamza's avatar
Noomen Hamza committed
539

540 541 542 543 544 545 546 547 548 549 550
    EnterCriticalSection(&This->lock);
    LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
    {
        if (rot_entry->cookie == dwRegister)
        {
            rot_entry->last_modified = *pfiletime;
            LeaveCriticalSection(&This->lock);
            return S_OK;
        }
    }
    LeaveCriticalSection(&This->lock);
Noomen Hamza's avatar
Noomen Hamza committed
551

552
    /* FIXME: call IrotNoteChangeTime */
Noomen Hamza's avatar
Noomen Hamza committed
553

554
    return E_INVALIDARG;
Noomen Hamza's avatar
Noomen Hamza committed
555
}
556

Noomen Hamza's avatar
Noomen Hamza committed
557 558
/***********************************************************************
 *        RunningObjectTable_GetTimeOfLastChange
559 560 561 562
 *
 * PARAMS
 *  pmkObjectName  [in]  moniker of the object whose status is desired 
 *  pfiletime      [out] structure that receives object's last change time
Noomen Hamza's avatar
Noomen Hamza committed
563
 */
564 565 566
static HRESULT WINAPI
RunningObjectTableImpl_GetTimeOfLastChange(IRunningObjectTable* iface,
                            IMoniker *pmkObjectName, FILETIME *pfiletime)
Noomen Hamza's avatar
Noomen Hamza committed
567
{
568
    HRESULT hr = MK_E_UNAVAILABLE;
569
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
570 571
    MInterfacePointer *moniker_data;
    struct rot_entry *rot_entry;
Noomen Hamza's avatar
Noomen Hamza committed
572

573
    TRACE("(%p,%p,%p)\n",This,pmkObjectName,pfiletime);
Noomen Hamza's avatar
Noomen Hamza committed
574 575 576 577

    if (pmkObjectName==NULL || pfiletime==NULL)
        return E_INVALIDARG;

578 579 580
    hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
    if (hr != S_OK)
        return hr;
Noomen Hamza's avatar
Noomen Hamza committed
581

582
    hr = MK_E_UNAVAILABLE;
Noomen Hamza's avatar
Noomen Hamza committed
583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
    EnterCriticalSection(&This->lock);
    LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
    {
        if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
            !memcmp(moniker_data, rot_entry->moniker_data, moniker_data->ulCntData))
        {
            *pfiletime = rot_entry->last_modified;
            hr = S_OK;
            break;
        }
    }
    LeaveCriticalSection(&This->lock);

    /* FIXME: if (hr != S_OK) call IrotGetTimeOfLastChange */

    HeapFree(GetProcessHeap(), 0, moniker_data);
    return hr;
Noomen Hamza's avatar
Noomen Hamza committed
601 602 603 604
}

/***********************************************************************
 *        RunningObjectTable_EnumRunning
605 606 607
 *
 * PARAMS
 *  ppenumMoniker  [out]  receives the IEnumMoniker interface pointer 
Noomen Hamza's avatar
Noomen Hamza committed
608
 */
609 610 611
static HRESULT WINAPI
RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface,
                                   IEnumMoniker **ppenumMoniker)
Noomen Hamza's avatar
Noomen Hamza committed
612
{
613
    HRESULT hr;
614
    RunningObjectTableImpl *This = (RunningObjectTableImpl *)iface;
615 616 617 618
    MInterfacePointer **monikers;
    ULONG moniker_count = 0;
    const struct rot_entry *rot_entry;
    ULONG i = 0;
619

620
    EnterCriticalSection(&This->lock);
Noomen Hamza's avatar
Noomen Hamza committed
621

622 623
    LIST_FOR_EACH_ENTRY( rot_entry, &This->rot, const struct rot_entry, entry )
        moniker_count++;
Noomen Hamza's avatar
Noomen Hamza committed
624

625
    monikers = HeapAlloc(GetProcessHeap(), 0, moniker_count * sizeof(*monikers));
Noomen Hamza's avatar
Noomen Hamza committed
626

627 628 629 630 631 632 633
    LIST_FOR_EACH_ENTRY( rot_entry, &This->rot, const struct rot_entry, entry )
    {
        SIZE_T size = FIELD_OFFSET(MInterfacePointer, abData[rot_entry->moniker->ulCntData]);
        monikers[i] = HeapAlloc(GetProcessHeap(), 0, size);
        memcpy(monikers[i], rot_entry->moniker, size);
        i++;
    }
634

635 636 637
    LeaveCriticalSection(&This->lock);
    
    /* FIXME: call IrotEnumRunning and append data */
Noomen Hamza's avatar
Noomen Hamza committed
638

639
    hr = EnumMonikerImpl_CreateEnumROTMoniker(monikers, moniker_count, 0, ppenumMoniker);
Noomen Hamza's avatar
Noomen Hamza committed
640

641
    return hr;
Noomen Hamza's avatar
Noomen Hamza committed
642 643 644
}

/***********************************************************************
645
 *           GetRunningObjectTable (OLE32.@)
Noomen Hamza's avatar
Noomen Hamza committed
646
 */
647 648
HRESULT WINAPI
GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
Noomen Hamza's avatar
Noomen Hamza committed
649 650 651 652
{
    IID riid=IID_IRunningObjectTable;
    HRESULT res;

653
    TRACE("()\n");
Noomen Hamza's avatar
Noomen Hamza committed
654 655 656 657 658 659 660

    if (reserved!=0)
        return E_UNEXPECTED;

    if(runningObjectTableInstance==NULL)
        return CO_E_NOTINITIALIZED;

661
    res = IRunningObjectTable_QueryInterface((IRunningObjectTable*)runningObjectTableInstance,&riid,(void**)pprot);
Noomen Hamza's avatar
Noomen Hamza committed
662 663

    return res;
664
}
Marcus Meissner's avatar
Marcus Meissner committed
665 666

/******************************************************************************
667
 *              OleRun        [OLE32.@]
Marcus Meissner's avatar
Marcus Meissner committed
668 669 670
 */
HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
{
671 672 673 674 675 676 677 678 679 680
    IRunnableObject *runable;
    IRunnableObject *This = (IRunnableObject *)pUnknown;
    LRESULT ret;

    ret = IRunnableObject_QueryInterface(This,&IID_IRunnableObject,(LPVOID*)&runable);
    if (ret)
        return 0; /* Appears to return no error. */
    ret = IRunnableObject_Run(runable,NULL);
    IRunnableObject_Release(runable);
    return ret;
Marcus Meissner's avatar
Marcus Meissner committed
681
}
682 683

/******************************************************************************
684
 *              MkParseDisplayName        [OLE32.@]
685
 */
686
HRESULT WINAPI MkParseDisplayName(LPBC pbc, LPCOLESTR szUserName,
687 688 689
				LPDWORD pchEaten, LPMONIKER *ppmk)
{
    FIXME("(%p, %s, %p, %p): stub.\n", pbc, debugstr_w(szUserName), pchEaten, *ppmk);
690

Patrik Stridvall's avatar
Patrik Stridvall committed
691
    if (!(IsValidInterface((LPUNKNOWN) pbc)))
692
        return E_INVALIDARG;
693 694 695

    return MK_E_SYNTAX;
}
696 697

/******************************************************************************
698
 *              CreateClassMoniker        [OLE32.@]
699
 */
700 701 702 703 704 705 706 707 708
HRESULT WINAPI CreateClassMoniker(REFCLSID rclsid, IMoniker ** ppmk)
{
    FIXME("%s\n", debugstr_guid( rclsid ));
    if( ppmk )
        *ppmk = NULL;
    return E_NOTIMPL;
}

/* Virtual function table for the IRunningObjectTable class. */
709
static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
{
    RunningObjectTableImpl_QueryInterface,
    RunningObjectTableImpl_AddRef,
    RunningObjectTableImpl_Release,
    RunningObjectTableImpl_Register,
    RunningObjectTableImpl_Revoke,
    RunningObjectTableImpl_IsRunning,
    RunningObjectTableImpl_GetObject,
    RunningObjectTableImpl_NoteChangeTime,
    RunningObjectTableImpl_GetTimeOfLastChange,
    RunningObjectTableImpl_EnumRunning
};

/***********************************************************************
 *        RunningObjectTable_Initialize
 */
HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
{
    TRACE("\n");

    /* create the unique instance of the RunningObjectTableImpl structure */
    runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));

733
    if (!runningObjectTableInstance)
734 735 736 737 738 739 740 741 742 743
        return E_OUTOFMEMORY;

    /* initialize the virtual table function */
    runningObjectTableInstance->lpVtbl = &VT_RunningObjectTableImpl;

    /* the initial reference is set to "1" ! because if set to "0" it will be not practis when */
    /* the ROT referred many times not in the same time (all the objects in the ROT will  */
    /* be removed every time the ROT is removed ) */
    runningObjectTableInstance->ref = 1;

744 745
    list_init(&runningObjectTableInstance->rot);
    InitializeCriticalSection(&runningObjectTableInstance->lock);
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765

    return S_OK;
}

/***********************************************************************
 *        RunningObjectTable_UnInitialize
 */
HRESULT WINAPI RunningObjectTableImpl_UnInitialize()
{
    TRACE("\n");

    if (runningObjectTableInstance==NULL)
        return E_POINTER;

    RunningObjectTableImpl_Release((IRunningObjectTable*)runningObjectTableInstance);

    RunningObjectTableImpl_Destroy();

    return S_OK;
}
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820

/***********************************************************************
 *        EnumMoniker_QueryInterface
 */
static HRESULT WINAPI EnumMonikerImpl_QueryInterface(IEnumMoniker* iface,REFIID riid,void** ppvObject)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;

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

    /* validate arguments */
    if (ppvObject == NULL)
        return E_INVALIDARG;

    *ppvObject = NULL;

    if (IsEqualIID(&IID_IUnknown, riid))
        *ppvObject = (IEnumMoniker*)This;
    else
        if (IsEqualIID(&IID_IEnumMoniker, riid))
            *ppvObject = (IEnumMoniker*)This;

    if ((*ppvObject)==NULL)
        return E_NOINTERFACE;

    IEnumMoniker_AddRef(iface);

    return S_OK;
}

/***********************************************************************
 *        EnumMoniker_AddRef
 */
static ULONG   WINAPI EnumMonikerImpl_AddRef(IEnumMoniker* iface)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;

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

    return InterlockedIncrement(&This->ref);
}

/***********************************************************************
 *        EnumMoniker_release
 */
static ULONG   WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
    ULONG ref;

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

    ref = InterlockedDecrement(&This->ref);

    /* unitialize rot structure if there's no more reference to it*/
821 822 823
    if (ref == 0)
    {
        ULONG i;
824

825
        TRACE("(%p) Deleting\n",This);
826

827 828 829 830
        for (i = 0; i < This->moniker_count; i++)
            HeapFree(GetProcessHeap(), 0, This->monikers[i]);
        HeapFree(GetProcessHeap(), 0, This->monikers);
        HeapFree(GetProcessHeap(), 0, This);
831 832 833 834 835 836 837 838 839 840 841
    }

    return ref;
}
/***********************************************************************
 *        EnmumMoniker_Next
 */
static HRESULT   WINAPI EnumMonikerImpl_Next(IEnumMoniker* iface, ULONG celt, IMoniker** rgelt, ULONG * pceltFetched)
{
    ULONG i;
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
842 843 844
    HRESULT hr = S_OK;

    TRACE("(%p) TabCurrentPos %ld Tablastindx %ld\n", This, This->pos, This->moniker_count);
845 846

    /* retrieve the requested number of moniker from the current position */
847 848 849 850 851 852 853 854 855
    for(i = 0; (This->pos < This->moniker_count) && (i < celt); i++)
    {
        IStream *stream;
        hr = create_stream_on_mip_ro(This->monikers[This->pos++], &stream);
        if (hr != S_OK) break;
        hr = CoUnmarshalInterface(stream, &IID_IMoniker, (void **)&rgelt[i]);
        IStream_Release(stream);
        if (hr != S_OK) break;
    }
856

857
    if (pceltFetched != NULL)
858 859
        *pceltFetched= i;

860 861 862 863
    if (hr != S_OK)
        return hr;

    if (i == celt)
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
        return S_OK;
    else
        return S_FALSE;

}

/***********************************************************************
 *        EnmumMoniker_Skip
 */
static HRESULT   WINAPI EnumMonikerImpl_Skip(IEnumMoniker* iface, ULONG celt)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;

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

879 880
    if  (This->pos + celt >= This->moniker_count)
        return S_FALSE;
881

882
    This->pos += celt;
883 884 885 886 887 888 889 890 891 892 893

    return S_OK;
}

/***********************************************************************
 *        EnmumMoniker_Reset
 */
static HRESULT   WINAPI EnumMonikerImpl_Reset(IEnumMoniker* iface)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;

894
    This->pos = 0;	/* set back to start of list */
895 896 897 898 899 900 901 902 903 904 905 906

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

    return S_OK;
}

/***********************************************************************
 *        EnmumMoniker_Clone
 */
static HRESULT   WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface, IEnumMoniker ** ppenum)
{
    EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
907 908
    MInterfacePointer **monikers = HeapAlloc(GetProcessHeap(), 0, sizeof(*monikers)*This->moniker_count);
    ULONG i;
909 910

    TRACE("(%p)\n",This);
911 912 913 914 915 916 917 918

    for (i = 0; i < This->moniker_count; i++)
    {
        SIZE_T size = FIELD_OFFSET(MInterfacePointer, abData[This->monikers[i]->ulCntData]);
        monikers[i] = HeapAlloc(GetProcessHeap(), 0, size);
        memcpy(monikers[i], This->monikers[i], size);
    }

919
    /* copy the enum structure */ 
920 921
    return EnumMonikerImpl_CreateEnumROTMoniker(monikers, This->moniker_count,
        This->pos, ppenum);
922 923 924
}

/* Virtual function table for the IEnumMoniker class. */
925
static const IEnumMonikerVtbl VT_EnumMonikerImpl =
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
{
    EnumMonikerImpl_QueryInterface,
    EnumMonikerImpl_AddRef,
    EnumMonikerImpl_Release,
    EnumMonikerImpl_Next,
    EnumMonikerImpl_Skip,
    EnumMonikerImpl_Reset,
    EnumMonikerImpl_Clone
};

/***********************************************************************
 *        EnumMonikerImpl_CreateEnumROTMoniker
 *        Used by EnumRunning to create the structure and EnumClone
 *	  to copy the structure
 */
941 942 943 944
static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(MInterfacePointer **monikers,
                                                 ULONG moniker_count,
                                                 ULONG current_pos,
                                                 IEnumMoniker **ppenumMoniker)
945 946 947
{
    EnumMonikerImpl* This = NULL;

948
    if (!ppenumMoniker)
949 950 951
        return E_INVALIDARG;

    This = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl));
952
    if (!This) return E_OUTOFMEMORY;
953 954 955 956 957 958 959 960

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

    /* initialize the virtual table function */
    This->lpVtbl = &VT_EnumMonikerImpl;

    /* the initial reference is set to "1" */
    This->ref = 1;			/* set the ref count to one         */
961
    This->pos = current_pos;		/* Set the list start posn */
962 963
    This->moniker_count = moniker_count; /* Need the same size table as ROT */
    This->monikers = monikers;
964 965 966 967 968

    *ppenumMoniker =  (IEnumMoniker*)This;

    return S_OK;
}
969 970 971 972 973 974 975 976 977 978


/* Shared implementation of moniker marshaler based on saving and loading of
 * monikers */

typedef struct MonikerMarshal
{
    const IUnknownVtbl *lpVtbl;
    const IMarshalVtbl *lpVtblMarshal;
    
979
    LONG ref;
980 981 982
    IMoniker *moniker;
} MonikerMarshal;

983 984 985 986 987
static inline MonikerMarshal *impl_from_IMarshal( IMarshal *iface )
{
    return (MonikerMarshal *)((char*)iface - FIELD_OFFSET(MonikerMarshal, lpVtblMarshal));
}

988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
static HRESULT WINAPI MonikerMarshalInner_QueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppv)
{
    MonikerMarshal *This = (MonikerMarshal *)iface;
    TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
    *ppv = NULL;
    if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IMarshal, riid))
    {
        *ppv = &This->lpVtblMarshal;
        IUnknown_AddRef((IUnknown *)&This->lpVtblMarshal);
        return S_OK;
    }
    FIXME("No interface for %s\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

static ULONG WINAPI MonikerMarshalInner_AddRef(IUnknown *iface)
{
    MonikerMarshal *This = (MonikerMarshal *)iface;
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI MonikerMarshalInner_Release(IUnknown *iface)
{
    MonikerMarshal *This = (MonikerMarshal *)iface;
    ULONG ref = InterlockedDecrement(&This->ref);

    if (!ref) HeapFree(GetProcessHeap(), 0, This);
    return ref;
}

static const IUnknownVtbl VT_MonikerMarshalInner =
{
    MonikerMarshalInner_QueryInterface,
    MonikerMarshalInner_AddRef,
    MonikerMarshalInner_Release
};

static HRESULT WINAPI MonikerMarshal_QueryInterface(IMarshal *iface, REFIID riid, LPVOID *ppv)
{
1027
    MonikerMarshal *This = impl_from_IMarshal(iface);
1028 1029 1030 1031 1032
    return IMoniker_QueryInterface(This->moniker, riid, ppv);
}

static ULONG WINAPI MonikerMarshal_AddRef(IMarshal *iface)
{
1033
    MonikerMarshal *This = impl_from_IMarshal(iface);
1034 1035 1036 1037 1038
    return IMoniker_AddRef(This->moniker);
}

static ULONG WINAPI MonikerMarshal_Release(IMarshal *iface)
{
1039
    MonikerMarshal *This = impl_from_IMarshal(iface);
1040 1041 1042 1043 1044 1045 1046
    return IMoniker_Release(This->moniker);
}

static HRESULT WINAPI MonikerMarshal_GetUnmarshalClass(
  LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
  void* pvDestContext, DWORD mshlflags, CLSID* pCid)
{
1047
    MonikerMarshal *This = impl_from_IMarshal(iface);
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058

    TRACE("(%s, %p, %lx, %p, %lx, %p)\n", debugstr_guid(riid), pv,
        dwDestContext, pvDestContext, mshlflags, pCid);

    return IMoniker_GetClassID(This->moniker, pCid);
}

static HRESULT WINAPI MonikerMarshal_GetMarshalSizeMax(
  LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
  void* pvDestContext, DWORD mshlflags, DWORD* pSize)
{
1059
    MonikerMarshal *This = impl_from_IMarshal(iface);
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
    HRESULT hr;
    ULARGE_INTEGER size;

    TRACE("(%s, %p, %lx, %p, %lx, %p)\n", debugstr_guid(riid), pv,
        dwDestContext, pvDestContext, mshlflags, pSize);

    hr = IMoniker_GetSizeMax(This->moniker, &size);
    if (hr == S_OK)
        *pSize = (DWORD)size.QuadPart;
    return hr;
}

static HRESULT WINAPI MonikerMarshal_MarshalInterface(LPMARSHAL iface, IStream *pStm, 
    REFIID riid, void* pv, DWORD dwDestContext,
    void* pvDestContext, DWORD mshlflags)
{
1076
    MonikerMarshal *This = impl_from_IMarshal(iface);
1077 1078 1079 1080 1081 1082 1083 1084 1085

    TRACE("(%p, %s, %p, %lx, %p, %lx)\n", pStm, debugstr_guid(riid), pv,
        dwDestContext, pvDestContext, mshlflags);

    return IMoniker_Save(This->moniker, pStm, FALSE);
}

static HRESULT WINAPI MonikerMarshal_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
{
1086
    MonikerMarshal *This = impl_from_IMarshal(iface);
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
    HRESULT hr;

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

    hr = IMoniker_Load(This->moniker, pStm);
    if (hr == S_OK)
        hr = IMoniker_QueryInterface(This->moniker, riid, ppv);
    return hr;
}

static HRESULT WINAPI MonikerMarshal_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
{
    TRACE("()\n");
    /* can't release a state-based marshal as nothing on server side to
     * release */
    return S_OK;
}

static HRESULT WINAPI MonikerMarshal_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
{
    TRACE("()\n");
    /* can't disconnect a state-based marshal as nothing on server side to
     * disconnect from */
    return S_OK;
}

static const IMarshalVtbl VT_MonikerMarshal =
{
    MonikerMarshal_QueryInterface,
    MonikerMarshal_AddRef,
    MonikerMarshal_Release,
    MonikerMarshal_GetUnmarshalClass,
    MonikerMarshal_GetMarshalSizeMax,
    MonikerMarshal_MarshalInterface,
    MonikerMarshal_UnmarshalInterface,
    MonikerMarshal_ReleaseMarshalData,
    MonikerMarshal_DisconnectObject
};

HRESULT MonikerMarshal_Create(IMoniker *inner, IUnknown **outer)
{
    MonikerMarshal *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
    if (!This) return E_OUTOFMEMORY;

    This->lpVtbl = &VT_MonikerMarshalInner;
    This->lpVtblMarshal = &VT_MonikerMarshal;
    This->ref = 1;
    This->moniker = inner;

    *outer = (IUnknown *)&This->lpVtbl;
    return S_OK;
}