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
38 #include "wine/debug.h"
39 #include "compobj_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
44 /* generates an ipid in the following format (similar to native version):
45 * Data1 = apartment-local ipid counter
46 * Data2 = apartment creator thread ID
48 * Data4 = random value
50 static inline HRESULT
generate_ipid(struct stub_manager
*m
, IPID
*ipid
)
53 hr
= UuidCreate(ipid
);
56 ERR("couldn't create IPID for stub manager %p\n", m
);
61 ipid
->Data1
= InterlockedIncrement(&m
->apt
->ipidc
);
62 ipid
->Data2
= (USHORT
)m
->apt
->tid
;
63 ipid
->Data3
= (USHORT
)GetCurrentProcessId();
67 /* registers a new interface stub COM object with the stub manager and returns registration record */
68 struct ifstub
*stub_manager_new_ifstub(struct stub_manager
*m
, IRpcStubBuffer
*sb
, IUnknown
*iptr
, REFIID iid
, DWORD dest_context
,
69 void *dest_context_data
, MSHLFLAGS flags
)
74 TRACE("oid=%s, stubbuffer=%p, iptr=%p, iid=%s\n",
75 wine_dbgstr_longlong(m
->oid
), sb
, iptr
, debugstr_guid(iid
));
77 stub
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct ifstub
));
78 if (!stub
) return NULL
;
80 hr
= RPC_CreateServerChannel(dest_context
, dest_context_data
, &stub
->chan
);
83 HeapFree(GetProcessHeap(), 0, stub
);
87 stub
->stubbuffer
= sb
;
88 if (sb
) IRpcStubBuffer_AddRef(sb
);
90 IUnknown_AddRef(iptr
);
95 /* FIXME: find a cleaner way of identifying that we are creating an ifstub
96 * for the remunknown interface */
97 if (flags
& MSHLFLAGSP_REMUNKNOWN
)
98 stub
->ipid
= m
->oxid_info
.ipidRemUnknown
;
100 generate_ipid(m
, &stub
->ipid
);
102 EnterCriticalSection(&m
->lock
);
103 list_add_head(&m
->ifstubs
, &stub
->entry
);
104 /* every normal marshal is counted so we don't allow more than we should */
105 if (flags
& MSHLFLAGS_NORMAL
) m
->norm_refs
++;
106 LeaveCriticalSection(&m
->lock
);
108 TRACE("ifstub %p created with ipid %s\n", stub
, debugstr_guid(&stub
->ipid
));
113 static void stub_manager_delete_ifstub(struct stub_manager
*m
, struct ifstub
*ifstub
)
115 TRACE("m=%p, m->oid=%s, ipid=%s\n", m
, wine_dbgstr_longlong(m
->oid
), debugstr_guid(&ifstub
->ipid
));
117 list_remove(&ifstub
->entry
);
119 RPC_UnregisterInterface(&ifstub
->iid
);
121 if (ifstub
->stubbuffer
) IRpcStubBuffer_Release(ifstub
->stubbuffer
);
122 IUnknown_Release(ifstub
->iface
);
123 IRpcChannelBuffer_Release(ifstub
->chan
);
125 HeapFree(GetProcessHeap(), 0, ifstub
);
128 static struct ifstub
*stub_manager_ipid_to_ifstub(struct stub_manager
*m
, const IPID
*ipid
)
131 struct ifstub
*result
= NULL
;
133 EnterCriticalSection(&m
->lock
);
134 LIST_FOR_EACH( cursor
, &m
->ifstubs
)
136 struct ifstub
*ifstub
= LIST_ENTRY( cursor
, struct ifstub
, entry
);
138 if (IsEqualGUID(ipid
, &ifstub
->ipid
))
144 LeaveCriticalSection(&m
->lock
);
149 struct ifstub
*stub_manager_find_ifstub(struct stub_manager
*m
, REFIID iid
, MSHLFLAGS flags
)
151 struct ifstub
*result
= NULL
;
152 struct ifstub
*ifstub
;
154 EnterCriticalSection(&m
->lock
);
155 LIST_FOR_EACH_ENTRY( ifstub
, &m
->ifstubs
, struct ifstub
, entry
)
157 if (IsEqualIID(iid
, &ifstub
->iid
) && (ifstub
->flags
== flags
))
163 LeaveCriticalSection(&m
->lock
);
168 /* creates a new stub manager and adds it into the apartment. caller must
169 * release stub manager when it is no longer required. the apartment and
170 * external refs together take one implicit ref */
171 struct stub_manager
*new_stub_manager(APARTMENT
*apt
, IUnknown
*object
)
173 struct stub_manager
*sm
;
178 sm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct stub_manager
));
179 if (!sm
) return NULL
;
181 list_init(&sm
->ifstubs
);
183 InitializeCriticalSection(&sm
->lock
);
184 DEBUG_SET_CRITSEC_NAME(&sm
->lock
, "stub_manager");
186 IUnknown_AddRef(object
);
190 /* start off with 2 references because the stub is in the apartment
191 * and the caller will also hold a reference */
195 sm
->oxid_info
.dwPid
= GetCurrentProcessId();
196 sm
->oxid_info
.dwTid
= GetCurrentThreadId();
198 * FIXME: this is a hack for marshalling IRemUnknown. In real
199 * DCOM, the IPID of the IRemUnknown interface is generated like
200 * any other and passed to the OXID resolver which then returns it
201 * when queried. We don't have an OXID resolver yet so instead we
202 * use a magic IPID reserved for IRemUnknown.
204 sm
->oxid_info
.ipidRemUnknown
.Data1
= 0xffffffff;
205 sm
->oxid_info
.ipidRemUnknown
.Data2
= 0xffff;
206 sm
->oxid_info
.ipidRemUnknown
.Data3
= 0xffff;
207 assert(sizeof(sm
->oxid_info
.ipidRemUnknown
.Data4
) == sizeof(apt
->oxid
));
208 memcpy(sm
->oxid_info
.ipidRemUnknown
.Data4
, &apt
->oxid
, sizeof(OXID
));
209 sm
->oxid_info
.dwAuthnHint
= RPC_C_AUTHN_LEVEL_NONE
;
210 sm
->oxid_info
.psa
= NULL
/* FIXME */;
212 /* Yes, that's right, this starts at zero. that's zero EXTERNAL
213 * refs, i.e., nobody has unmarshalled anything yet. We can't have
214 * negative refs because the stub manager cannot be explicitly
215 * killed, it has to die by somebody unmarshalling then releasing
216 * the marshalled ifptr.
220 hres
= IUnknown_QueryInterface(object
, &IID_IExternalConnection
, (void**)&sm
->extern_conn
);
222 sm
->extern_conn
= NULL
;
224 EnterCriticalSection(&apt
->cs
);
225 sm
->oid
= apt
->oidc
++;
226 list_add_head(&apt
->stubmgrs
, &sm
->entry
);
227 LeaveCriticalSection(&apt
->cs
);
229 TRACE("Created new stub manager (oid=%s) at %p for object with IUnknown %p\n", wine_dbgstr_longlong(sm
->oid
), sm
, object
);
234 /* caller must remove stub manager from apartment prior to calling this function */
235 static void stub_manager_delete(struct stub_manager
*m
)
239 TRACE("destroying %p (oid=%s)\n", m
, wine_dbgstr_longlong(m
->oid
));
241 /* release every ifstub */
242 while ((cursor
= list_head(&m
->ifstubs
)))
244 struct ifstub
*ifstub
= LIST_ENTRY(cursor
, struct ifstub
, entry
);
245 stub_manager_delete_ifstub(m
, ifstub
);
249 IExternalConnection_Release(m
->extern_conn
);
251 CoTaskMemFree(m
->oxid_info
.psa
);
252 IUnknown_Release(m
->object
);
254 DEBUG_CLEAR_CRITSEC_NAME(&m
->lock
);
255 DeleteCriticalSection(&m
->lock
);
257 HeapFree(GetProcessHeap(), 0, m
);
260 /* increments the internal refcount */
261 static ULONG
stub_manager_int_addref(struct stub_manager
*This
)
265 EnterCriticalSection(&This
->apt
->cs
);
267 LeaveCriticalSection(&This
->apt
->cs
);
269 TRACE("before %d\n", refs
- 1);
274 /* decrements the internal refcount */
275 ULONG
stub_manager_int_release(struct stub_manager
*This
)
278 APARTMENT
*apt
= This
->apt
;
280 EnterCriticalSection(&apt
->cs
);
283 TRACE("after %d\n", refs
);
285 /* remove from apartment so no other thread can access it... */
287 list_remove(&This
->entry
);
289 LeaveCriticalSection(&apt
->cs
);
291 /* ... so now we can delete it without being inside the apartment critsec */
293 stub_manager_delete(This
);
298 /* gets the stub manager associated with an object - caller must have
299 * a reference to the apartment while a reference to the stub manager is held.
300 * it must also call release on the stub manager when it is no longer needed */
301 struct stub_manager
*get_stub_manager_from_object(APARTMENT
*apt
, void *object
)
303 struct stub_manager
*result
= NULL
;
306 EnterCriticalSection(&apt
->cs
);
307 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
309 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
311 if (m
->object
== object
)
314 stub_manager_int_addref(result
);
318 LeaveCriticalSection(&apt
->cs
);
321 TRACE("found %p for object %p\n", result
, object
);
323 TRACE("not found for object %p\n", object
);
328 /* removes the apartment reference to an object, destroying it when no other
329 * threads have a reference to it */
330 void apartment_disconnectobject(struct apartment
*apt
, void *object
)
333 struct stub_manager
*stubmgr
;
335 EnterCriticalSection(&apt
->cs
);
336 LIST_FOR_EACH_ENTRY( stubmgr
, &apt
->stubmgrs
, struct stub_manager
, entry
)
338 if (stubmgr
->object
== object
)
341 stub_manager_int_release(stubmgr
);
345 LeaveCriticalSection(&apt
->cs
);
348 TRACE("disconnect object %p\n", object
);
350 WARN("couldn't find object %p\n", object
);
353 /* gets the stub manager associated with an object id - caller must have
354 * a reference to the apartment while a reference to the stub manager is held.
355 * it must also call release on the stub manager when it is no longer needed */
356 struct stub_manager
*get_stub_manager(APARTMENT
*apt
, OID oid
)
358 struct stub_manager
*result
= NULL
;
361 EnterCriticalSection(&apt
->cs
);
362 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
364 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
369 stub_manager_int_addref(result
);
373 LeaveCriticalSection(&apt
->cs
);
376 TRACE("found %p for oid %s\n", result
, wine_dbgstr_longlong(oid
));
378 TRACE("not found for oid %s\n", wine_dbgstr_longlong(oid
));
383 /* add some external references (ie from a client that unmarshaled an ifptr) */
384 ULONG
stub_manager_ext_addref(struct stub_manager
*m
, ULONG refs
, BOOL tableweak
)
386 BOOL first_extern_ref
;
389 EnterCriticalSection(&m
->lock
);
391 first_extern_ref
= refs
&& !m
->extrefs
;
393 /* make sure we don't overflow extrefs */
394 refs
= min(refs
, (ULONG_MAX
-1 - m
->extrefs
));
395 rc
= (m
->extrefs
+= refs
);
400 LeaveCriticalSection(&m
->lock
);
402 TRACE("added %u refs to %p (oid %s), rc is now %u\n", refs
, m
, wine_dbgstr_longlong(m
->oid
), rc
);
405 * NOTE: According to tests, creating a stub causes two AddConnection calls followed by
406 * one ReleaseConnection call (with fLastReleaseCloses=FALSE).
408 if(first_extern_ref
&& m
->extern_conn
)
409 IExternalConnection_AddConnection(m
->extern_conn
, EXTCONN_STRONG
, 0);
414 /* remove some external references */
415 ULONG
stub_manager_ext_release(struct stub_manager
*m
, ULONG refs
, BOOL tableweak
, BOOL last_unlock_releases
)
417 BOOL last_extern_ref
;
420 EnterCriticalSection(&m
->lock
);
422 /* make sure we don't underflow extrefs */
423 refs
= min(refs
, m
->extrefs
);
424 rc
= (m
->extrefs
-= refs
);
428 if (!last_unlock_releases
)
431 last_extern_ref
= refs
&& !m
->extrefs
;
433 LeaveCriticalSection(&m
->lock
);
435 TRACE("removed %u refs from %p (oid %s), rc is now %u\n", refs
, m
, wine_dbgstr_longlong(m
->oid
), rc
);
437 if (last_extern_ref
&& m
->extern_conn
)
438 IExternalConnection_ReleaseConnection(m
->extern_conn
, EXTCONN_STRONG
, 0, last_unlock_releases
);
441 if (!(m
->extern_conn
&& last_unlock_releases
&& m
->weakrefs
))
442 stub_manager_int_release(m
);
447 /* gets the stub manager associated with an ipid - caller must have
448 * a reference to the apartment while a reference to the stub manager is held.
449 * it must also call release on the stub manager when it is no longer needed */
450 static struct stub_manager
*get_stub_manager_from_ipid(APARTMENT
*apt
, const IPID
*ipid
)
452 struct stub_manager
*result
= NULL
;
455 EnterCriticalSection(&apt
->cs
);
456 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
458 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
460 if (stub_manager_ipid_to_ifstub(m
, ipid
))
463 stub_manager_int_addref(result
);
467 LeaveCriticalSection(&apt
->cs
);
470 TRACE("found %p for ipid %s\n", result
, debugstr_guid(ipid
));
472 ERR("not found for ipid %s\n", debugstr_guid(ipid
));
477 static HRESULT
ipid_to_stub_manager(const IPID
*ipid
, APARTMENT
**stub_apt
, struct stub_manager
**stubmgr_ret
)
479 /* FIXME: hack for IRemUnknown */
480 if (ipid
->Data2
== 0xffff)
481 *stub_apt
= apartment_findfromoxid(*(const OXID
*)ipid
->Data4
, TRUE
);
483 *stub_apt
= apartment_findfromtid(ipid
->Data2
);
486 TRACE("Couldn't find apartment corresponding to TID 0x%04x\n", ipid
->Data2
);
487 return RPC_E_INVALID_OBJECT
;
489 *stubmgr_ret
= get_stub_manager_from_ipid(*stub_apt
, ipid
);
492 apartment_release(*stub_apt
);
494 return RPC_E_INVALID_OBJECT
;
499 /* gets the apartment, stub and channel of an object. the caller must
500 * release the references to all objects (except iface) if the function
501 * returned success, otherwise no references are returned. */
502 HRESULT
ipid_get_dispatch_params(const IPID
*ipid
, APARTMENT
**stub_apt
,
503 IRpcStubBuffer
**stub
, IRpcChannelBuffer
**chan
,
504 IID
*iid
, IUnknown
**iface
)
506 struct stub_manager
*stubmgr
;
507 struct ifstub
*ifstub
;
511 hr
= ipid_to_stub_manager(ipid
, &apt
, &stubmgr
);
512 if (hr
!= S_OK
) return RPC_E_DISCONNECTED
;
514 ifstub
= stub_manager_ipid_to_ifstub(stubmgr
, ipid
);
517 *stub
= ifstub
->stubbuffer
;
518 IRpcStubBuffer_AddRef(*stub
);
519 *chan
= ifstub
->chan
;
520 IRpcChannelBuffer_AddRef(*chan
);
523 *iface
= ifstub
->iface
;
525 stub_manager_int_release(stubmgr
);
530 stub_manager_int_release(stubmgr
);
531 apartment_release(apt
);
532 return RPC_E_DISCONNECTED
;
536 /* returns TRUE if it is possible to unmarshal, FALSE otherwise. */
537 BOOL
stub_manager_notify_unmarshal(struct stub_manager
*m
, const IPID
*ipid
)
540 struct ifstub
*ifstub
;
542 if (!(ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
)))
544 ERR("attempted unmarshal of unknown IPID %s\n", debugstr_guid(ipid
));
548 EnterCriticalSection(&m
->lock
);
550 /* track normal marshals so we can enforce rules whilst in-process */
551 if (ifstub
->flags
& MSHLFLAGS_NORMAL
)
557 ERR("attempted invalid normal unmarshal, norm_refs is zero\n");
562 LeaveCriticalSection(&m
->lock
);
567 /* handles refcounting for CoReleaseMarshalData */
568 void stub_manager_release_marshal_data(struct stub_manager
*m
, ULONG refs
, const IPID
*ipid
, BOOL tableweak
)
570 struct ifstub
*ifstub
;
572 if (!(ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
)))
575 if (ifstub
->flags
& MSHLFLAGS_TABLEWEAK
)
577 else if (ifstub
->flags
& MSHLFLAGS_TABLESTRONG
)
580 stub_manager_ext_release(m
, refs
, tableweak
, !tableweak
);
583 /* is an ifstub table marshaled? */
584 BOOL
stub_manager_is_table_marshaled(struct stub_manager
*m
, const IPID
*ipid
)
586 struct ifstub
*ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
);
590 return ifstub
->flags
& (MSHLFLAGS_TABLESTRONG
| MSHLFLAGS_TABLEWEAK
);
594 /*****************************************************************************
596 * IRemUnknown implementation
599 * Note: this object is not related to the lifetime of a stub_manager, but it
600 * interacts with stub managers.
603 typedef struct rem_unknown
605 IRemUnknown IRemUnknown_iface
;
609 static const IRemUnknownVtbl RemUnknown_Vtbl
;
611 static inline RemUnknown
*impl_from_IRemUnknown(IRemUnknown
*iface
)
613 return CONTAINING_RECORD(iface
, RemUnknown
, IRemUnknown_iface
);
617 /* construct an IRemUnknown object with one outstanding reference */
618 static HRESULT
RemUnknown_Construct(IRemUnknown
**ppRemUnknown
)
620 RemUnknown
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
622 if (!This
) return E_OUTOFMEMORY
;
624 This
->IRemUnknown_iface
.lpVtbl
= &RemUnknown_Vtbl
;
627 *ppRemUnknown
= &This
->IRemUnknown_iface
;
631 static HRESULT WINAPI
RemUnknown_QueryInterface(IRemUnknown
*iface
, REFIID riid
, void **ppv
)
633 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
635 if (IsEqualIID(riid
, &IID_IUnknown
) ||
636 IsEqualIID(riid
, &IID_IRemUnknown
))
639 IRemUnknown_AddRef(iface
);
643 FIXME("No interface for iid %s\n", debugstr_guid(riid
));
646 return E_NOINTERFACE
;
649 static ULONG WINAPI
RemUnknown_AddRef(IRemUnknown
*iface
)
652 RemUnknown
*This
= impl_from_IRemUnknown(iface
);
654 refs
= InterlockedIncrement(&This
->refs
);
656 TRACE("%p before: %d\n", iface
, refs
-1);
660 static ULONG WINAPI
RemUnknown_Release(IRemUnknown
*iface
)
663 RemUnknown
*This
= impl_from_IRemUnknown(iface
);
665 refs
= InterlockedDecrement(&This
->refs
);
667 HeapFree(GetProcessHeap(), 0, This
);
669 TRACE("%p after: %d\n", iface
, refs
);
673 static HRESULT WINAPI
RemUnknown_RemQueryInterface(IRemUnknown
*iface
,
674 REFIPID ripid
, ULONG cRefs
, USHORT cIids
, IID
*iids
/* [size_is(cIids)] */,
675 REMQIRESULT
**ppQIResults
/* [size_is(,cIids)] */)
679 USHORT successful_qis
= 0;
681 struct stub_manager
*stubmgr
;
683 TRACE("(%p)->(%s, %d, %d, %p, %p)\n", iface
, debugstr_guid(ripid
), cRefs
, cIids
, iids
, ppQIResults
);
685 hr
= ipid_to_stub_manager(ripid
, &apt
, &stubmgr
);
686 if (hr
!= S_OK
) return hr
;
688 *ppQIResults
= CoTaskMemAlloc(sizeof(REMQIRESULT
) * cIids
);
690 for (i
= 0; i
< cIids
; i
++)
692 HRESULT hrobj
= marshal_object(apt
, &(*ppQIResults
)[i
].std
, &iids
[i
],
693 stubmgr
->object
, MSHCTX_DIFFERENTMACHINE
, NULL
, MSHLFLAGS_NORMAL
);
696 (*ppQIResults
)[i
].hResult
= hrobj
;
699 stub_manager_int_release(stubmgr
);
700 apartment_release(apt
);
702 if (successful_qis
== cIids
)
703 return S_OK
; /* we got all requested interfaces */
704 else if (successful_qis
== 0)
705 return E_NOINTERFACE
; /* we didn't get any interfaces */
707 return S_FALSE
; /* we got some interfaces */
710 static HRESULT WINAPI
RemUnknown_RemAddRef(IRemUnknown
*iface
,
711 USHORT cInterfaceRefs
,
712 REMINTERFACEREF
* InterfaceRefs
/* [size_is(cInterfaceRefs)] */,
713 HRESULT
*pResults
/* [size_is(cInterfaceRefs)] */)
718 TRACE("(%p)->(%d, %p, %p)\n", iface
, cInterfaceRefs
, InterfaceRefs
, pResults
);
720 for (i
= 0; i
< cInterfaceRefs
; i
++)
723 struct stub_manager
*stubmgr
;
725 pResults
[i
] = ipid_to_stub_manager(&InterfaceRefs
[i
].ipid
, &apt
, &stubmgr
);
726 if (pResults
[i
] != S_OK
)
732 stub_manager_ext_addref(stubmgr
, InterfaceRefs
[i
].cPublicRefs
, FALSE
);
733 if (InterfaceRefs
[i
].cPrivateRefs
)
734 FIXME("Adding %d refs securely not implemented\n", InterfaceRefs
[i
].cPrivateRefs
);
736 stub_manager_int_release(stubmgr
);
737 apartment_release(apt
);
743 static HRESULT WINAPI
RemUnknown_RemRelease(IRemUnknown
*iface
,
744 USHORT cInterfaceRefs
,
745 REMINTERFACEREF
* InterfaceRefs
/* [size_is(cInterfaceRefs)] */)
750 TRACE("(%p)->(%d, %p)\n", iface
, cInterfaceRefs
, InterfaceRefs
);
752 for (i
= 0; i
< cInterfaceRefs
; i
++)
755 struct stub_manager
*stubmgr
;
757 hr
= ipid_to_stub_manager(&InterfaceRefs
[i
].ipid
, &apt
, &stubmgr
);
761 /* FIXME: we should undo any changes already made in this function */
765 stub_manager_ext_release(stubmgr
, InterfaceRefs
[i
].cPublicRefs
, FALSE
, TRUE
);
766 if (InterfaceRefs
[i
].cPrivateRefs
)
767 FIXME("Releasing %d refs securely not implemented\n", InterfaceRefs
[i
].cPrivateRefs
);
769 stub_manager_int_release(stubmgr
);
770 apartment_release(apt
);
776 static const IRemUnknownVtbl RemUnknown_Vtbl
=
778 RemUnknown_QueryInterface
,
781 RemUnknown_RemQueryInterface
,
782 RemUnknown_RemAddRef
,
783 RemUnknown_RemRelease
786 /* starts the IRemUnknown listener for the current apartment */
787 HRESULT
start_apartment_remote_unknown(void)
789 IRemUnknown
*pRemUnknown
;
791 APARTMENT
*apt
= COM_CurrentApt();
793 EnterCriticalSection(&apt
->cs
);
794 if (!apt
->remunk_exported
)
796 /* create the IRemUnknown object */
797 hr
= RemUnknown_Construct(&pRemUnknown
);
800 STDOBJREF stdobjref
; /* dummy - not used */
801 /* register it with the stub manager */
802 hr
= marshal_object(apt
, &stdobjref
, &IID_IRemUnknown
, (IUnknown
*)pRemUnknown
, MSHCTX_DIFFERENTMACHINE
, NULL
, MSHLFLAGS_NORMAL
|MSHLFLAGSP_REMUNKNOWN
);
803 /* release our reference to the object as the stub manager will manage the life cycle for us */
804 IRemUnknown_Release(pRemUnknown
);
806 apt
->remunk_exported
= TRUE
;
809 LeaveCriticalSection(&apt
->cs
);