msi: Load the folder property if available and requested.
[wine/multimedia.git] / dlls / ole32 / stubmanager.c
blobb7d6ba7f42fe79b2d28fb3c6bf27b82b7a53a18e
1 /*
2 * A stub manager is an object that controls interface stubs. It is
3 * identified by an OID (object identifier) and acts as the network
4 * identity of the object. There can be many stub managers in a
5 * process or apartment.
7 * Copyright 2002 Marcus Meissner
8 * Copyright 2004 Mike Hearn for CodeWeavers
9 * Copyright 2004 Robert Shearman (for CodeWeavers)
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include <assert.h>
31 #include <stdarg.h>
32 #include <limits.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winuser.h"
37 #include "objbase.h"
38 #include "rpc.h"
40 #include "wine/debug.h"
41 #include "compobj_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole);
45 static void stub_manager_delete_ifstub(struct stub_manager *m, struct ifstub *ifstub);
46 static struct ifstub *stub_manager_ipid_to_ifstub(struct stub_manager *m, const IPID *ipid);
48 /* creates a new stub manager and adds it into the apartment. caller must
49 * release stub manager when it is no longer required. the apartment and
50 * external refs together take one implicit ref */
51 struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object)
53 struct stub_manager *sm;
55 assert( apt );
57 sm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct stub_manager));
58 if (!sm) return NULL;
60 list_init(&sm->ifstubs);
62 InitializeCriticalSection(&sm->lock);
63 DEBUG_SET_CRITSEC_NAME(&sm->lock, "stub_manager");
65 IUnknown_AddRef(object);
66 sm->object = object;
67 sm->apt = apt;
69 /* start off with 2 references because the stub is in the apartment
70 * and the caller will also hold a reference */
71 sm->refs = 2;
73 sm->oxid_info.dwPid = GetCurrentProcessId();
74 sm->oxid_info.dwTid = GetCurrentThreadId();
76 * FIXME: this is a hack for marshalling IRemUnknown. In real
77 * DCOM, the IPID of the IRemUnknown interface is generated like
78 * any other and passed to the OXID resolver which then returns it
79 * when queried. We don't have an OXID resolver yet so instead we
80 * use a magic IPID reserved for IRemUnknown.
82 sm->oxid_info.ipidRemUnknown.Data1 = 0xffffffff;
83 sm->oxid_info.ipidRemUnknown.Data2 = 0xffff;
84 sm->oxid_info.ipidRemUnknown.Data3 = 0xffff;
85 assert(sizeof(sm->oxid_info.ipidRemUnknown.Data4) == sizeof(apt->oxid));
86 memcpy(&sm->oxid_info.ipidRemUnknown.Data4, &apt->oxid, sizeof(OXID));
87 sm->oxid_info.dwAuthnHint = RPC_C_AUTHN_LEVEL_NONE;
88 sm->oxid_info.psa = NULL /* FIXME */;
90 /* yes, that's right, this starts at zero. that's zero EXTERNAL
91 * refs, ie nobody has unmarshalled anything yet. we can't have
92 * negative refs because the stub manager cannot be explicitly
93 * killed, it has to die by somebody unmarshalling then releasing
94 * the marshalled ifptr.
96 sm->extrefs = 0;
98 EnterCriticalSection(&apt->cs);
99 sm->oid = apt->oidc++;
100 list_add_head(&apt->stubmgrs, &sm->entry);
101 LeaveCriticalSection(&apt->cs);
103 TRACE("Created new stub manager (oid=%s) at %p for object with IUnknown %p\n", wine_dbgstr_longlong(sm->oid), sm, object);
105 return sm;
108 /* caller must remove stub manager from apartment prior to calling this function */
109 static void stub_manager_delete(struct stub_manager *m)
111 struct list *cursor;
113 TRACE("destroying %p (oid=%s)\n", m, wine_dbgstr_longlong(m->oid));
115 /* release every ifstub */
116 while ((cursor = list_head(&m->ifstubs)))
118 struct ifstub *ifstub = LIST_ENTRY(cursor, struct ifstub, entry);
119 stub_manager_delete_ifstub(m, ifstub);
122 CoTaskMemFree(m->oxid_info.psa);
123 IUnknown_Release(m->object);
125 DEBUG_CLEAR_CRITSEC_NAME(&m->lock);
126 DeleteCriticalSection(&m->lock);
128 HeapFree(GetProcessHeap(), 0, m);
131 /* gets the stub manager associated with an object - caller must have
132 * a reference to the apartment while a reference to the stub manager is held.
133 * it must also call release on the stub manager when it is no longer needed */
134 struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object)
136 struct stub_manager *result = NULL;
137 struct list *cursor;
139 EnterCriticalSection(&apt->cs);
140 LIST_FOR_EACH( cursor, &apt->stubmgrs )
142 struct stub_manager *m = LIST_ENTRY( cursor, struct stub_manager, entry );
144 if (m->object == object)
146 result = m;
147 stub_manager_int_addref(result);
148 break;
151 LeaveCriticalSection(&apt->cs);
153 if (result)
154 TRACE("found %p for object %p\n", result, object);
155 else
156 TRACE("not found for object %p\n", object);
158 return result;
161 /* removes the apartment reference to an object, destroying it when no other
162 * threads have a reference to it */
163 void apartment_disconnectobject(struct apartment *apt, void *object)
165 int found = FALSE;
166 struct stub_manager *stubmgr;
168 EnterCriticalSection(&apt->cs);
169 LIST_FOR_EACH_ENTRY( stubmgr, &apt->stubmgrs, struct stub_manager, entry )
171 if (stubmgr->object == object)
173 found = TRUE;
174 stub_manager_int_release(stubmgr);
175 break;
178 LeaveCriticalSection(&apt->cs);
180 if (found)
181 TRACE("disconnect object %p\n", object);
182 else
183 WARN("couldn't find object %p\n", object);
186 /* gets the stub manager associated with an object id - caller must have
187 * a reference to the apartment while a reference to the stub manager is held.
188 * it must also call release on the stub manager when it is no longer needed */
189 struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid)
191 struct stub_manager *result = NULL;
192 struct list *cursor;
194 EnterCriticalSection(&apt->cs);
195 LIST_FOR_EACH( cursor, &apt->stubmgrs )
197 struct stub_manager *m = LIST_ENTRY( cursor, struct stub_manager, entry );
199 if (m->oid == oid)
201 result = m;
202 stub_manager_int_addref(result);
203 break;
206 LeaveCriticalSection(&apt->cs);
208 if (result)
209 TRACE("found %p for oid %s\n", result, wine_dbgstr_longlong(oid));
210 else
211 TRACE("not found for oid %s\n", wine_dbgstr_longlong(oid));
213 return result;
216 /* increments the internal refcount */
217 ULONG stub_manager_int_addref(struct stub_manager *This)
219 ULONG refs;
221 EnterCriticalSection(&This->apt->cs);
222 refs = ++This->refs;
223 LeaveCriticalSection(&This->apt->cs);
225 TRACE("before %d\n", refs - 1);
227 return refs;
230 /* decrements the internal refcount */
231 ULONG stub_manager_int_release(struct stub_manager *This)
233 ULONG refs;
234 APARTMENT *apt = This->apt;
236 EnterCriticalSection(&apt->cs);
237 refs = --This->refs;
239 TRACE("after %d\n", refs);
241 /* remove from apartment so no other thread can access it... */
242 if (!refs)
243 list_remove(&This->entry);
245 LeaveCriticalSection(&apt->cs);
247 /* ... so now we can delete it without being inside the apartment critsec */
248 if (!refs)
249 stub_manager_delete(This);
251 return refs;
254 /* add some external references (ie from a client that unmarshaled an ifptr) */
255 ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs)
257 ULONG rc;
259 EnterCriticalSection(&m->lock);
261 /* make sure we don't overflow extrefs */
262 refs = min(refs, (ULONG_MAX-1 - m->extrefs));
263 rc = (m->extrefs += refs);
265 LeaveCriticalSection(&m->lock);
267 TRACE("added %u refs to %p (oid %s), rc is now %u\n", refs, m, wine_dbgstr_longlong(m->oid), rc);
269 return rc;
272 /* remove some external references */
273 ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs, BOOL last_unlock_releases)
275 ULONG rc;
277 EnterCriticalSection(&m->lock);
279 /* make sure we don't underflow extrefs */
280 refs = min(refs, m->extrefs);
281 rc = (m->extrefs -= refs);
283 LeaveCriticalSection(&m->lock);
285 TRACE("removed %u refs from %p (oid %s), rc is now %u\n", refs, m, wine_dbgstr_longlong(m->oid), rc);
287 if (rc == 0 && last_unlock_releases)
288 stub_manager_int_release(m);
290 return rc;
293 static struct ifstub *stub_manager_ipid_to_ifstub(struct stub_manager *m, const IPID *ipid)
295 struct list *cursor;
296 struct ifstub *result = NULL;
298 EnterCriticalSection(&m->lock);
299 LIST_FOR_EACH( cursor, &m->ifstubs )
301 struct ifstub *ifstub = LIST_ENTRY( cursor, struct ifstub, entry );
303 if (IsEqualGUID(ipid, &ifstub->ipid))
305 result = ifstub;
306 break;
309 LeaveCriticalSection(&m->lock);
311 return result;
314 struct ifstub *stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags)
316 struct ifstub *result = NULL;
317 struct ifstub *ifstub;
319 EnterCriticalSection(&m->lock);
320 LIST_FOR_EACH_ENTRY( ifstub, &m->ifstubs, struct ifstub, entry )
322 if (IsEqualIID(iid, &ifstub->iid) && (ifstub->flags == flags))
324 result = ifstub;
325 break;
328 LeaveCriticalSection(&m->lock);
330 return result;
333 /* gets the stub manager associated with an ipid - caller must have
334 * a reference to the apartment while a reference to the stub manager is held.
335 * it must also call release on the stub manager when it is no longer needed */
336 static struct stub_manager *get_stub_manager_from_ipid(APARTMENT *apt, const IPID *ipid)
338 struct stub_manager *result = NULL;
339 struct list *cursor;
341 EnterCriticalSection(&apt->cs);
342 LIST_FOR_EACH( cursor, &apt->stubmgrs )
344 struct stub_manager *m = LIST_ENTRY( cursor, struct stub_manager, entry );
346 if (stub_manager_ipid_to_ifstub(m, ipid))
348 result = m;
349 stub_manager_int_addref(result);
350 break;
353 LeaveCriticalSection(&apt->cs);
355 if (result)
356 TRACE("found %p for ipid %s\n", result, debugstr_guid(ipid));
357 else
358 ERR("not found for ipid %s\n", debugstr_guid(ipid));
360 return result;
363 HRESULT ipid_to_stub_manager(const IPID *ipid, APARTMENT **stub_apt, struct stub_manager **stubmgr_ret)
365 /* FIXME: hack for IRemUnknown */
366 if (ipid->Data2 == 0xffff)
367 *stub_apt = apartment_findfromoxid(*(OXID *)ipid->Data4, TRUE);
368 else
369 *stub_apt = apartment_findfromtid(ipid->Data2);
370 if (!*stub_apt)
372 TRACE("Couldn't find apartment corresponding to TID 0x%04x\n", ipid->Data2);
373 return RPC_E_INVALID_OBJECT;
375 *stubmgr_ret = get_stub_manager_from_ipid(*stub_apt, ipid);
376 if (!*stubmgr_ret)
378 apartment_release(*stub_apt);
379 *stub_apt = NULL;
380 return RPC_E_INVALID_OBJECT;
382 return S_OK;
385 /* gets the apartment, stub and channel of an object. the caller must
386 * release the references to all objects (except iface) if the function
387 * returned success, otherwise no references are returned. */
388 HRESULT ipid_get_dispatch_params(const IPID *ipid, APARTMENT **stub_apt,
389 IRpcStubBuffer **stub, IRpcChannelBuffer **chan,
390 IID *iid, IUnknown **iface)
392 struct stub_manager *stubmgr;
393 struct ifstub *ifstub;
394 APARTMENT *apt;
395 HRESULT hr;
397 hr = ipid_to_stub_manager(ipid, &apt, &stubmgr);
398 if (hr != S_OK) return RPC_E_DISCONNECTED;
400 ifstub = stub_manager_ipid_to_ifstub(stubmgr, ipid);
401 if (ifstub)
403 *stub = ifstub->stubbuffer;
404 IRpcStubBuffer_AddRef(*stub);
405 *chan = ifstub->chan;
406 IRpcChannelBuffer_AddRef(*chan);
407 *stub_apt = apt;
408 *iid = ifstub->iid;
409 *iface = ifstub->iface;
411 stub_manager_int_release(stubmgr);
412 return S_OK;
414 else
416 stub_manager_int_release(stubmgr);
417 apartment_release(apt);
418 return RPC_E_DISCONNECTED;
422 /* generates an ipid in the following format (similar to native version):
423 * Data1 = apartment-local ipid counter
424 * Data2 = apartment creator thread ID
425 * Data3 = process ID
426 * Data4 = random value
428 static inline HRESULT generate_ipid(struct stub_manager *m, IPID *ipid)
430 HRESULT hr;
431 hr = UuidCreate(ipid);
432 if (FAILED(hr))
434 ERR("couldn't create IPID for stub manager %p\n", m);
435 UuidCreateNil(ipid);
436 return hr;
439 ipid->Data1 = InterlockedIncrement(&m->apt->ipidc);
440 ipid->Data2 = (USHORT)m->apt->tid;
441 ipid->Data3 = (USHORT)GetCurrentProcessId();
442 return S_OK;
445 /* registers a new interface stub COM object with the stub manager and returns registration record */
446 struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, MSHLFLAGS flags)
448 struct ifstub *stub;
449 HRESULT hr;
451 TRACE("oid=%s, stubbuffer=%p, iptr=%p, iid=%s\n",
452 wine_dbgstr_longlong(m->oid), sb, iptr, debugstr_guid(iid));
454 stub = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct ifstub));
455 if (!stub) return NULL;
457 hr = RPC_CreateServerChannel(&stub->chan);
458 if (hr != S_OK)
460 HeapFree(GetProcessHeap(), 0, stub);
461 return NULL;
464 stub->stubbuffer = sb;
465 if (sb) IRpcStubBuffer_AddRef(sb);
467 IUnknown_AddRef(iptr);
468 stub->iface = iptr;
469 stub->flags = flags;
470 stub->iid = *iid;
472 /* FIXME: find a cleaner way of identifying that we are creating an ifstub
473 * for the remunknown interface */
474 if (IsEqualIID(iid, &IID_IRemUnknown))
475 stub->ipid = m->oxid_info.ipidRemUnknown;
476 else
477 generate_ipid(m, &stub->ipid);
479 EnterCriticalSection(&m->lock);
480 list_add_head(&m->ifstubs, &stub->entry);
481 /* every normal marshal is counted so we don't allow more than we should */
482 if (flags & MSHLFLAGS_NORMAL) m->norm_refs++;
483 LeaveCriticalSection(&m->lock);
485 TRACE("ifstub %p created with ipid %s\n", stub, debugstr_guid(&stub->ipid));
487 return stub;
490 static void stub_manager_delete_ifstub(struct stub_manager *m, struct ifstub *ifstub)
492 TRACE("m=%p, m->oid=%s, ipid=%s\n", m, wine_dbgstr_longlong(m->oid), debugstr_guid(&ifstub->ipid));
494 list_remove(&ifstub->entry);
496 RPC_UnregisterInterface(&ifstub->iid);
498 if (ifstub->stubbuffer) IUnknown_Release(ifstub->stubbuffer);
499 IUnknown_Release(ifstub->iface);
500 IRpcChannelBuffer_Release(ifstub->chan);
502 HeapFree(GetProcessHeap(), 0, ifstub);
505 /* returns TRUE if it is possible to unmarshal, FALSE otherwise. */
506 BOOL stub_manager_notify_unmarshal(struct stub_manager *m, const IPID *ipid)
508 BOOL ret = TRUE;
509 struct ifstub *ifstub;
511 if (!(ifstub = stub_manager_ipid_to_ifstub(m, ipid)))
513 ERR("attempted unmarshal of unknown IPID %s\n", debugstr_guid(ipid));
514 return FALSE;
517 EnterCriticalSection(&m->lock);
519 /* track normal marshals so we can enforce rules whilst in-process */
520 if (ifstub->flags & MSHLFLAGS_NORMAL)
522 if (m->norm_refs)
523 m->norm_refs--;
524 else
526 ERR("attempted invalid normal unmarshal, norm_refs is zero\n");
527 ret = FALSE;
531 LeaveCriticalSection(&m->lock);
533 return ret;
536 /* handles refcounting for CoReleaseMarshalData */
537 void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const IPID *ipid)
539 struct ifstub *ifstub;
541 if (!(ifstub = stub_manager_ipid_to_ifstub(m, ipid)))
542 return;
544 if (ifstub->flags & MSHLFLAGS_TABLEWEAK)
545 refs = 0;
546 else if (ifstub->flags & MSHLFLAGS_TABLESTRONG)
547 refs = 1;
549 stub_manager_ext_release(m, refs, TRUE);
552 /* is an ifstub table marshaled? */
553 BOOL stub_manager_is_table_marshaled(struct stub_manager *m, const IPID *ipid)
555 struct ifstub *ifstub = stub_manager_ipid_to_ifstub(m, ipid);
557 assert( ifstub );
559 return ifstub->flags & (MSHLFLAGS_TABLESTRONG | MSHLFLAGS_TABLEWEAK);
563 /*****************************************************************************
565 * IRemUnknown implementation
568 * Note: this object is not related to the lifetime of a stub_manager, but it
569 * interacts with stub managers.
572 typedef struct rem_unknown
574 const IRemUnknownVtbl *lpVtbl;
575 LONG refs;
576 } RemUnknown;
578 static const IRemUnknownVtbl RemUnknown_Vtbl;
581 /* construct an IRemUnknown object with one outstanding reference */
582 static HRESULT RemUnknown_Construct(IRemUnknown **ppRemUnknown)
584 RemUnknown *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
586 if (!This) return E_OUTOFMEMORY;
588 This->lpVtbl = &RemUnknown_Vtbl;
589 This->refs = 1;
591 *ppRemUnknown = (IRemUnknown *)This;
592 return S_OK;
595 static HRESULT WINAPI RemUnknown_QueryInterface(IRemUnknown *iface, REFIID riid, void **ppv)
597 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
599 if (IsEqualIID(riid, &IID_IUnknown) ||
600 IsEqualIID(riid, &IID_IRemUnknown))
602 *ppv = (LPVOID)iface;
603 IRemUnknown_AddRef(iface);
604 return S_OK;
607 FIXME("No interface for iid %s\n", debugstr_guid(riid));
609 *ppv = NULL;
610 return E_NOINTERFACE;
613 static ULONG WINAPI RemUnknown_AddRef(IRemUnknown *iface)
615 ULONG refs;
616 RemUnknown *This = (RemUnknown *)iface;
618 refs = InterlockedIncrement(&This->refs);
620 TRACE("%p before: %d\n", iface, refs-1);
621 return refs;
624 static ULONG WINAPI RemUnknown_Release(IRemUnknown *iface)
626 ULONG refs;
627 RemUnknown *This = (RemUnknown *)iface;
629 refs = InterlockedDecrement(&This->refs);
630 if (!refs)
631 HeapFree(GetProcessHeap(), 0, This);
633 TRACE("%p after: %d\n", iface, refs);
634 return refs;
637 static HRESULT WINAPI RemUnknown_RemQueryInterface(IRemUnknown *iface,
638 REFIPID ripid, ULONG cRefs, USHORT cIids, IID *iids /* [size_is(cIids)] */,
639 REMQIRESULT **ppQIResults /* [size_is(,cIids)] */)
641 HRESULT hr;
642 USHORT i;
643 USHORT successful_qis = 0;
644 APARTMENT *apt;
645 struct stub_manager *stubmgr;
647 TRACE("(%p)->(%s, %d, %d, %p, %p)\n", iface, debugstr_guid(ripid), cRefs, cIids, iids, ppQIResults);
649 hr = ipid_to_stub_manager(ripid, &apt, &stubmgr);
650 if (hr != S_OK) return hr;
652 *ppQIResults = CoTaskMemAlloc(sizeof(REMQIRESULT) * cIids);
654 for (i = 0; i < cIids; i++)
656 HRESULT hrobj = marshal_object(apt, &(*ppQIResults)[i].std, &iids[i],
657 stubmgr->object, MSHLFLAGS_NORMAL);
658 if (hrobj == S_OK)
659 successful_qis++;
660 (*ppQIResults)[i].hResult = hrobj;
663 stub_manager_int_release(stubmgr);
664 apartment_release(apt);
666 if (successful_qis == cIids)
667 return S_OK; /* we got all requested interfaces */
668 else if (successful_qis == 0)
669 return E_NOINTERFACE; /* we didn't get any interfaces */
670 else
671 return S_FALSE; /* we got some interfaces */
674 static HRESULT WINAPI RemUnknown_RemAddRef(IRemUnknown *iface,
675 USHORT cInterfaceRefs,
676 REMINTERFACEREF* InterfaceRefs /* [size_is(cInterfaceRefs)] */,
677 HRESULT *pResults /* [size_is(cInterfaceRefs)] */)
679 HRESULT hr = S_OK;
680 USHORT i;
682 TRACE("(%p)->(%d, %p, %p)\n", iface, cInterfaceRefs, InterfaceRefs, pResults);
684 for (i = 0; i < cInterfaceRefs; i++)
686 APARTMENT *apt;
687 struct stub_manager *stubmgr;
689 pResults[i] = ipid_to_stub_manager(&InterfaceRefs[i].ipid, &apt, &stubmgr);
690 if (pResults[i] != S_OK)
692 hr = S_FALSE;
693 continue;
696 stub_manager_ext_addref(stubmgr, InterfaceRefs[i].cPublicRefs);
697 if (InterfaceRefs[i].cPrivateRefs)
698 FIXME("Adding %ld refs securely not implemented\n", InterfaceRefs[i].cPrivateRefs);
700 stub_manager_int_release(stubmgr);
701 apartment_release(apt);
704 return hr;
707 static HRESULT WINAPI RemUnknown_RemRelease(IRemUnknown *iface,
708 USHORT cInterfaceRefs,
709 REMINTERFACEREF* InterfaceRefs /* [size_is(cInterfaceRefs)] */)
711 HRESULT hr = S_OK;
712 USHORT i;
714 TRACE("(%p)->(%d, %p)\n", iface, cInterfaceRefs, InterfaceRefs);
716 for (i = 0; i < cInterfaceRefs; i++)
718 APARTMENT *apt;
719 struct stub_manager *stubmgr;
721 hr = ipid_to_stub_manager(&InterfaceRefs[i].ipid, &apt, &stubmgr);
722 if (hr != S_OK)
724 hr = E_INVALIDARG;
725 /* FIXME: we should undo any changes already made in this function */
726 break;
729 stub_manager_ext_release(stubmgr, InterfaceRefs[i].cPublicRefs, TRUE);
730 if (InterfaceRefs[i].cPrivateRefs)
731 FIXME("Releasing %ld refs securely not implemented\n", InterfaceRefs[i].cPrivateRefs);
733 stub_manager_int_release(stubmgr);
734 apartment_release(apt);
737 return hr;
740 static const IRemUnknownVtbl RemUnknown_Vtbl =
742 RemUnknown_QueryInterface,
743 RemUnknown_AddRef,
744 RemUnknown_Release,
745 RemUnknown_RemQueryInterface,
746 RemUnknown_RemAddRef,
747 RemUnknown_RemRelease
750 /* starts the IRemUnknown listener for the current apartment */
751 HRESULT start_apartment_remote_unknown(void)
753 IRemUnknown *pRemUnknown;
754 HRESULT hr = S_OK;
755 APARTMENT *apt = COM_CurrentApt();
757 EnterCriticalSection(&apt->cs);
758 if (!apt->remunk_exported)
760 /* create the IRemUnknown object */
761 hr = RemUnknown_Construct(&pRemUnknown);
762 if (hr == S_OK)
764 STDOBJREF stdobjref; /* dummy - not used */
765 /* register it with the stub manager */
766 hr = marshal_object(apt, &stdobjref, &IID_IRemUnknown, (IUnknown *)pRemUnknown, MSHLFLAGS_NORMAL);
767 /* release our reference to the object as the stub manager will manage the life cycle for us */
768 IRemUnknown_Release(pRemUnknown);
769 if (hr == S_OK)
770 apt->remunk_exported = TRUE;
773 LeaveCriticalSection(&apt->cs);
774 return hr;