source: trunk/src/ole32/moniker.cpp@ 291

Last change on this file since 291 was 291, checked in by davidr, 26 years ago

Updated clsid handling to correctly draw textual clsid's
Fixed GUID instansiation.
Moved initialisation to OLE32.CPP
Added many new APIs incl. CoCreateInstance & CoGetClassObject.
Many partially implemented stubs completed and moved to OLE32.CPP
Running Object Table implemented (Moniker.cpp)
IMalloc & Task Memory implemented.

File size: 14.9 KB
Line 
1/*
2 *
3 * Project Odin Software License can be found in LICENSE.TXT
4 *
5 */
6/*
7 * COM Monikers.
8 *
9 * 1/7/99
10 *
11 * Copyright 1999 David J. Raison
12 *
13 * Some portions from Wine Implementation
14 * Copyright 1998 Marcus Meissner
15 * Copyright 1999 Noomen Hamza
16 */
17
18#include "ole32.h"
19
20#include "moniker.h"
21
22// ======================================================================
23// DATA
24// ======================================================================
25
26// Singleton instance of ROT
27RunningObjectTableImpl * runningObjectTableInstance = 0;
28
29// VTABLE instance
30static ICOM_VTABLE(IRunningObjectTable) VT_RunningObjectTableImpl =
31{
32 RunningObjectTableImpl_QueryInterface,
33 RunningObjectTableImpl_AddRef,
34 RunningObjectTableImpl_Release,
35 RunningObjectTableImpl_Register,
36 RunningObjectTableImpl_Revoke,
37 RunningObjectTableImpl_IsRunning,
38 RunningObjectTableImpl_GetObject,
39 RunningObjectTableImpl_NoteChangeTime,
40 RunningObjectTableImpl_GetTimeOfLastChange,
41 RunningObjectTableImpl_EnumRunning
42};
43
44// ======================================================================
45// Local Methods
46// ======================================================================
47
48// ----------------------------------------------------------------------
49// Initialize
50// ----------------------------------------------------------------------
51HRESULT RunningObjectTableImpl_Initialize()
52{
53 // create singleton ROT
54 runningObjectTableInstance = (RunningObjectTableImpl *)
55 HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));
56
57 if (runningObjectTableInstance == 0)
58 return E_OUTOFMEMORY;
59
60 /* initialize the virtual table function */
61 runningObjectTableInstance->lpvtbl = &VT_RunningObjectTableImpl;
62 runningObjectTableInstance->ref = 1;
63 runningObjectTableInstance->runObjTabSize = ROT_BLOCK_SIZE;
64 runningObjectTableInstance->runObjTabRegister = 0;
65 runningObjectTableInstance->runObjTabLastIndx = 0;
66 runningObjectTableInstance->runObjTab = (RunObject *)
67 HeapAlloc(GetProcessHeap(), 0, sizeof(RunObject[ROT_BLOCK_SIZE]));
68
69 if (runningObjectTableInstance->runObjTab == NULL)
70 return E_OUTOFMEMORY;
71
72 return S_OK;
73}
74
75// ----------------------------------------------------------------------
76// UnInitialize
77// ----------------------------------------------------------------------
78HRESULT RunningObjectTableImpl_UnInitialize()
79{
80 RunningObjectTableImpl_Release((IRunningObjectTable * )runningObjectTableInstance);
81 Destroy();
82
83 return S_OK;
84}
85
86// ----------------------------------------------------------------------
87// Destroy
88// ----------------------------------------------------------------------
89static HRESULT Destroy()
90{
91 HeapFree(GetProcessHeap(), 0, runningObjectTableInstance->runObjTab);
92 HeapFree(GetProcessHeap(), 0, runningObjectTableInstance);
93
94 return S_OK;
95}
96
97// ----------------------------------------------------------------------
98// GetObjectIndex
99// ----------------------------------------------------------------------
100static HRESULT GetObjectIndex(RunningObjectTableImpl * This, DWORD identReg,
101 IMoniker * pmk, DWORD * indx)
102{
103 DWORD i;
104
105 if (pmk != NULL)
106 /* search object identified by a moniker*/
107 for(i = 0; (i < This->runObjTabLastIndx) && (!IMoniker_IsEqual(This->runObjTab[i].pmkObj, pmk) == S_OK); i++)
108 ;
109 else
110 /* search object identified by a register identifier*/
111 for(i = 0; ((i<This->runObjTabLastIndx) && (This->runObjTab[i].identRegObj != identReg)); i++)
112 ;
113
114 if (i == This->runObjTabLastIndx)
115 return S_FALSE;
116
117 if (indx != NULL)
118 *indx = i;
119
120 return S_OK;
121}
122
123// ======================================================================
124// COM INTERFACE FUNCTIONS
125// ======================================================================
126
127// ----------------------------------------------------------------------
128// RunningObjectTableImpl_QueryInterface
129// ----------------------------------------------------------------------
130HRESULT WIN32API RunningObjectTableImpl_QueryInterface
131 (IRunningObjectTable * iface,
132 REFIID riid,
133 void**ppvObject)
134{
135 ICOM_THIS(RunningObjectTableImpl, iface);
136
137 dprintf(("OLE32: RunningObjectTableImpl_QueryInterface(%p, %p, %p)", This, riid, ppvObject));
138
139 /* validate arguments*/
140 if (This == 0)
141 return CO_E_NOTINITIALIZED;
142
143 if (ppvObject == 0)
144 return E_INVALIDARG;
145
146 * ppvObject = 0;
147
148 if (IsEqualIID(IID_IUnknown, riid))
149 * ppvObject = (IRunningObjectTable * )This;
150 else
151 if (IsEqualIID(IID_IRunningObjectTable, riid))
152 * ppvObject = (IRunningObjectTable * )This;
153
154 if ((* ppvObject) == 0)
155 return E_NOINTERFACE;
156
157 RunningObjectTableImpl_AddRef(iface);
158
159 return S_OK;
160}
161
162// ----------------------------------------------------------------------
163// RunningObjectTableImpl_AddRef
164// ----------------------------------------------------------------------
165ULONG WIN32API RunningObjectTableImpl_AddRef
166 (IRunningObjectTable * iface)
167{
168 ICOM_THIS(RunningObjectTableImpl, iface);
169
170 dprintf(("OLE32: RunningObjectTableImpl_AddRef(%p)", This));
171
172 return ++(This->ref);
173}
174
175// ----------------------------------------------------------------------
176// RunningObjectTableImpl_Release
177// ----------------------------------------------------------------------
178ULONG WIN32API RunningObjectTableImpl_Release
179 (IRunningObjectTable * iface)
180{
181 ICOM_THIS(RunningObjectTableImpl, iface);
182
183 DWORD i;
184
185 dprintf(("OLE32: RunningObjectTableImpl_Release(%p)", This));
186
187 This->ref--;
188
189 /* unitialize ROT structure if there's no more reference to it*/
190 if (This->ref == 0){
191
192 /* release all registred objects */
193 for( i = 0; i < This->runObjTabLastIndx; i++)
194 {
195 if (( This->runObjTab[i].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0)
196 IUnknown_Release(This->runObjTab[i].pObj);
197
198 IMoniker_Release(This->runObjTab[i].pmkObj);
199 }
200
201 /*
202 * RunningObjectTable data structure will be not destroyed here !
203 * The destruction will be done only
204 * when RunningObjectTableImpl_UnInitialize function is called
205 */
206
207 /* there's no more elements in the table */
208 This->runObjTabRegister = 0;
209 This->runObjTabLastIndx = 0;
210
211 return 0;
212 }
213
214 return This->ref;
215}
216
217// ----------------------------------------------------------------------
218// RunningObjectTableImpl_Register
219// ----------------------------------------------------------------------
220HRESULT WIN32API RunningObjectTableImpl_Register
221 (IRunningObjectTable * iface,
222 DWORD grfFlags, /* Registration options */
223 IUnknown * punkObject, /* Pointer to the object being registered */
224 IMoniker * pmkObjectName, /* Pointer to the moniker of the object being registered */
225 DWORD * pdwRegister) /* Pointer to the value identifying the registration */
226{
227 ICOM_THIS(RunningObjectTableImpl, iface);
228
229 dprintf(("OLE32: RunningObjectTableImpl_Register(%p, %ld, %p, %p, %p)", This, grfFlags, punkObject, pmkObjectName, pdwRegister));
230
231 HRESULT res = S_OK;
232
233 /* there's only two types of register : strong and or weak registration (only one must be passed on parameter) */
234 if ( ( (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || !(grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
235 (!(grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || (grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
236 (grfFlags) )
237 return E_INVALIDARG;
238
239 if ((punkObject == NULL) || (pmkObjectName == NULL) || (pdwRegister == NULL))
240 return E_INVALIDARG;
241
242 /* verify if the object to be registred was registred befor */
243 if (GetObjectIndex(This, -1, pmkObjectName, NULL) == S_OK)
244 res = MK_S_MONIKERALREADYREGISTERED;
245
246 /* put the new registred object in the first free element in the table */
247 This->runObjTab[This->runObjTabLastIndx].pObj = punkObject;
248 This->runObjTab[This->runObjTabLastIndx].pmkObj = pmkObjectName;
249 This->runObjTab[This->runObjTabLastIndx].regTypeObj = grfFlags;
250 This->runObjTab[This->runObjTabLastIndx].identRegObj = This->runObjTabRegister;
251 CoFileTimeNow(&(This->runObjTab[This->runObjTabLastIndx].lastModifObj));
252
253 /* gives a registration identifier to the registred object*/
254 (* pdwRegister)= This->runObjTabRegister;
255
256 if (This->runObjTabRegister == 0xFFFFFFFF)
257 {
258 WriteLog("OLE32: Rot_Impl_Register() - runObjTabRegister: %ld overflow! ", This->runObjTabRegister);
259 return E_FAIL;
260 }
261 This->runObjTabRegister++;
262 This->runObjTabLastIndx++;
263
264 if (This->runObjTabLastIndx == This->runObjTabSize)
265 { /* table is full ! so it must be resized */
266
267 This->runObjTabSize += ROT_BLOCK_SIZE; /* newsize table */
268 This->runObjTab = (RunObject *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->runObjTab,
269 This->runObjTabSize * sizeof(RunObject));
270 if (!This->runObjTab)
271 return E_OUTOFMEMORY;
272 }
273 /* add a reference to the object in the strong registration case */
274 if ((grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0 )
275 IUnknown_AddRef(punkObject);
276
277 IMoniker_AddRef(pmkObjectName);
278
279 return res;
280 return S_OK;
281}
282
283// ----------------------------------------------------------------------
284// RunningObjectTableImpl_Revoke
285// ----------------------------------------------------------------------
286HRESULT WIN32API RunningObjectTableImpl_Revoke
287 (IRunningObjectTable * iface,
288 DWORD dwRegister) /* Value identifying registration to be revoked*/
289{
290
291 ICOM_THIS(RunningObjectTableImpl, iface);
292
293 dprintf(("OLE32: RunningObjectTableImpl_Revoke(%p, %ld)", This, dwRegister));
294
295 DWORD index, j;
296
297 /* verify if the object to be revoked was registred befor or not */
298 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
299 return E_INVALIDARG;
300
301 /* release the object if it was registred with a strong registrantion option */
302 if ((This->runObjTab[index].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0)
303 IUnknown_Release(This->runObjTab[index].pObj);
304
305 IMoniker_Release(This->runObjTab[index].pmkObj);
306
307 /* remove the object from the table */
308 for(j = index; j < This->runObjTabLastIndx - 1; j++)
309 This->runObjTab[j]= This->runObjTab[j + 1];
310
311 This->runObjTabLastIndx--;
312
313 return S_OK;
314}
315
316// ----------------------------------------------------------------------
317// RunningObjectTableImpl_IsRunning
318// ----------------------------------------------------------------------
319HRESULT WIN32API RunningObjectTableImpl_IsRunning
320 (IRunningObjectTable * iface,
321 IMoniker * pmkObjectName) /* Pointer to the moniker of the object whose status is desired */
322{
323 ICOM_THIS(RunningObjectTableImpl, iface);
324
325 dprintf(("OLE32: RunningObjectTableImpl_IsRunning(%p, %p)", This, pmkObjectName));
326
327 return GetObjectIndex(This, -1, pmkObjectName, NULL);
328}
329
330// ----------------------------------------------------------------------
331// RunningObjectTableImpl_GetObject
332// ----------------------------------------------------------------------
333HRESULT WIN32API RunningObjectTableImpl_GetObject
334 (IRunningObjectTable * iface,
335 IMoniker * pmkObjectName, /* Pointer to the moniker on the object */
336 IUnknown **ppunkObject) /* Address of output variable that receives the IUnknown interface pointer */
337{
338 ICOM_THIS(RunningObjectTableImpl, iface);
339
340 dprintf(("OLE32: RunningObjectTableImpl_GetObject(%p, %p, %p)", This, pmkObjectName, ppunkObject));
341
342 DWORD index;
343
344 if (ppunkObject == NULL)
345 return E_POINTER;
346
347 *ppunkObject = 0;
348
349 /* verify if the object was registred befor or not */
350 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
351 return MK_E_UNAVAILABLE;
352
353 /* add a reference to the object then set output object argument */
354 IUnknown_AddRef(This->runObjTab[index].pObj);
355 *ppunkObject = This->runObjTab[index].pObj;
356
357 return S_OK;
358}
359
360// ----------------------------------------------------------------------
361// RunningObjectTableImpl_NoteChangeTime
362// ----------------------------------------------------------------------
363HRESULT WIN32API RunningObjectTableImpl_NoteChangeTime
364 (IRunningObjectTable * iface,
365 DWORD dwRegister, /* Value identifying registration being updated */
366 FILETIME * pfiletime) /* Pointer to structure containing object's last change time */
367{
368 ICOM_THIS(RunningObjectTableImpl, iface);
369
370 dprintf(( "OLE32: RunningObjectTableImpl_NoteChangeTime(%p, %ld, %p)", This, dwRegister, pfiletime));
371
372 DWORD index=-1;
373
374 /* verify if the object to be changed was registred befor or not */
375 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
376 return E_INVALIDARG;
377
378 /* set the new value of the last time change */
379 This->runObjTab[index].lastModifObj = (* pfiletime);
380
381 return S_OK;
382}
383
384// ----------------------------------------------------------------------
385// RunningObjectTableImpl_GetTimeOfLastChange
386// ----------------------------------------------------------------------
387HRESULT WIN32API RunningObjectTableImpl_GetTimeOfLastChange
388 (IRunningObjectTable * iface,
389 IMoniker * pmkObjectName, /* Pointer to moniker on the object whose status is desired */
390 FILETIME * pfiletime) /* Pointer to structure that receives object's last change time */
391{
392 ICOM_THIS(RunningObjectTableImpl, iface);
393
394 dprintf(( "OLE32: RunningObjectTableImpl_GetTimeOfLastChange(%p, %p, %p)", This, pmkObjectName, pfiletime));
395
396 DWORD index = -1;
397
398 if (pmkObjectName == NULL || pfiletime == NULL)
399 return E_INVALIDARG;
400
401 /* verify if the object was registred befor or not */
402 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
403 return MK_E_UNAVAILABLE;;
404
405 (* pfiletime)= This->runObjTab[index].lastModifObj;
406
407 return S_OK;
408}
409
410// ----------------------------------------------------------------------
411// RunningObjectTableImpl_EnumRunning
412// ----------------------------------------------------------------------
413HRESULT WIN32API RunningObjectTableImpl_EnumRunning
414 (IRunningObjectTable * iface,
415 IEnumMoniker **ppenumMoniker) /* Address of output variable that receives the IEnumMoniker interface pointer */
416{
417 dprintf(( "OLE32: RunningObjectTableImpl_EnumRunning - stub"));
418 return E_NOTIMPL;
419}
420
421// ======================================================================
422// API Methods
423// ======================================================================
424
425// ----------------------------------------------------------------------
426// GetRunningObjectTable
427// ----------------------------------------------------------------------
428HRESULT WIN32API GetRunningObjectTable(DWORD reserved, LPVOID *pprot)
429{
430 IID riid = IID_IRunningObjectTable;
431 HRESULT hr;
432
433 dprintf(("OLE32: GetRunningObjectTable"));
434
435 if (reserved != 0)
436 return E_UNEXPECTED;
437
438 if (runningObjectTableInstance == NULL)
439 return CO_E_NOTINITIALIZED;
440
441 hr = RunningObjectTableImpl_QueryInterface(
442 (IRunningObjectTable*)runningObjectTableInstance, &riid, (void**)pprot);
443
444 return hr;
445}
446
Note: See TracBrowser for help on using the repository browser.