4 * Copyright 1998 Marcus Meissner
5 * Copyright 1999 Noomen Hamza
6 * Copyright 2005 Robert Shearman (for CodeWeavers)
7 * Copyright 2007 Robert Shearman
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
40 #include "wine/list.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
43 #include "wine/exception.h"
45 #include "compobj_private.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
51 /* see MSDN docs for IROTData::GetComparisonData, which states what this
54 #define MAX_COMPARISON_DATA 2048
56 static LONG WINAPI
rpc_filter(EXCEPTION_POINTERS
*eptr
)
58 return I_RpcExceptionFilter(eptr
->ExceptionRecord
->ExceptionCode
);
61 /* define the structure of the running object table elements */
65 InterfaceData
* object
; /* marshaled running object*/
66 MonikerComparisonData
* moniker_data
; /* moniker comparison data that identifies this object */
67 DWORD cookie
; /* cookie identifying this object */
68 FILETIME last_modified
;
69 IrotContextHandle ctxt_handle
;
72 /* define the RunningObjectTableImpl structure */
73 typedef struct RunningObjectTableImpl
75 IRunningObjectTable IRunningObjectTable_iface
;
78 struct list rot
; /* list of ROT entries */
79 CRITICAL_SECTION lock
;
80 } RunningObjectTableImpl
;
82 static RunningObjectTableImpl
* runningObjectTableInstance
= NULL
;
83 static IrotHandle irot_handle
;
85 /* define the EnumMonikerImpl structure */
86 typedef struct EnumMonikerImpl
88 IEnumMoniker IEnumMoniker_iface
;
91 InterfaceList
*moniker_list
;
95 static inline RunningObjectTableImpl
*impl_from_IRunningObjectTable(IRunningObjectTable
*iface
)
97 return CONTAINING_RECORD(iface
, RunningObjectTableImpl
, IRunningObjectTable_iface
);
100 static inline EnumMonikerImpl
*impl_from_IEnumMoniker(IEnumMoniker
*iface
)
102 return CONTAINING_RECORD(iface
, EnumMonikerImpl
, IEnumMoniker_iface
);
105 /* IEnumMoniker Local functions*/
106 static HRESULT
EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList
*moniker_list
,
107 ULONG pos
, IEnumMoniker
**ppenumMoniker
);
109 static IrotHandle
get_irot_handle(void)
115 IrotHandle new_handle
;
116 unsigned short ncacn_np
[] = IROT_PROTSEQ
;
117 unsigned short endpoint
[] = IROT_ENDPOINT
;
118 status
= RpcStringBindingComposeW(NULL
, ncacn_np
, NULL
, endpoint
, NULL
, &binding
);
119 if (status
== RPC_S_OK
)
121 status
= RpcBindingFromStringBindingW(binding
, &new_handle
);
122 RpcStringFreeW(&binding
);
124 if (status
!= RPC_S_OK
)
126 if (InterlockedCompareExchangePointer(&irot_handle
, new_handle
, NULL
))
127 /* another thread beat us to it */
128 RpcBindingFree(&new_handle
);
133 static BOOL
start_rpcss(void)
135 static const WCHAR rpcssW
[] = {'R','p','c','S','s',0};
136 SC_HANDLE scm
, service
;
137 SERVICE_STATUS_PROCESS status
;
142 if (!(scm
= OpenSCManagerW( NULL
, NULL
, 0 )))
144 ERR( "failed to open service manager\n" );
147 if (!(service
= OpenServiceW( scm
, rpcssW
, SERVICE_START
| SERVICE_QUERY_STATUS
)))
149 ERR( "failed to open RpcSs service\n" );
150 CloseServiceHandle( scm
);
153 if (StartServiceW( service
, 0, NULL
) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING
)
155 ULONGLONG start_time
= GetTickCount64();
160 if (!QueryServiceStatusEx( service
, SC_STATUS_PROCESS_INFO
,
161 (BYTE
*)&status
, sizeof(status
), &dummy
))
163 if (status
.dwCurrentState
== SERVICE_RUNNING
)
168 if (GetTickCount64() - start_time
> 30000) break;
171 } while (status
.dwCurrentState
== SERVICE_START_PENDING
);
173 if (status
.dwCurrentState
!= SERVICE_RUNNING
)
174 WARN( "RpcSs failed to start %u\n", status
.dwCurrentState
);
176 else ERR( "failed to start RpcSs service\n" );
178 CloseServiceHandle( service
);
179 CloseServiceHandle( scm
);
183 static HRESULT
create_stream_on_mip_ro(const InterfaceData
*mip
, IStream
**stream
)
185 HGLOBAL hglobal
= GlobalAlloc(0, mip
->ulCntData
);
186 void *pv
= GlobalLock(hglobal
);
187 memcpy(pv
, mip
->abData
, mip
->ulCntData
);
188 GlobalUnlock(hglobal
);
189 return CreateStreamOnHGlobal(hglobal
, TRUE
, stream
);
192 static void rot_entry_delete(struct rot_entry
*rot_entry
)
194 if (rot_entry
->cookie
)
196 InterfaceData
*object
= NULL
;
197 InterfaceData
*moniker
= NULL
;
200 IrotRevoke(get_irot_handle(), rot_entry
->cookie
,
201 &rot_entry
->ctxt_handle
, &object
, &moniker
);
207 MIDL_user_free(object
);
212 hr
= create_stream_on_mip_ro(moniker
, &stream
);
215 CoReleaseMarshalData(stream
);
216 IStream_Release(stream
);
219 MIDL_user_free(moniker
);
221 if (rot_entry
->object
)
225 hr
= create_stream_on_mip_ro(rot_entry
->object
, &stream
);
228 CoReleaseMarshalData(stream
);
229 IStream_Release(stream
);
232 HeapFree(GetProcessHeap(), 0, rot_entry
->object
);
233 HeapFree(GetProcessHeap(), 0, rot_entry
->moniker_data
);
234 HeapFree(GetProcessHeap(), 0, rot_entry
);
237 /* moniker_data must be freed with HeapFree when no longer in use */
238 static HRESULT
get_moniker_comparison_data(IMoniker
*pMoniker
, MonikerComparisonData
**moniker_data
)
241 IROTData
*pROTData
= NULL
;
242 hr
= IMoniker_QueryInterface(pMoniker
, &IID_IROTData
, (void *)&pROTData
);
245 ULONG size
= MAX_COMPARISON_DATA
;
246 *moniker_data
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MonikerComparisonData
, abData
[size
]));
249 IROTData_Release(pROTData
);
250 return E_OUTOFMEMORY
;
252 hr
= IROTData_GetComparisonData(pROTData
, (*moniker_data
)->abData
, size
, &size
);
253 IROTData_Release(pROTData
);
256 ERR("Failed to copy comparison data into buffer, hr = 0x%08x\n", hr
);
257 HeapFree(GetProcessHeap(), 0, *moniker_data
);
260 (*moniker_data
)->ulCntData
= size
;
265 LPOLESTR pszDisplayName
;
269 TRACE("generating comparison data from display name\n");
271 hr
= CreateBindCtx(0, &pbc
);
274 hr
= IMoniker_GetDisplayName(pMoniker
, pbc
, NULL
, &pszDisplayName
);
275 IBindCtx_Release(pbc
);
278 hr
= IMoniker_GetClassID(pMoniker
, &clsid
);
281 CoTaskMemFree(pszDisplayName
);
285 len
= strlenW(pszDisplayName
);
286 *moniker_data
= HeapAlloc(GetProcessHeap(), 0,
287 FIELD_OFFSET(MonikerComparisonData
, abData
[sizeof(CLSID
) + (len
+1)*sizeof(WCHAR
)]));
290 CoTaskMemFree(pszDisplayName
);
291 return E_OUTOFMEMORY
;
293 (*moniker_data
)->ulCntData
= sizeof(CLSID
) + (len
+1)*sizeof(WCHAR
);
295 memcpy(&(*moniker_data
)->abData
[0], &clsid
, sizeof(clsid
));
296 memcpy(&(*moniker_data
)->abData
[sizeof(clsid
)], pszDisplayName
, (len
+1)*sizeof(WCHAR
));
297 CoTaskMemFree(pszDisplayName
);
302 static HRESULT
reduce_moniker(IMoniker
*pmk
, IBindCtx
*pbc
, IMoniker
**pmkReduced
)
304 IBindCtx
*pbcNew
= NULL
;
308 hr
= CreateBindCtx(0, &pbcNew
);
313 hr
= IMoniker_Reduce(pmk
, pbc
, MKRREDUCE_ALL
, NULL
, pmkReduced
);
315 ERR("reducing moniker failed with error 0x%08x\n", hr
);
316 if (pbcNew
) IBindCtx_Release(pbcNew
);
320 /***********************************************************************
321 * RunningObjectTable_QueryInterface
323 static HRESULT WINAPI
324 RunningObjectTableImpl_QueryInterface(IRunningObjectTable
* iface
,
325 REFIID riid
,void** ppvObject
)
327 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
329 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
331 /* validate arguments */
338 if (IsEqualIID(&IID_IUnknown
, riid
) ||
339 IsEqualIID(&IID_IRunningObjectTable
, riid
))
340 *ppvObject
= &This
->IRunningObjectTable_iface
;
343 return E_NOINTERFACE
;
345 IRunningObjectTable_AddRef(iface
);
350 /***********************************************************************
351 * RunningObjectTable_AddRef
354 RunningObjectTableImpl_AddRef(IRunningObjectTable
* iface
)
356 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
358 TRACE("(%p)\n",This
);
360 return InterlockedIncrement(&This
->ref
);
363 /***********************************************************************
364 * RunningObjectTable_Destroy
367 RunningObjectTableImpl_Destroy(void)
369 struct list
*cursor
, *cursor2
;
370 IrotHandle old_handle
;
374 if (runningObjectTableInstance
==NULL
)
377 /* free the ROT table memory */
378 LIST_FOR_EACH_SAFE(cursor
, cursor2
, &runningObjectTableInstance
->rot
)
380 struct rot_entry
*rot_entry
= LIST_ENTRY(cursor
, struct rot_entry
, entry
);
381 list_remove(&rot_entry
->entry
);
382 rot_entry_delete(rot_entry
);
385 DEBUG_CLEAR_CRITSEC_NAME(&runningObjectTableInstance
->lock
);
386 DeleteCriticalSection(&runningObjectTableInstance
->lock
);
388 /* free the ROT structure memory */
389 HeapFree(GetProcessHeap(),0,runningObjectTableInstance
);
390 runningObjectTableInstance
= NULL
;
392 old_handle
= irot_handle
;
395 RpcBindingFree(&old_handle
);
400 /***********************************************************************
401 * RunningObjectTable_Release
404 RunningObjectTableImpl_Release(IRunningObjectTable
* iface
)
406 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
409 TRACE("(%p)\n",This
);
411 ref
= InterlockedDecrement(&This
->ref
);
413 /* uninitialize ROT structure if there are no more references to it */
416 struct list
*cursor
, *cursor2
;
417 LIST_FOR_EACH_SAFE(cursor
, cursor2
, &This
->rot
)
419 struct rot_entry
*rot_entry
= LIST_ENTRY(cursor
, struct rot_entry
, entry
);
420 list_remove(&rot_entry
->entry
);
421 rot_entry_delete(rot_entry
);
423 /* RunningObjectTable data structure will be not destroyed here ! the destruction will be done only
424 * when RunningObjectTableImpl_UnInitialize function is called
431 /***********************************************************************
432 * RunningObjectTable_Register
435 * grfFlags [in] Registration options
436 * punkObject [in] the object being registered
437 * pmkObjectName [in] the moniker of the object being registered
438 * pdwRegister [out] the value identifying the registration
440 static HRESULT WINAPI
441 RunningObjectTableImpl_Register(IRunningObjectTable
* iface
, DWORD grfFlags
,
442 IUnknown
*punkObject
, IMoniker
*pmkObjectName
, DWORD
*pdwRegister
)
444 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
445 struct rot_entry
*rot_entry
;
447 IStream
*pStream
= NULL
;
450 InterfaceData
*moniker
= NULL
;
452 TRACE("(%p,%d,%p,%p,%p)\n",This
,grfFlags
,punkObject
,pmkObjectName
,pdwRegister
);
454 if (grfFlags
& ~(ROTFLAGS_REGISTRATIONKEEPSALIVE
|ROTFLAGS_ALLOWANYCLIENT
))
456 ERR("Invalid grfFlags: 0x%08x\n", grfFlags
& ~(ROTFLAGS_REGISTRATIONKEEPSALIVE
|ROTFLAGS_ALLOWANYCLIENT
));
460 if (punkObject
==NULL
|| pmkObjectName
==NULL
|| pdwRegister
==NULL
)
463 rot_entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*rot_entry
));
465 return E_OUTOFMEMORY
;
468 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
471 rot_entry_delete(rot_entry
);
474 mshlflags
= (grfFlags
& ROTFLAGS_REGISTRATIONKEEPSALIVE
) ? MSHLFLAGS_TABLESTRONG
: MSHLFLAGS_TABLEWEAK
;
475 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, punkObject
, MSHCTX_LOCAL
| MSHCTX_NOSHAREDMEM
, NULL
, mshlflags
);
476 /* FIXME: a cleaner way would be to create an IStream class that writes
477 * directly to an MInterfacePointer */
481 hr
= GetHGlobalFromStream(pStream
, &hglobal
);
484 SIZE_T size
= GlobalSize(hglobal
);
485 const void *pv
= GlobalLock(hglobal
);
486 rot_entry
->object
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MInterfacePointer
, abData
[size
]));
487 rot_entry
->object
->ulCntData
= size
;
488 memcpy(rot_entry
->object
->abData
, pv
, size
);
489 GlobalUnlock(hglobal
);
492 IStream_Release(pStream
);
495 rot_entry_delete(rot_entry
);
499 hr
= CreateBindCtx(0, &pbc
);
502 rot_entry_delete(rot_entry
);
506 hr
= reduce_moniker(pmkObjectName
, pbc
, &pmkObjectName
);
509 rot_entry_delete(rot_entry
);
510 IBindCtx_Release(pbc
);
514 hr
= IMoniker_GetTimeOfLastChange(pmkObjectName
, pbc
, NULL
,
515 &rot_entry
->last_modified
);
516 IBindCtx_Release(pbc
);
519 CoFileTimeNow(&rot_entry
->last_modified
);
523 hr
= get_moniker_comparison_data(pmkObjectName
,
524 &rot_entry
->moniker_data
);
527 rot_entry_delete(rot_entry
);
528 IMoniker_Release(pmkObjectName
);
532 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
535 rot_entry_delete(rot_entry
);
536 IMoniker_Release(pmkObjectName
);
539 /* marshal moniker */
540 hr
= CoMarshalInterface(pStream
, &IID_IMoniker
, (IUnknown
*)pmkObjectName
,
541 MSHCTX_LOCAL
| MSHCTX_NOSHAREDMEM
, NULL
, MSHLFLAGS_TABLESTRONG
);
542 /* FIXME: a cleaner way would be to create an IStream class that writes
543 * directly to an MInterfacePointer */
547 hr
= GetHGlobalFromStream(pStream
, &hglobal
);
550 SIZE_T size
= GlobalSize(hglobal
);
551 const void *pv
= GlobalLock(hglobal
);
552 moniker
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceData
, abData
[size
]));
553 moniker
->ulCntData
= size
;
554 memcpy(moniker
->abData
, pv
, size
);
555 GlobalUnlock(hglobal
);
558 IStream_Release(pStream
);
559 IMoniker_Release(pmkObjectName
);
562 HeapFree(GetProcessHeap(), 0, moniker
);
563 rot_entry_delete(rot_entry
);
572 hr
= IrotRegister(get_irot_handle(), rot_entry
->moniker_data
,
573 rot_entry
->object
, moniker
,
574 &rot_entry
->last_modified
, grfFlags
,
575 &rot_entry
->cookie
, &rot_entry
->ctxt_handle
);
579 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
582 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
589 HeapFree(GetProcessHeap(), 0, moniker
);
592 rot_entry_delete(rot_entry
);
596 /* gives a registration identifier to the registered object*/
597 *pdwRegister
= rot_entry
->cookie
;
599 EnterCriticalSection(&This
->lock
);
600 list_add_tail(&This
->rot
, &rot_entry
->entry
);
601 LeaveCriticalSection(&This
->lock
);
606 /***********************************************************************
607 * RunningObjectTable_Revoke
610 * dwRegister [in] Value identifying registration to be revoked
612 static HRESULT WINAPI
613 RunningObjectTableImpl_Revoke( IRunningObjectTable
* iface
, DWORD dwRegister
)
615 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
616 struct rot_entry
*rot_entry
;
618 TRACE("(%p,%d)\n",This
,dwRegister
);
620 EnterCriticalSection(&This
->lock
);
621 LIST_FOR_EACH_ENTRY(rot_entry
, &This
->rot
, struct rot_entry
, entry
)
623 if (rot_entry
->cookie
== dwRegister
)
625 list_remove(&rot_entry
->entry
);
626 LeaveCriticalSection(&This
->lock
);
628 rot_entry_delete(rot_entry
);
632 LeaveCriticalSection(&This
->lock
);
637 /***********************************************************************
638 * RunningObjectTable_IsRunning
641 * pmkObjectName [in] moniker of the object whose status is desired
643 static HRESULT WINAPI
644 RunningObjectTableImpl_IsRunning( IRunningObjectTable
* iface
, IMoniker
*pmkObjectName
)
646 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
647 MonikerComparisonData
*moniker_data
;
649 const struct rot_entry
*rot_entry
;
651 TRACE("(%p,%p)\n",This
,pmkObjectName
);
653 hr
= reduce_moniker(pmkObjectName
, NULL
, &pmkObjectName
);
656 hr
= get_moniker_comparison_data(pmkObjectName
, &moniker_data
);
657 IMoniker_Release(pmkObjectName
);
662 EnterCriticalSection(&This
->lock
);
663 LIST_FOR_EACH_ENTRY(rot_entry
, &This
->rot
, const struct rot_entry
, entry
)
665 if ((rot_entry
->moniker_data
->ulCntData
== moniker_data
->ulCntData
) &&
666 !memcmp(moniker_data
->abData
, rot_entry
->moniker_data
->abData
, moniker_data
->ulCntData
))
672 LeaveCriticalSection(&This
->lock
);
680 hr
= IrotIsRunning(get_irot_handle(), moniker_data
);
684 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
687 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
696 HeapFree(GetProcessHeap(), 0, moniker_data
);
701 /***********************************************************************
702 * RunningObjectTable_GetObject
705 * pmkObjectName [in] Pointer to the moniker on the object
706 * ppunkObject [out] variable that receives the IUnknown interface pointer
708 static HRESULT WINAPI
709 RunningObjectTableImpl_GetObject( IRunningObjectTable
* iface
,
710 IMoniker
*pmkObjectName
, IUnknown
**ppunkObject
)
712 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
713 MonikerComparisonData
*moniker_data
;
714 InterfaceData
*object
= NULL
;
717 struct rot_entry
*rot_entry
;
719 TRACE("(%p,%p,%p)\n",This
,pmkObjectName
,ppunkObject
);
721 if (ppunkObject
== NULL
)
726 hr
= reduce_moniker(pmkObjectName
, NULL
, &pmkObjectName
);
729 hr
= get_moniker_comparison_data(pmkObjectName
, &moniker_data
);
730 IMoniker_Release(pmkObjectName
);
734 EnterCriticalSection(&This
->lock
);
735 LIST_FOR_EACH_ENTRY(rot_entry
, &This
->rot
, struct rot_entry
, entry
)
737 if ((rot_entry
->moniker_data
->ulCntData
== moniker_data
->ulCntData
) &&
738 !memcmp(moniker_data
->abData
, rot_entry
->moniker_data
->abData
, moniker_data
->ulCntData
))
741 hr
= create_stream_on_mip_ro(rot_entry
->object
, &pStream
);
744 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)ppunkObject
);
745 IStream_Release(pStream
);
748 LeaveCriticalSection(&This
->lock
);
749 HeapFree(GetProcessHeap(), 0, moniker_data
);
754 LeaveCriticalSection(&This
->lock
);
756 TRACE("moniker unavailable locally, calling SCM\n");
762 hr
= IrotGetObject(get_irot_handle(), moniker_data
, &object
, &cookie
);
766 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
769 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
780 hr
= create_stream_on_mip_ro(object
, &pStream
);
783 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)ppunkObject
);
784 IStream_Release(pStream
);
788 WARN("Moniker unavailable, IrotGetObject returned 0x%08x\n", hr
);
790 HeapFree(GetProcessHeap(), 0, moniker_data
);
795 /***********************************************************************
796 * RunningObjectTable_NoteChangeTime
799 * dwRegister [in] Value identifying registration being updated
800 * pfiletime [in] Pointer to structure containing object's last change time
802 static HRESULT WINAPI
803 RunningObjectTableImpl_NoteChangeTime(IRunningObjectTable
* iface
,
804 DWORD dwRegister
, FILETIME
*pfiletime
)
806 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
807 struct rot_entry
*rot_entry
;
808 HRESULT hr
= E_INVALIDARG
;
810 TRACE("(%p,%d,%p)\n",This
,dwRegister
,pfiletime
);
812 EnterCriticalSection(&This
->lock
);
813 LIST_FOR_EACH_ENTRY(rot_entry
, &This
->rot
, struct rot_entry
, entry
)
815 if (rot_entry
->cookie
== dwRegister
)
817 rot_entry
->last_modified
= *pfiletime
;
818 LeaveCriticalSection(&This
->lock
);
824 hr
= IrotNoteChangeTime(get_irot_handle(), dwRegister
, pfiletime
);
828 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
831 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
842 LeaveCriticalSection(&This
->lock
);
845 TRACE("-- 0x08%x\n", hr
);
849 /***********************************************************************
850 * RunningObjectTable_GetTimeOfLastChange
853 * pmkObjectName [in] moniker of the object whose status is desired
854 * pfiletime [out] structure that receives object's last change time
856 static HRESULT WINAPI
857 RunningObjectTableImpl_GetTimeOfLastChange(IRunningObjectTable
* iface
,
858 IMoniker
*pmkObjectName
, FILETIME
*pfiletime
)
860 HRESULT hr
= MK_E_UNAVAILABLE
;
861 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
862 MonikerComparisonData
*moniker_data
;
863 const struct rot_entry
*rot_entry
;
865 TRACE("(%p,%p,%p)\n",This
,pmkObjectName
,pfiletime
);
867 if (pmkObjectName
==NULL
|| pfiletime
==NULL
)
870 hr
= reduce_moniker(pmkObjectName
, NULL
, &pmkObjectName
);
873 hr
= get_moniker_comparison_data(pmkObjectName
, &moniker_data
);
874 IMoniker_Release(pmkObjectName
);
878 hr
= MK_E_UNAVAILABLE
;
880 EnterCriticalSection(&This
->lock
);
881 LIST_FOR_EACH_ENTRY(rot_entry
, &This
->rot
, const struct rot_entry
, entry
)
883 if ((rot_entry
->moniker_data
->ulCntData
== moniker_data
->ulCntData
) &&
884 !memcmp(moniker_data
->abData
, rot_entry
->moniker_data
->abData
, moniker_data
->ulCntData
))
886 *pfiletime
= rot_entry
->last_modified
;
891 LeaveCriticalSection(&This
->lock
);
899 hr
= IrotGetTimeOfLastChange(get_irot_handle(), moniker_data
, pfiletime
);
903 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
906 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
915 HeapFree(GetProcessHeap(), 0, moniker_data
);
917 TRACE("-- 0x%08x\n", hr
);
921 /***********************************************************************
922 * RunningObjectTable_EnumRunning
925 * ppenumMoniker [out] receives the IEnumMoniker interface pointer
927 static HRESULT WINAPI
928 RunningObjectTableImpl_EnumRunning(IRunningObjectTable
* iface
,
929 IEnumMoniker
**ppenumMoniker
)
931 RunningObjectTableImpl
*This
= impl_from_IRunningObjectTable(iface
);
932 InterfaceList
*interface_list
= NULL
;
935 TRACE("(%p, %p)\n", This
, ppenumMoniker
);
937 *ppenumMoniker
= NULL
;
943 hr
= IrotEnumRunning(get_irot_handle(), &interface_list
);
947 hr
= HRESULT_FROM_WIN32(GetExceptionCode());
950 if (hr
== HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE
))
959 hr
= EnumMonikerImpl_CreateEnumROTMoniker(interface_list
,
965 /* Virtual function table for the IRunningObjectTable class. */
966 static const IRunningObjectTableVtbl VT_RunningObjectTableImpl
=
968 RunningObjectTableImpl_QueryInterface
,
969 RunningObjectTableImpl_AddRef
,
970 RunningObjectTableImpl_Release
,
971 RunningObjectTableImpl_Register
,
972 RunningObjectTableImpl_Revoke
,
973 RunningObjectTableImpl_IsRunning
,
974 RunningObjectTableImpl_GetObject
,
975 RunningObjectTableImpl_NoteChangeTime
,
976 RunningObjectTableImpl_GetTimeOfLastChange
,
977 RunningObjectTableImpl_EnumRunning
980 /***********************************************************************
981 * RunningObjectTable_Initialize
983 HRESULT WINAPI
RunningObjectTableImpl_Initialize(void)
987 /* create the unique instance of the RunningObjectTableImpl structure */
988 runningObjectTableInstance
= HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl
));
990 if (!runningObjectTableInstance
)
991 return E_OUTOFMEMORY
;
993 /* initialize the virtual table function */
994 runningObjectTableInstance
->IRunningObjectTable_iface
.lpVtbl
= &VT_RunningObjectTableImpl
;
996 /* the initial reference is set to "1" so that it isn't destroyed after its
997 * first use until the process is destroyed, as the running object table is
998 * a process-wide cache of a global table */
999 runningObjectTableInstance
->ref
= 1;
1001 list_init(&runningObjectTableInstance
->rot
);
1002 InitializeCriticalSection(&runningObjectTableInstance
->lock
);
1003 DEBUG_SET_CRITSEC_NAME(&runningObjectTableInstance
->lock
, "RunningObjectTableImpl.lock");
1008 /***********************************************************************
1009 * RunningObjectTable_UnInitialize
1011 HRESULT WINAPI
RunningObjectTableImpl_UnInitialize(void)
1015 if (runningObjectTableInstance
==NULL
)
1018 RunningObjectTableImpl_Release(&runningObjectTableInstance
->IRunningObjectTable_iface
);
1020 RunningObjectTableImpl_Destroy();
1025 /***********************************************************************
1026 * GetRunningObjectTable (OLE32.@)
1028 * Retrieves the global running object table.
1031 * reserved [I] Reserved. Set to 0.
1032 * pprot [O] Address that receives the pointer to the running object table.
1036 * Failure: Any HRESULT code.
1039 GetRunningObjectTable(DWORD reserved
, LPRUNNINGOBJECTTABLE
*pprot
)
1041 IID riid
=IID_IRunningObjectTable
;
1047 return E_UNEXPECTED
;
1049 if(runningObjectTableInstance
==NULL
)
1050 return CO_E_NOTINITIALIZED
;
1052 res
= IRunningObjectTable_QueryInterface(&runningObjectTableInstance
->IRunningObjectTable_iface
,
1053 &riid
,(void**)pprot
);
1058 static HRESULT
get_moniker_for_progid_display_name(LPBC pbc
,
1059 LPCOLESTR szDisplayName
,
1066 LPCWSTR start
= szDisplayName
;
1069 IMoniker
*class_moniker
;
1074 /* find end delimiter */
1075 for (end
= start
; *end
; end
++)
1081 /* must start with '@' or have a ':' somewhere and mustn't be one character
1082 * long (since that looks like an absolute path) */
1083 if (((start
== szDisplayName
) && (*end
== '\0')) || (len
<= 1))
1086 progid
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1089 memcpy(progid
, start
, len
* sizeof(WCHAR
));
1092 hr
= CLSIDFromProgID(progid
, &clsid
);
1093 HeapFree(GetProcessHeap(), 0, progid
);
1097 hr
= CreateClassMoniker(&clsid
, &class_moniker
);
1100 IParseDisplayName
*pdn
;
1101 hr
= IMoniker_BindToObject(class_moniker
, pbc
, NULL
,
1102 &IID_IParseDisplayName
, (void **)&pdn
);
1103 /* fallback to using IClassFactory to get IParseDisplayName -
1104 * adsldp.dll depends on this */
1108 hr
= IMoniker_BindToObject(class_moniker
, pbc
, NULL
,
1109 &IID_IClassFactory
, (void **)&pcf
);
1112 hr
= IClassFactory_CreateInstance(pcf
, NULL
,
1113 &IID_IParseDisplayName
,
1115 IClassFactory_Release(pcf
);
1118 IMoniker_Release(class_moniker
);
1121 hr
= IParseDisplayName_ParseDisplayName(pdn
, pbc
,
1122 (LPOLESTR
)szDisplayName
,
1124 IParseDisplayName_Release(pdn
);
1130 /******************************************************************************
1131 * MkParseDisplayName [OLE32.@]
1133 HRESULT WINAPI
MkParseDisplayName(LPBC pbc
, LPCOLESTR szDisplayName
,
1134 LPDWORD pchEaten
, LPMONIKER
*ppmk
)
1136 HRESULT hr
= MK_E_SYNTAX
;
1137 static const WCHAR wszClsidColon
[] = {'c','l','s','i','d',':'};
1141 TRACE("(%p, %s, %p, %p)\n", pbc
, debugstr_w(szDisplayName
), pchEaten
, ppmk
);
1143 if (!pbc
|| !IsValidInterface((LPUNKNOWN
) pbc
))
1144 return E_INVALIDARG
;
1146 if (!szDisplayName
|| !*szDisplayName
)
1147 return E_INVALIDARG
;
1149 if (!pchEaten
|| !ppmk
)
1150 return E_INVALIDARG
;
1155 if (!strncmpiW(szDisplayName
, wszClsidColon
, ARRAY_SIZE(wszClsidColon
)))
1157 hr
= ClassMoniker_CreateFromDisplayName(pbc
, szDisplayName
, &chEaten
, &moniker
);
1158 if (FAILED(hr
) && (hr
!= MK_E_SYNTAX
))
1163 hr
= get_moniker_for_progid_display_name(pbc
, szDisplayName
, &chEaten
, &moniker
);
1164 if (FAILED(hr
) && (hr
!= MK_E_SYNTAX
))
1170 hr
= FileMoniker_CreateFromDisplayName(pbc
, szDisplayName
, &chEaten
, &moniker
);
1171 if (FAILED(hr
) && (hr
!= MK_E_SYNTAX
))
1179 IMoniker
*next_moniker
;
1180 *pchEaten
+= chEaten
;
1181 szDisplayName
+= chEaten
;
1182 if (!*szDisplayName
)
1188 hr
= IMoniker_ParseDisplayName(moniker
, pbc
, NULL
,
1189 (LPOLESTR
)szDisplayName
, &chEaten
,
1191 IMoniker_Release(moniker
);
1197 moniker
= next_moniker
;
1204 /***********************************************************************
1205 * GetClassFile (OLE32.@)
1207 * Retrieves the class ID associated with the given filename.
1210 * filePathName [I] Filename to retrieve the class ID for.
1211 * pclsid [O] Address that receives the class ID for the file.
1215 * Failure: Any HRESULT code.
1217 HRESULT WINAPI
GetClassFile(LPCOLESTR filePathName
,CLSID
*pclsid
)
1221 int nbElm
, length
, i
;
1222 LONG sizeProgId
, ret
;
1223 LPOLESTR
*pathDec
=0,absFile
=0,progId
=0;
1225 static const WCHAR bkslashW
[] = {'\\',0};
1226 static const WCHAR dotW
[] = {'.',0};
1228 TRACE("%s, %p\n", debugstr_w(filePathName
), pclsid
);
1230 /* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/
1231 if((StgIsStorageFile(filePathName
))==S_OK
){
1233 res
=StgOpenStorage(filePathName
,NULL
,STGM_READ
| STGM_SHARE_DENY_WRITE
,NULL
,0,&pstg
);
1235 if (SUCCEEDED(res
)) {
1236 res
=ReadClassStg(pstg
,pclsid
);
1237 IStorage_Release(pstg
);
1242 /* If the file is not a storage object then attempt to match various bits in the file against a
1243 pattern in the registry. This case is not frequently used, so I present only the pseudocode for
1246 for(i=0;i<nFileTypes;i++)
1248 for(i=0;j<nPatternsForType;j++){
1253 pat=ReadPatternFromRegistry(i,j);
1254 hFile=CreateFileW(filePathName,,,,,,hFile);
1255 SetFilePosition(hFile,pat.offset);
1256 ReadFile(hFile,buf,pat.size,&r,NULL);
1257 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1259 *pclsid=ReadCLSIDFromRegistry(i);
1265 /* if the above strategies fail then search for the extension key in the registry */
1267 /* get the last element (absolute file) in the path name */
1268 nbElm
=FileMonikerImpl_DecomposePath(filePathName
,&pathDec
);
1269 absFile
=pathDec
[nbElm
-1];
1271 /* failed if the path represents a directory and not an absolute file name*/
1272 if (!lstrcmpW(absFile
, bkslashW
)) {
1273 CoTaskMemFree(pathDec
);
1274 return MK_E_INVALIDEXTENSION
;
1277 /* get the extension of the file */
1279 length
=lstrlenW(absFile
);
1280 for(i
= length
-1; (i
>= 0) && *(extension
= &absFile
[i
]) != '.'; i
--)
1283 if (!extension
|| !lstrcmpW(extension
, dotW
)) {
1284 CoTaskMemFree(pathDec
);
1285 return MK_E_INVALIDEXTENSION
;
1288 ret
= RegQueryValueW(HKEY_CLASSES_ROOT
, extension
, NULL
, &sizeProgId
);
1290 /* get the progId associated to the extension */
1291 progId
= CoTaskMemAlloc(sizeProgId
);
1292 ret
= RegQueryValueW(HKEY_CLASSES_ROOT
, extension
, progId
, &sizeProgId
);
1294 /* return the clsid associated to the progId */
1295 res
= CLSIDFromProgID(progId
, pclsid
);
1297 res
= HRESULT_FROM_WIN32(ret
);
1298 CoTaskMemFree(progId
);
1301 res
= HRESULT_FROM_WIN32(ret
);
1303 for(i
=0; pathDec
[i
]!=NULL
;i
++)
1304 CoTaskMemFree(pathDec
[i
]);
1305 CoTaskMemFree(pathDec
);
1307 return res
!= S_OK
? MK_E_INVALIDEXTENSION
: res
;
1310 /***********************************************************************
1311 * EnumMoniker_QueryInterface
1313 static HRESULT WINAPI
EnumMonikerImpl_QueryInterface(IEnumMoniker
* iface
,REFIID riid
,void** ppvObject
)
1315 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1317 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
1319 /* validate arguments */
1320 if (ppvObject
== NULL
)
1321 return E_INVALIDARG
;
1325 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IEnumMoniker
, riid
))
1326 *ppvObject
= &This
->IEnumMoniker_iface
;
1328 return E_NOINTERFACE
;
1330 IEnumMoniker_AddRef(iface
);
1334 /***********************************************************************
1335 * EnumMoniker_AddRef
1337 static ULONG WINAPI
EnumMonikerImpl_AddRef(IEnumMoniker
* iface
)
1339 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1341 TRACE("(%p)\n",This
);
1343 return InterlockedIncrement(&This
->ref
);
1346 /***********************************************************************
1347 * EnumMoniker_release
1349 static ULONG WINAPI
EnumMonikerImpl_Release(IEnumMoniker
* iface
)
1351 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1354 TRACE("(%p)\n",This
);
1356 ref
= InterlockedDecrement(&This
->ref
);
1358 /* uninitialize ROT structure if there are no more references to it */
1363 TRACE("(%p) Deleting\n",This
);
1365 for (i
= 0; i
< This
->moniker_list
->size
; i
++)
1366 HeapFree(GetProcessHeap(), 0, This
->moniker_list
->interfaces
[i
]);
1367 HeapFree(GetProcessHeap(), 0, This
->moniker_list
);
1368 HeapFree(GetProcessHeap(), 0, This
);
1373 /***********************************************************************
1376 static HRESULT WINAPI
EnumMonikerImpl_Next(IEnumMoniker
* iface
, ULONG celt
, IMoniker
** rgelt
, ULONG
* pceltFetched
)
1379 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1382 TRACE("(%p) TabCurrentPos %d Tablastindx %d\n", This
, This
->pos
, This
->moniker_list
->size
);
1384 /* retrieve the requested number of moniker from the current position */
1385 for(i
= 0; (This
->pos
< This
->moniker_list
->size
) && (i
< celt
); i
++)
1388 hr
= create_stream_on_mip_ro(This
->moniker_list
->interfaces
[This
->pos
++], &stream
);
1389 if (hr
!= S_OK
) break;
1390 hr
= CoUnmarshalInterface(stream
, &IID_IMoniker
, (void **)&rgelt
[i
]);
1391 IStream_Release(stream
);
1392 if (hr
!= S_OK
) break;
1395 if (pceltFetched
!= NULL
)
1408 /***********************************************************************
1411 static HRESULT WINAPI
EnumMonikerImpl_Skip(IEnumMoniker
* iface
, ULONG celt
)
1413 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1415 TRACE("(%p)\n",This
);
1417 if (This
->pos
+ celt
>= This
->moniker_list
->size
)
1425 /***********************************************************************
1428 static HRESULT WINAPI
EnumMonikerImpl_Reset(IEnumMoniker
* iface
)
1430 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1432 This
->pos
= 0; /* set back to start of list */
1434 TRACE("(%p)\n",This
);
1439 /***********************************************************************
1442 static HRESULT WINAPI
EnumMonikerImpl_Clone(IEnumMoniker
* iface
, IEnumMoniker
** ppenum
)
1444 EnumMonikerImpl
*This
= impl_from_IEnumMoniker(iface
);
1445 InterfaceList
*moniker_list
;
1448 TRACE("(%p)\n",This
);
1452 moniker_list
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceList
, interfaces
[This
->moniker_list
->size
]));
1454 return E_OUTOFMEMORY
;
1456 moniker_list
->size
= This
->moniker_list
->size
;
1457 for (i
= 0; i
< This
->moniker_list
->size
; i
++)
1459 SIZE_T size
= FIELD_OFFSET(InterfaceData
, abData
[This
->moniker_list
->interfaces
[i
]->ulCntData
]);
1460 moniker_list
->interfaces
[i
] = HeapAlloc(GetProcessHeap(), 0, size
);
1461 if (!moniker_list
->interfaces
[i
])
1464 for (i
= 0; i
< end
; i
++)
1465 HeapFree(GetProcessHeap(), 0, moniker_list
->interfaces
[i
]);
1466 HeapFree(GetProcessHeap(), 0, moniker_list
);
1467 return E_OUTOFMEMORY
;
1469 memcpy(moniker_list
->interfaces
[i
], This
->moniker_list
->interfaces
[i
], size
);
1472 /* copy the enum structure */
1473 return EnumMonikerImpl_CreateEnumROTMoniker(moniker_list
, This
->pos
, ppenum
);
1476 /* Virtual function table for the IEnumMoniker class. */
1477 static const IEnumMonikerVtbl VT_EnumMonikerImpl
=
1479 EnumMonikerImpl_QueryInterface
,
1480 EnumMonikerImpl_AddRef
,
1481 EnumMonikerImpl_Release
,
1482 EnumMonikerImpl_Next
,
1483 EnumMonikerImpl_Skip
,
1484 EnumMonikerImpl_Reset
,
1485 EnumMonikerImpl_Clone
1488 /***********************************************************************
1489 * EnumMonikerImpl_CreateEnumROTMoniker
1490 * Used by EnumRunning to create the structure and EnumClone
1491 * to copy the structure
1493 static HRESULT
EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList
*moniker_list
,
1495 IEnumMoniker
**ppenumMoniker
)
1497 EnumMonikerImpl
* This
= NULL
;
1500 return E_INVALIDARG
;
1502 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl
));
1503 if (!This
) return E_OUTOFMEMORY
;
1505 TRACE("(%p)\n", This
);
1507 /* initialize the virtual table function */
1508 This
->IEnumMoniker_iface
.lpVtbl
= &VT_EnumMonikerImpl
;
1510 /* the initial reference is set to "1" */
1511 This
->ref
= 1; /* set the ref count to one */
1512 This
->pos
= current_pos
; /* Set the list start posn */
1513 This
->moniker_list
= moniker_list
;
1515 *ppenumMoniker
= &This
->IEnumMoniker_iface
;
1521 /* Shared implementation of moniker marshaler based on saving and loading of
1524 typedef struct MonikerMarshal
1526 IUnknown IUnknown_iface
;
1527 IMarshal IMarshal_iface
;
1533 static inline MonikerMarshal
*impl_from_IUnknown(IUnknown
*iface
)
1535 return CONTAINING_RECORD(iface
, MonikerMarshal
, IUnknown_iface
);
1538 static inline MonikerMarshal
*impl_from_IMarshal( IMarshal
*iface
)
1540 return CONTAINING_RECORD(iface
, MonikerMarshal
, IMarshal_iface
);
1543 static HRESULT WINAPI
MonikerMarshalInner_QueryInterface(IUnknown
*iface
, REFIID riid
, LPVOID
*ppv
)
1545 MonikerMarshal
*This
= impl_from_IUnknown(iface
);
1546 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
1548 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IMarshal
, riid
))
1550 *ppv
= &This
->IMarshal_iface
;
1551 IMarshal_AddRef(&This
->IMarshal_iface
);
1554 FIXME("No interface for %s\n", debugstr_guid(riid
));
1555 return E_NOINTERFACE
;
1558 static ULONG WINAPI
MonikerMarshalInner_AddRef(IUnknown
*iface
)
1560 MonikerMarshal
*This
= impl_from_IUnknown(iface
);
1561 return InterlockedIncrement(&This
->ref
);
1564 static ULONG WINAPI
MonikerMarshalInner_Release(IUnknown
*iface
)
1566 MonikerMarshal
*This
= impl_from_IUnknown(iface
);
1567 ULONG ref
= InterlockedDecrement(&This
->ref
);
1569 if (!ref
) HeapFree(GetProcessHeap(), 0, This
);
1573 static const IUnknownVtbl VT_MonikerMarshalInner
=
1575 MonikerMarshalInner_QueryInterface
,
1576 MonikerMarshalInner_AddRef
,
1577 MonikerMarshalInner_Release
1580 static HRESULT WINAPI
MonikerMarshal_QueryInterface(IMarshal
*iface
, REFIID riid
, LPVOID
*ppv
)
1582 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1583 return IMoniker_QueryInterface(This
->moniker
, riid
, ppv
);
1586 static ULONG WINAPI
MonikerMarshal_AddRef(IMarshal
*iface
)
1588 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1589 return IMoniker_AddRef(This
->moniker
);
1592 static ULONG WINAPI
MonikerMarshal_Release(IMarshal
*iface
)
1594 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1595 return IMoniker_Release(This
->moniker
);
1598 static HRESULT WINAPI
MonikerMarshal_GetUnmarshalClass(
1599 LPMARSHAL iface
, REFIID riid
, void* pv
, DWORD dwDestContext
,
1600 void* pvDestContext
, DWORD mshlflags
, CLSID
* pCid
)
1602 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1604 TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid
), pv
,
1605 dwDestContext
, pvDestContext
, mshlflags
, pCid
);
1607 return IMoniker_GetClassID(This
->moniker
, pCid
);
1610 static HRESULT WINAPI
MonikerMarshal_GetMarshalSizeMax(
1611 LPMARSHAL iface
, REFIID riid
, void* pv
, DWORD dwDestContext
,
1612 void* pvDestContext
, DWORD mshlflags
, DWORD
* pSize
)
1614 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1616 ULARGE_INTEGER size
;
1618 TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid
), pv
,
1619 dwDestContext
, pvDestContext
, mshlflags
, pSize
);
1621 hr
= IMoniker_GetSizeMax(This
->moniker
, &size
);
1623 *pSize
= (DWORD
)size
.QuadPart
;
1627 static HRESULT WINAPI
MonikerMarshal_MarshalInterface(LPMARSHAL iface
, IStream
*pStm
,
1628 REFIID riid
, void* pv
, DWORD dwDestContext
,
1629 void* pvDestContext
, DWORD mshlflags
)
1631 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1633 TRACE("(%p, %s, %p, %x, %p, %x)\n", pStm
, debugstr_guid(riid
), pv
,
1634 dwDestContext
, pvDestContext
, mshlflags
);
1636 return IMoniker_Save(This
->moniker
, pStm
, FALSE
);
1639 static HRESULT WINAPI
MonikerMarshal_UnmarshalInterface(LPMARSHAL iface
, IStream
*pStm
, REFIID riid
, void **ppv
)
1641 MonikerMarshal
*This
= impl_from_IMarshal(iface
);
1644 TRACE("(%p, %s, %p)\n", pStm
, debugstr_guid(riid
), ppv
);
1646 hr
= IMoniker_Load(This
->moniker
, pStm
);
1648 hr
= IMoniker_QueryInterface(This
->moniker
, riid
, ppv
);
1652 static HRESULT WINAPI
MonikerMarshal_ReleaseMarshalData(LPMARSHAL iface
, IStream
*pStm
)
1655 /* can't release a state-based marshal as nothing on server side to
1660 static HRESULT WINAPI
MonikerMarshal_DisconnectObject(LPMARSHAL iface
, DWORD dwReserved
)
1663 /* can't disconnect a state-based marshal as nothing on server side to
1664 * disconnect from */
1668 static const IMarshalVtbl VT_MonikerMarshal
=
1670 MonikerMarshal_QueryInterface
,
1671 MonikerMarshal_AddRef
,
1672 MonikerMarshal_Release
,
1673 MonikerMarshal_GetUnmarshalClass
,
1674 MonikerMarshal_GetMarshalSizeMax
,
1675 MonikerMarshal_MarshalInterface
,
1676 MonikerMarshal_UnmarshalInterface
,
1677 MonikerMarshal_ReleaseMarshalData
,
1678 MonikerMarshal_DisconnectObject
1681 HRESULT
MonikerMarshal_Create(IMoniker
*inner
, IUnknown
**outer
)
1683 MonikerMarshal
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1684 if (!This
) return E_OUTOFMEMORY
;
1686 This
->IUnknown_iface
.lpVtbl
= &VT_MonikerMarshalInner
;
1687 This
->IMarshal_iface
.lpVtbl
= &VT_MonikerMarshal
;
1689 This
->moniker
= inner
;
1691 *outer
= &This
->IUnknown_iface
;
1695 void * __RPC_USER
MIDL_user_allocate(SIZE_T size
)
1697 return HeapAlloc(GetProcessHeap(), 0, size
);
1700 void __RPC_USER
MIDL_user_free(void *p
)
1702 HeapFree(GetProcessHeap(), 0, p
);