1 | /*
|
---|
2 | * COMPOBJ library
|
---|
3 | *
|
---|
4 | * Copyright 1995 Martin von Loewis
|
---|
5 | * Copyright 1998 Justin Bradford
|
---|
6 | * Copyright 1999 Francis Beaudet
|
---|
7 | * Copyright 1999 Sylvain St-Germain
|
---|
8 | * Copyright 2002 Marcus Meissner
|
---|
9 | *
|
---|
10 | * This library is free software; you can redistribute it and/or
|
---|
11 | * modify it under the terms of the GNU Lesser General Public
|
---|
12 | * License as published by the Free Software Foundation; either
|
---|
13 | * version 2.1 of the License, or (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This library is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * Lesser General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU Lesser General Public
|
---|
21 | * License along with this library; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | #include "config.h"
|
---|
26 |
|
---|
27 | #include <stdlib.h>
|
---|
28 | #include <stdio.h>
|
---|
29 | #include <string.h>
|
---|
30 | #include <assert.h>
|
---|
31 |
|
---|
32 | #include "windef.h"
|
---|
33 | #include "objbase.h"
|
---|
34 | #include "ole2.h"
|
---|
35 | #include "ole2ver.h"
|
---|
36 | #include "rpc.h"
|
---|
37 | #include "winerror.h"
|
---|
38 | #include "winreg.h"
|
---|
39 | #include "wownt32.h"
|
---|
40 | #include "wtypes.h"
|
---|
41 | #include "wine/unicode.h"
|
---|
42 | #include "wine/obj_base.h"
|
---|
43 | #include "wine/obj_clientserver.h"
|
---|
44 | #include "wine/obj_misc.h"
|
---|
45 | #include "wine/obj_marshal.h"
|
---|
46 | #include "wine/obj_storage.h"
|
---|
47 | #include "wine/obj_channel.h"
|
---|
48 | #include "compobj_private.h"
|
---|
49 |
|
---|
50 | #include "wine/debug.h"
|
---|
51 |
|
---|
52 | WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
---|
53 |
|
---|
54 | /****************************************************************************
|
---|
55 | * This section defines variables internal to the COM module.
|
---|
56 | *
|
---|
57 | * TODO: Most of these things will have to be made thread-safe.
|
---|
58 | */
|
---|
59 | HINSTANCE COMPOBJ_hInstance32 = 0;
|
---|
60 |
|
---|
61 | static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid, DWORD dwClsContext, LPUNKNOWN* ppUnk);
|
---|
62 | static void COM_RevokeAllClasses();
|
---|
63 | static void COM_ExternalLockFreeList();
|
---|
64 |
|
---|
65 | /*****************************************************************************
|
---|
66 | * Appartment management stuff
|
---|
67 | *
|
---|
68 | * NOTE:
|
---|
69 | * per Thread values are stored in the TEB on offset 0xF80
|
---|
70 | *
|
---|
71 | * see www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
|
---|
72 | *
|
---|
73 | */
|
---|
74 |
|
---|
75 | typedef struct {
|
---|
76 | unsigned char threadingModell; /* we use the COINIT flags */
|
---|
77 | unsigned long threadID;
|
---|
78 | long AppartmentLockCount;
|
---|
79 | } OleAppartmentData;
|
---|
80 |
|
---|
81 | typedef struct {
|
---|
82 | OleAppartmentData *AppartmentData;
|
---|
83 | } OleThreadData;
|
---|
84 |
|
---|
85 | /* not jet used
|
---|
86 | static CRITICAL_SECTION csAppartmentData = CRITICAL_SECTION_INIT("csAppartmentData");
|
---|
87 | */
|
---|
88 | /*
|
---|
89 | * the first STA created in a process is the main STA
|
---|
90 | */
|
---|
91 |
|
---|
92 | /* not jet used
|
---|
93 | static OleAppartmentData * mainSTA;
|
---|
94 | */
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * a Process can only have one MTA
|
---|
98 | */
|
---|
99 |
|
---|
100 | /* not jet used
|
---|
101 | static OleAppartmentData * processMTA;
|
---|
102 | */
|
---|
103 |
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * This lock count counts the number of times CoInitialize is called. It is
|
---|
107 | * decreased every time CoUninitialize is called. When it hits 0, the COM
|
---|
108 | * libraries are freed
|
---|
109 | */
|
---|
110 | static LONG s_COMLockCount = 0;
|
---|
111 |
|
---|
112 | /*
|
---|
113 | * This linked list contains the list of registered class objects. These
|
---|
114 | * are mostly used to register the factories for out-of-proc servers of OLE
|
---|
115 | * objects.
|
---|
116 | *
|
---|
117 | * TODO: Make this data structure aware of inter-process communication. This
|
---|
118 | * means that parts of this will be exported to the Wine Server.
|
---|
119 | */
|
---|
120 | typedef struct tagRegisteredClass
|
---|
121 | {
|
---|
122 | CLSID classIdentifier;
|
---|
123 | LPUNKNOWN classObject;
|
---|
124 | DWORD runContext;
|
---|
125 | DWORD connectFlags;
|
---|
126 | DWORD dwCookie;
|
---|
127 | HANDLE hThread; /* only for localserver */
|
---|
128 | struct tagRegisteredClass* nextClass;
|
---|
129 | } RegisteredClass;
|
---|
130 |
|
---|
131 | static CRITICAL_SECTION csRegisteredClassList = CRITICAL_SECTION_INIT("csRegisteredClassList");
|
---|
132 | static RegisteredClass* firstRegisteredClass = NULL;
|
---|
133 |
|
---|
134 | /*****************************************************************************
|
---|
135 | * This section contains OpenDllList definitions
|
---|
136 | *
|
---|
137 | * The OpenDllList contains only handles of dll loaded by CoGetClassObject or
|
---|
138 | * other functions what do LoadLibrary _without_ giving back a HMODULE.
|
---|
139 | * Without this list these handles would be freed never.
|
---|
140 | *
|
---|
141 | * FIXME: a DLL what says OK whenn asked for unloading is unloaded in the
|
---|
142 | * next unload-call but not before 600 sec.
|
---|
143 | */
|
---|
144 |
|
---|
145 | typedef struct tagOpenDll {
|
---|
146 | HINSTANCE hLibrary;
|
---|
147 | struct tagOpenDll *next;
|
---|
148 | } OpenDll;
|
---|
149 |
|
---|
150 | static CRITICAL_SECTION csOpenDllList = CRITICAL_SECTION_INIT("csOpenDllList");
|
---|
151 | static OpenDll *openDllList = NULL; /* linked list of open dlls */
|
---|
152 |
|
---|
153 | static void COMPOBJ_DLLList_Add(HANDLE hLibrary);
|
---|
154 | static void COMPOBJ_DllList_FreeUnused(int Timeout);
|
---|
155 |
|
---|
156 |
|
---|
157 | /******************************************************************************
|
---|
158 | * Initialize/Uninitialize critical sections.
|
---|
159 | */
|
---|
160 | void COMPOBJ_InitProcess( void )
|
---|
161 | {
|
---|
162 | }
|
---|
163 |
|
---|
164 | void COMPOBJ_UninitProcess( void )
|
---|
165 | {
|
---|
166 | }
|
---|
167 |
|
---|
168 | /*****************************************************************************
|
---|
169 | * This section contains OpenDllList implemantation
|
---|
170 | */
|
---|
171 |
|
---|
172 | static void COMPOBJ_DLLList_Add(HANDLE hLibrary)
|
---|
173 | {
|
---|
174 | OpenDll *ptr;
|
---|
175 | OpenDll *tmp;
|
---|
176 |
|
---|
177 | TRACE("\n");
|
---|
178 |
|
---|
179 | EnterCriticalSection( &csOpenDllList );
|
---|
180 |
|
---|
181 | if (openDllList == NULL) {
|
---|
182 | /* empty list -- add first node */
|
---|
183 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
---|
184 | openDllList->hLibrary=hLibrary;
|
---|
185 | openDllList->next = NULL;
|
---|
186 | } else {
|
---|
187 | /* search for this dll */
|
---|
188 | int found = FALSE;
|
---|
189 | for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
|
---|
190 | if (ptr->hLibrary == hLibrary) {
|
---|
191 | found = TRUE;
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | if (!found) {
|
---|
196 | /* dll not found, add it */
|
---|
197 | tmp = openDllList;
|
---|
198 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
---|
199 | openDllList->hLibrary = hLibrary;
|
---|
200 | openDllList->next = tmp;
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | LeaveCriticalSection( &csOpenDllList );
|
---|
205 | }
|
---|
206 |
|
---|
207 | static void COMPOBJ_DllList_FreeUnused(int Timeout)
|
---|
208 | {
|
---|
209 | OpenDll *curr, *next, *prev = NULL;
|
---|
210 | typedef HRESULT(*DllCanUnloadNowFunc)(void);
|
---|
211 | DllCanUnloadNowFunc DllCanUnloadNow;
|
---|
212 |
|
---|
213 | TRACE("\n");
|
---|
214 |
|
---|
215 | EnterCriticalSection( &csOpenDllList );
|
---|
216 |
|
---|
217 | for (curr = openDllList; curr != NULL; ) {
|
---|
218 | DllCanUnloadNow = (DllCanUnloadNowFunc) GetProcAddress(curr->hLibrary, "DllCanUnloadNow");
|
---|
219 |
|
---|
220 | if ( (DllCanUnloadNow != NULL) && (DllCanUnloadNow() == S_OK) ) {
|
---|
221 | next = curr->next;
|
---|
222 |
|
---|
223 | TRACE("freeing 0x%08x\n", curr->hLibrary);
|
---|
224 | FreeLibrary(curr->hLibrary);
|
---|
225 |
|
---|
226 | HeapFree(GetProcessHeap(), 0, curr);
|
---|
227 | if (curr == openDllList) {
|
---|
228 | openDllList = next;
|
---|
229 | } else {
|
---|
230 | prev->next = next;
|
---|
231 | }
|
---|
232 |
|
---|
233 | curr = next;
|
---|
234 | } else {
|
---|
235 | prev = curr;
|
---|
236 | curr = curr->next;
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | LeaveCriticalSection( &csOpenDllList );
|
---|
241 | }
|
---|
242 |
|
---|
243 | /******************************************************************************
|
---|
244 | * CoBuildVersion [COMPOBJ.1]
|
---|
245 | * CoBuildVersion [OLE32.4]
|
---|
246 | *
|
---|
247 | * RETURNS
|
---|
248 | * Current build version, hiword is majornumber, loword is minornumber
|
---|
249 | */
|
---|
250 | DWORD WINAPI CoBuildVersion(void)
|
---|
251 | {
|
---|
252 | TRACE("Returning version %d, build %d.\n", rmm, rup);
|
---|
253 | return (rmm<<16)+rup;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /******************************************************************************
|
---|
257 | * CoInitialize [OLE32.26]
|
---|
258 | *
|
---|
259 | * Initializes the COM libraries.
|
---|
260 | *
|
---|
261 | * See CoInitializeEx
|
---|
262 | */
|
---|
263 | HRESULT WINAPI CoInitialize(
|
---|
264 | LPVOID lpReserved /* [in] pointer to win32 malloc interface
|
---|
265 | (obsolete, should be NULL) */
|
---|
266 | )
|
---|
267 | {
|
---|
268 | /*
|
---|
269 | * Just delegate to the newer method.
|
---|
270 | */
|
---|
271 | return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /******************************************************************************
|
---|
275 | * CoInitializeEx [OLE32.163]
|
---|
276 | *
|
---|
277 | * Initializes the COM libraries. The behavior used to set the win32 IMalloc
|
---|
278 | * used for memory management is obsolete.
|
---|
279 | *
|
---|
280 | * RETURNS
|
---|
281 | * S_OK if successful,
|
---|
282 | * S_FALSE if this function was called already.
|
---|
283 | * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
|
---|
284 | * threading model.
|
---|
285 | *
|
---|
286 | * BUGS
|
---|
287 | * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
|
---|
288 | * is never returned.
|
---|
289 | *
|
---|
290 | * See the windows documentation for more details.
|
---|
291 | */
|
---|
292 | HRESULT WINAPI CoInitializeEx(
|
---|
293 | LPVOID lpReserved, /* [in] pointer to win32 malloc interface
|
---|
294 | (obsolete, should be NULL) */
|
---|
295 | DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
|
---|
296 | )
|
---|
297 | {
|
---|
298 | HRESULT hr;
|
---|
299 |
|
---|
300 | TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
|
---|
301 |
|
---|
302 | if (lpReserved!=NULL)
|
---|
303 | {
|
---|
304 | ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
|
---|
305 | }
|
---|
306 |
|
---|
307 | /*
|
---|
308 | * Check for unsupported features.
|
---|
309 | */
|
---|
310 | if (dwCoInit!=COINIT_APARTMENTTHREADED)
|
---|
311 | {
|
---|
312 | FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
|
---|
313 | /* Hope for the best and continue anyway */
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*
|
---|
317 | * Check the lock count. If this is the first time going through the initialize
|
---|
318 | * process, we have to initialize the libraries.
|
---|
319 | *
|
---|
320 | * And crank-up that lock count.
|
---|
321 | */
|
---|
322 | if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
|
---|
323 | {
|
---|
324 | /*
|
---|
325 | * Initialize the various COM libraries and data structures.
|
---|
326 | */
|
---|
327 | TRACE("() - Initializing the COM libraries\n");
|
---|
328 |
|
---|
329 |
|
---|
330 | RunningObjectTableImpl_Initialize();
|
---|
331 |
|
---|
332 | hr = S_OK;
|
---|
333 | }
|
---|
334 | else
|
---|
335 | hr = S_FALSE;
|
---|
336 |
|
---|
337 | return hr;
|
---|
338 | }
|
---|
339 |
|
---|
340 | /***********************************************************************
|
---|
341 | * CoUninitialize [OLE32.47]
|
---|
342 | *
|
---|
343 | * This method will release the COM libraries.
|
---|
344 | *
|
---|
345 | * See the windows documentation for more details.
|
---|
346 | */
|
---|
347 | void WINAPI CoUninitialize(void)
|
---|
348 | {
|
---|
349 | LONG lCOMRefCnt;
|
---|
350 | TRACE("()\n");
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * Decrease the reference count.
|
---|
354 | * If we are back to 0 locks on the COM library, make sure we free
|
---|
355 | * all the associated data structures.
|
---|
356 | */
|
---|
357 | lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
|
---|
358 | if (lCOMRefCnt==1)
|
---|
359 | {
|
---|
360 | /*
|
---|
361 | * Release the various COM libraries and data structures.
|
---|
362 | */
|
---|
363 | TRACE("() - Releasing the COM libraries\n");
|
---|
364 |
|
---|
365 | RunningObjectTableImpl_UnInitialize();
|
---|
366 | /*
|
---|
367 | * Release the references to the registered class objects.
|
---|
368 | */
|
---|
369 | COM_RevokeAllClasses();
|
---|
370 |
|
---|
371 | /*
|
---|
372 | * This will free the loaded COM Dlls.
|
---|
373 | */
|
---|
374 | CoFreeAllLibraries();
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * This will free list of external references to COM objects.
|
---|
378 | */
|
---|
379 | COM_ExternalLockFreeList();
|
---|
380 |
|
---|
381 | }
|
---|
382 | else if (lCOMRefCnt<1) {
|
---|
383 | ERR( "CoUninitialize() - not CoInitialized.\n" );
|
---|
384 | InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | /******************************************************************************
|
---|
389 | * CoDisconnectObject [COMPOBJ.15]
|
---|
390 | * CoDisconnectObject [OLE32.8]
|
---|
391 | */
|
---|
392 | HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
|
---|
393 | {
|
---|
394 | TRACE("(%p, %lx)\n",lpUnk,reserved);
|
---|
395 | return S_OK;
|
---|
396 | }
|
---|
397 |
|
---|
398 | /******************************************************************************
|
---|
399 | * CoCreateGuid[OLE32.6]
|
---|
400 | *
|
---|
401 | */
|
---|
402 | HRESULT WINAPI CoCreateGuid(
|
---|
403 | GUID *pguid /* [out] points to the GUID to initialize */
|
---|
404 | ) {
|
---|
405 | return UuidCreate(pguid);
|
---|
406 | }
|
---|
407 |
|
---|
408 | /******************************************************************************
|
---|
409 | * CLSIDFromString [OLE32.3]
|
---|
410 | * IIDFromString [OLE32.74]
|
---|
411 | * Converts a unique identifier from its string representation into
|
---|
412 | * the GUID struct.
|
---|
413 | *
|
---|
414 | * UNDOCUMENTED
|
---|
415 | * If idstr is not a valid CLSID string then it gets treated as a ProgID
|
---|
416 | *
|
---|
417 | * RETURNS
|
---|
418 | * the converted GUID
|
---|
419 | */
|
---|
420 | HRESULT WINAPI __CLSIDFromStringA(
|
---|
421 | LPCSTR idstr, /* [in] string representation of guid */
|
---|
422 | CLSID *id) /* [out] GUID converted from string */
|
---|
423 | {
|
---|
424 | BYTE *s = (BYTE *) idstr;
|
---|
425 | int i;
|
---|
426 | BYTE table[256];
|
---|
427 |
|
---|
428 | if (!s)
|
---|
429 | s = "{00000000-0000-0000-0000-000000000000}";
|
---|
430 | else { /* validate the CLSID string */
|
---|
431 |
|
---|
432 | if (strlen(s) != 38)
|
---|
433 | return CO_E_CLASSSTRING;
|
---|
434 |
|
---|
435 | if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
|
---|
436 | return CO_E_CLASSSTRING;
|
---|
437 |
|
---|
438 | for (i=1; i<37; i++) {
|
---|
439 | if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
|
---|
440 | if (!(((s[i] >= '0') && (s[i] <= '9')) ||
|
---|
441 | ((s[i] >= 'a') && (s[i] <= 'f')) ||
|
---|
442 | ((s[i] >= 'A') && (s[i] <= 'F'))))
|
---|
443 | return CO_E_CLASSSTRING;
|
---|
444 | }
|
---|
445 | }
|
---|
446 |
|
---|
447 | TRACE("%s -> %p\n", s, id);
|
---|
448 |
|
---|
449 | /* quick lookup table */
|
---|
450 | memset(table, 0, 256);
|
---|
451 |
|
---|
452 | for (i = 0; i < 10; i++) {
|
---|
453 | table['0' + i] = i;
|
---|
454 | }
|
---|
455 | for (i = 0; i < 6; i++) {
|
---|
456 | table['A' + i] = i+10;
|
---|
457 | table['a' + i] = i+10;
|
---|
458 | }
|
---|
459 |
|
---|
460 | /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
|
---|
461 |
|
---|
462 | id->Data1 = (table[s[1]] << 28 | table[s[2]] << 24 | table[s[3]] << 20 | table[s[4]] << 16 |
|
---|
463 | table[s[5]] << 12 | table[s[6]] << 8 | table[s[7]] << 4 | table[s[8]]);
|
---|
464 | id->Data2 = table[s[10]] << 12 | table[s[11]] << 8 | table[s[12]] << 4 | table[s[13]];
|
---|
465 | id->Data3 = table[s[15]] << 12 | table[s[16]] << 8 | table[s[17]] << 4 | table[s[18]];
|
---|
466 |
|
---|
467 | /* these are just sequential bytes */
|
---|
468 | id->Data4[0] = table[s[20]] << 4 | table[s[21]];
|
---|
469 | id->Data4[1] = table[s[22]] << 4 | table[s[23]];
|
---|
470 | id->Data4[2] = table[s[25]] << 4 | table[s[26]];
|
---|
471 | id->Data4[3] = table[s[27]] << 4 | table[s[28]];
|
---|
472 | id->Data4[4] = table[s[29]] << 4 | table[s[30]];
|
---|
473 | id->Data4[5] = table[s[31]] << 4 | table[s[32]];
|
---|
474 | id->Data4[6] = table[s[33]] << 4 | table[s[34]];
|
---|
475 | id->Data4[7] = table[s[35]] << 4 | table[s[36]];
|
---|
476 |
|
---|
477 | return S_OK;
|
---|
478 | }
|
---|
479 |
|
---|
480 | /*****************************************************************************/
|
---|
481 |
|
---|
482 | HRESULT WINAPI CLSIDFromString(
|
---|
483 | LPCOLESTR idstr, /* [in] string representation of GUID */
|
---|
484 | CLSID *id ) /* [out] GUID represented by above string */
|
---|
485 | {
|
---|
486 | char xid[40];
|
---|
487 | HRESULT ret;
|
---|
488 |
|
---|
489 | if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL ))
|
---|
490 | return CO_E_CLASSSTRING;
|
---|
491 |
|
---|
492 |
|
---|
493 | ret = __CLSIDFromStringA(xid,id);
|
---|
494 | if(ret != S_OK) { /* It appears a ProgID is also valid */
|
---|
495 | ret = CLSIDFromProgID(idstr, id);
|
---|
496 | }
|
---|
497 | return ret;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /******************************************************************************
|
---|
501 | * WINE_StringFromCLSID [Internal]
|
---|
502 | * Converts a GUID into the respective string representation.
|
---|
503 | *
|
---|
504 | * NOTES
|
---|
505 | *
|
---|
506 | * RETURNS
|
---|
507 | * the string representation and HRESULT
|
---|
508 | */
|
---|
509 | HRESULT WINAPI WINE_StringFromCLSID(
|
---|
510 | const CLSID *id, /* [in] GUID to be converted */
|
---|
511 | LPSTR idstr /* [out] pointer to buffer to contain converted guid */
|
---|
512 | ) {
|
---|
513 | static const char *hex = "0123456789ABCDEF";
|
---|
514 | char *s;
|
---|
515 | int i;
|
---|
516 |
|
---|
517 | if (!id)
|
---|
518 | { ERR("called with id=Null\n");
|
---|
519 | *idstr = 0x00;
|
---|
520 | return E_FAIL;
|
---|
521 | }
|
---|
522 |
|
---|
523 | sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
|
---|
524 | id->Data1, id->Data2, id->Data3,
|
---|
525 | id->Data4[0], id->Data4[1]);
|
---|
526 | s = &idstr[25];
|
---|
527 |
|
---|
528 | /* 6 hex bytes */
|
---|
529 | for (i = 2; i < 8; i++) {
|
---|
530 | *s++ = hex[id->Data4[i]>>4];
|
---|
531 | *s++ = hex[id->Data4[i] & 0xf];
|
---|
532 | }
|
---|
533 |
|
---|
534 | *s++ = '}';
|
---|
535 | *s++ = '\0';
|
---|
536 |
|
---|
537 | TRACE("%p->%s\n", id, idstr);
|
---|
538 |
|
---|
539 | return S_OK;
|
---|
540 | }
|
---|
541 |
|
---|
542 |
|
---|
543 | /******************************************************************************
|
---|
544 | * StringFromCLSID [OLE32.151]
|
---|
545 | * StringFromIID [OLE32.153]
|
---|
546 | * Converts a GUID into the respective string representation.
|
---|
547 | * The target string is allocated using the OLE IMalloc.
|
---|
548 | * RETURNS
|
---|
549 | * the string representation and HRESULT
|
---|
550 | */
|
---|
551 | HRESULT WINAPI StringFromCLSID(
|
---|
552 | REFCLSID id, /* [in] the GUID to be converted */
|
---|
553 | LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
|
---|
554 | ) {
|
---|
555 | char buf[80];
|
---|
556 | HRESULT ret;
|
---|
557 | LPMALLOC mllc;
|
---|
558 |
|
---|
559 | if ((ret=CoGetMalloc(0,&mllc)))
|
---|
560 | return ret;
|
---|
561 |
|
---|
562 | ret=WINE_StringFromCLSID(id,buf);
|
---|
563 | if (!ret) {
|
---|
564 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
|
---|
565 | *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
|
---|
566 | MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
|
---|
567 | }
|
---|
568 | return ret;
|
---|
569 | }
|
---|
570 |
|
---|
571 | /******************************************************************************
|
---|
572 | * StringFromGUID2 [COMPOBJ.76]
|
---|
573 | * StringFromGUID2 [OLE32.152]
|
---|
574 | *
|
---|
575 | * Converts a global unique identifier into a string of an API-
|
---|
576 | * specified fixed format. (The usual {.....} stuff.)
|
---|
577 | *
|
---|
578 | * RETURNS
|
---|
579 | * The (UNICODE) string representation of the GUID in 'str'
|
---|
580 | * The length of the resulting string, 0 if there was any problem.
|
---|
581 | */
|
---|
582 | INT WINAPI
|
---|
583 | StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
|
---|
584 | {
|
---|
585 | char xguid[80];
|
---|
586 |
|
---|
587 | if (WINE_StringFromCLSID(id,xguid))
|
---|
588 | return 0;
|
---|
589 | return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
|
---|
590 | }
|
---|
591 |
|
---|
592 | /******************************************************************************
|
---|
593 | * ProgIDFromCLSID [OLE32.133]
|
---|
594 | * Converts a class id into the respective Program ID. (By using a registry lookup)
|
---|
595 | * RETURNS S_OK on success
|
---|
596 | * riid associated with the progid
|
---|
597 | */
|
---|
598 |
|
---|
599 | HRESULT WINAPI ProgIDFromCLSID(
|
---|
600 | REFCLSID clsid, /* [in] class id as found in registry */
|
---|
601 | LPOLESTR *lplpszProgID/* [out] associated Prog ID */
|
---|
602 | )
|
---|
603 | {
|
---|
604 | char strCLSID[50], *buf, *buf2;
|
---|
605 | DWORD buf2len;
|
---|
606 | HKEY xhkey;
|
---|
607 | LPMALLOC mllc;
|
---|
608 | HRESULT ret = S_OK;
|
---|
609 |
|
---|
610 | WINE_StringFromCLSID(clsid, strCLSID);
|
---|
611 |
|
---|
612 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
|
---|
613 | sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
|
---|
614 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
---|
615 | ret = REGDB_E_CLASSNOTREG;
|
---|
616 |
|
---|
617 | HeapFree(GetProcessHeap(), 0, buf);
|
---|
618 |
|
---|
619 | if (ret == S_OK)
|
---|
620 | {
|
---|
621 | buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
|
---|
622 | buf2len = 255;
|
---|
623 | if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
|
---|
624 | ret = REGDB_E_CLASSNOTREG;
|
---|
625 |
|
---|
626 | if (ret == S_OK)
|
---|
627 | {
|
---|
628 | if (CoGetMalloc(0,&mllc))
|
---|
629 | ret = E_OUTOFMEMORY;
|
---|
630 | else
|
---|
631 | {
|
---|
632 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
|
---|
633 | *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
|
---|
634 | MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
|
---|
635 | }
|
---|
636 | }
|
---|
637 | HeapFree(GetProcessHeap(), 0, buf2);
|
---|
638 | }
|
---|
639 |
|
---|
640 | RegCloseKey(xhkey);
|
---|
641 | return ret;
|
---|
642 | }
|
---|
643 |
|
---|
644 | /******************************************************************************
|
---|
645 | * CLSIDFromProgID [OLE32.2]
|
---|
646 | * Converts a program id into the respective GUID. (By using a registry lookup)
|
---|
647 | * RETURNS
|
---|
648 | * riid associated with the progid
|
---|
649 | */
|
---|
650 | HRESULT WINAPI CLSIDFromProgID(
|
---|
651 | LPCOLESTR progid, /* [in] program id as found in registry */
|
---|
652 | LPCLSID riid ) /* [out] associated CLSID */
|
---|
653 | {
|
---|
654 | static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
|
---|
655 | char buf2[80];
|
---|
656 | DWORD buf2len = sizeof(buf2);
|
---|
657 | HKEY xhkey;
|
---|
658 |
|
---|
659 | WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
|
---|
660 | strcpyW( buf, progid );
|
---|
661 | strcatW( buf, clsidW );
|
---|
662 | if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
|
---|
663 | {
|
---|
664 | HeapFree(GetProcessHeap(),0,buf);
|
---|
665 | return CO_E_CLASSSTRING;
|
---|
666 | }
|
---|
667 | HeapFree(GetProcessHeap(),0,buf);
|
---|
668 |
|
---|
669 | if (RegQueryValueA(xhkey,NULL,buf2,&buf2len))
|
---|
670 | {
|
---|
671 | RegCloseKey(xhkey);
|
---|
672 | return CO_E_CLASSSTRING;
|
---|
673 | }
|
---|
674 | RegCloseKey(xhkey);
|
---|
675 | return __CLSIDFromStringA(buf2,riid);
|
---|
676 | }
|
---|
677 |
|
---|
678 |
|
---|
679 | /******************************************************************************
|
---|
680 | * CLSIDFromProgIDEx [OLE32.]
|
---|
681 | */
|
---|
682 | HRESULT WINAPI CLSIDFromProgIDEx(LPCOLESTR lpszProgID, LPCLSID pclsid)
|
---|
683 | {
|
---|
684 | FIXME("%s: Not implemented! (returning E_NOTIMPL)\n", __FUNCTION__);
|
---|
685 | return E_NOTIMPL;
|
---|
686 | }
|
---|
687 |
|
---|
688 | /*****************************************************************************
|
---|
689 | * CoGetPSClsid [OLE32.22]
|
---|
690 | *
|
---|
691 | * This function returns the CLSID of the DLL that implements the proxy and stub
|
---|
692 | * for the specified interface.
|
---|
693 | *
|
---|
694 | * It determines this by searching the
|
---|
695 | * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
|
---|
696 | * and any interface id registered by CoRegisterPSClsid within the current process.
|
---|
697 | *
|
---|
698 | * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
|
---|
699 | */
|
---|
700 | HRESULT WINAPI CoGetPSClsid(
|
---|
701 | REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
|
---|
702 | CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
|
---|
703 | {
|
---|
704 | char *buf, buf2[40];
|
---|
705 | DWORD buf2len;
|
---|
706 | HKEY xhkey;
|
---|
707 |
|
---|
708 | TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
|
---|
709 |
|
---|
710 | /* Get the input iid as a string */
|
---|
711 | WINE_StringFromCLSID(riid, buf2);
|
---|
712 | /* Allocate memory for the registry key we will construct.
|
---|
713 | (length of iid string plus constant length of static text */
|
---|
714 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
|
---|
715 | if (buf == NULL)
|
---|
716 | {
|
---|
717 | return (E_OUTOFMEMORY);
|
---|
718 | }
|
---|
719 |
|
---|
720 | /* Construct the registry key we want */
|
---|
721 | sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
|
---|
722 |
|
---|
723 | /* Open the key.. */
|
---|
724 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
---|
725 | {
|
---|
726 | HeapFree(GetProcessHeap(),0,buf);
|
---|
727 | return (E_INVALIDARG);
|
---|
728 | }
|
---|
729 | HeapFree(GetProcessHeap(),0,buf);
|
---|
730 |
|
---|
731 | /* ... Once we have the key, query the registry to get the
|
---|
732 | value of CLSID as a string, and convert it into a
|
---|
733 | proper CLSID structure to be passed back to the app */
|
---|
734 | buf2len = sizeof(buf2);
|
---|
735 | if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
|
---|
736 | {
|
---|
737 | RegCloseKey(xhkey);
|
---|
738 | return E_INVALIDARG;
|
---|
739 | }
|
---|
740 | RegCloseKey(xhkey);
|
---|
741 |
|
---|
742 | /* We have the CLSid we want back from the registry as a string, so
|
---|
743 | lets convert it into a CLSID structure */
|
---|
744 | if ( (__CLSIDFromStringA(buf2,pclsid)) != NOERROR) {
|
---|
745 | return E_INVALIDARG;
|
---|
746 | }
|
---|
747 |
|
---|
748 | TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
|
---|
749 | return (S_OK);
|
---|
750 | }
|
---|
751 |
|
---|
752 |
|
---|
753 |
|
---|
754 | /***********************************************************************
|
---|
755 | * WriteClassStm (OLE32.159)
|
---|
756 | *
|
---|
757 | * This function write a CLSID on stream
|
---|
758 | */
|
---|
759 | HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
|
---|
760 | {
|
---|
761 | TRACE("(%p,%p)\n",pStm,rclsid);
|
---|
762 |
|
---|
763 | if (rclsid==NULL)
|
---|
764 | return E_INVALIDARG;
|
---|
765 |
|
---|
766 | return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
|
---|
767 | }
|
---|
768 |
|
---|
769 | /***********************************************************************
|
---|
770 | * ReadClassStm (OLE32.135)
|
---|
771 | *
|
---|
772 | * This function read a CLSID from a stream
|
---|
773 | */
|
---|
774 | HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
|
---|
775 | {
|
---|
776 | ULONG nbByte;
|
---|
777 | HRESULT res;
|
---|
778 |
|
---|
779 | TRACE("(%p,%p)\n",pStm,pclsid);
|
---|
780 |
|
---|
781 | if (pclsid==NULL)
|
---|
782 | return E_INVALIDARG;
|
---|
783 |
|
---|
784 | res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
|
---|
785 |
|
---|
786 | if (FAILED(res))
|
---|
787 | return res;
|
---|
788 |
|
---|
789 | if (nbByte != sizeof(CLSID))
|
---|
790 | return S_FALSE;
|
---|
791 | else
|
---|
792 | return S_OK;
|
---|
793 | }
|
---|
794 |
|
---|
795 |
|
---|
796 | /***
|
---|
797 | * COM_GetRegisteredClassObject
|
---|
798 | *
|
---|
799 | * This internal method is used to scan the registered class list to
|
---|
800 | * find a class object.
|
---|
801 | *
|
---|
802 | * Params:
|
---|
803 | * rclsid Class ID of the class to find.
|
---|
804 | * dwClsContext Class context to match.
|
---|
805 | * ppv [out] returns a pointer to the class object. Complying
|
---|
806 | * to normal COM usage, this method will increase the
|
---|
807 | * reference count on this object.
|
---|
808 | */
|
---|
809 | static HRESULT COM_GetRegisteredClassObject(
|
---|
810 | REFCLSID rclsid,
|
---|
811 | DWORD dwClsContext,
|
---|
812 | LPUNKNOWN* ppUnk)
|
---|
813 | {
|
---|
814 | HRESULT hr = S_FALSE;
|
---|
815 | RegisteredClass* curClass;
|
---|
816 |
|
---|
817 | EnterCriticalSection( &csRegisteredClassList );
|
---|
818 |
|
---|
819 | /*
|
---|
820 | * Sanity check
|
---|
821 | */
|
---|
822 | assert(ppUnk!=0);
|
---|
823 |
|
---|
824 | /*
|
---|
825 | * Iterate through the whole list and try to match the class ID.
|
---|
826 | */
|
---|
827 | curClass = firstRegisteredClass;
|
---|
828 |
|
---|
829 | while (curClass != 0)
|
---|
830 | {
|
---|
831 | /*
|
---|
832 | * Check if we have a match on the class ID.
|
---|
833 | */
|
---|
834 | if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
|
---|
835 | {
|
---|
836 | /*
|
---|
837 | * Since we don't do out-of process or DCOM just right away, let's ignore the
|
---|
838 | * class context.
|
---|
839 | */
|
---|
840 |
|
---|
841 | /*
|
---|
842 | * We have a match, return the pointer to the class object.
|
---|
843 | */
|
---|
844 | *ppUnk = curClass->classObject;
|
---|
845 |
|
---|
846 | IUnknown_AddRef(curClass->classObject);
|
---|
847 |
|
---|
848 | hr = S_OK;
|
---|
849 | goto end;
|
---|
850 | }
|
---|
851 |
|
---|
852 | /*
|
---|
853 | * Step to the next class in the list.
|
---|
854 | */
|
---|
855 | curClass = curClass->nextClass;
|
---|
856 | }
|
---|
857 |
|
---|
858 | end:
|
---|
859 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
860 | /*
|
---|
861 | * If we get to here, we haven't found our class.
|
---|
862 | */
|
---|
863 | return hr;
|
---|
864 | }
|
---|
865 |
|
---|
866 | static DWORD WINAPI
|
---|
867 | _LocalServerThread(LPVOID param) {
|
---|
868 | HANDLE hPipe;
|
---|
869 | char pipefn[200];
|
---|
870 | RegisteredClass *newClass = (RegisteredClass*)param;
|
---|
871 | HRESULT hres;
|
---|
872 | IStream *pStm;
|
---|
873 | STATSTG ststg;
|
---|
874 | unsigned char *buffer;
|
---|
875 | int buflen;
|
---|
876 | IClassFactory *classfac;
|
---|
877 | LARGE_INTEGER seekto;
|
---|
878 | ULARGE_INTEGER newpos;
|
---|
879 | ULONG res;
|
---|
880 |
|
---|
881 | TRACE("Starting threader for %s.\n",debugstr_guid(&newClass->classIdentifier));
|
---|
882 | strcpy(pipefn,PIPEPREF);
|
---|
883 | WINE_StringFromCLSID(&newClass->classIdentifier,pipefn+strlen(PIPEPREF));
|
---|
884 |
|
---|
885 | hres = IUnknown_QueryInterface(newClass->classObject,&IID_IClassFactory,(LPVOID*)&classfac);
|
---|
886 | if (hres) return hres;
|
---|
887 |
|
---|
888 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
---|
889 | if (hres) {
|
---|
890 | FIXME("Failed to create stream on hglobal.\n");
|
---|
891 | return hres;
|
---|
892 | }
|
---|
893 | hres = CoMarshalInterface(pStm,&IID_IClassFactory,(LPVOID)classfac,0,NULL,0);
|
---|
894 | if (hres) {
|
---|
895 | FIXME("CoMarshalInterface failed, %lx!\n",hres);
|
---|
896 | return hres;
|
---|
897 | }
|
---|
898 | hres = IStream_Stat(pStm,&ststg,0);
|
---|
899 | if (hres) return hres;
|
---|
900 |
|
---|
901 | buflen = ststg.cbSize.DUMMYSTRUCTNAME_DOT LowPart;
|
---|
902 | buffer = HeapAlloc(GetProcessHeap(),0,buflen);
|
---|
903 | seekto.DUMMYSTRUCTNAME_DOT LowPart = 0;
|
---|
904 | seekto.DUMMYSTRUCTNAME_DOT HighPart = 0;
|
---|
905 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
---|
906 | if (hres) {
|
---|
907 | FIXME("IStream_Seek failed, %lx\n",hres);
|
---|
908 | return hres;
|
---|
909 | }
|
---|
910 | hres = IStream_Read(pStm,buffer,buflen,&res);
|
---|
911 | if (hres) {
|
---|
912 | FIXME("Stream Read failed, %lx\n",hres);
|
---|
913 | return hres;
|
---|
914 | }
|
---|
915 | IStream_Release(pStm);
|
---|
916 |
|
---|
917 | while (1) {
|
---|
918 | hPipe = CreateNamedPipeA(
|
---|
919 | pipefn,
|
---|
920 | PIPE_ACCESS_DUPLEX,
|
---|
921 | PIPE_TYPE_BYTE|PIPE_WAIT,
|
---|
922 | PIPE_UNLIMITED_INSTANCES,
|
---|
923 | 4096,
|
---|
924 | 4096,
|
---|
925 | NMPWAIT_USE_DEFAULT_WAIT,
|
---|
926 | NULL
|
---|
927 | );
|
---|
928 | if (hPipe == INVALID_HANDLE_VALUE) {
|
---|
929 | FIXME("pipe creation failed for %s, le is %lx\n",pipefn,GetLastError());
|
---|
930 | return 1;
|
---|
931 | }
|
---|
932 | if (!ConnectNamedPipe(hPipe,NULL)) {
|
---|
933 | ERR("Failure during ConnectNamedPipe %lx, ABORT!\n",GetLastError());
|
---|
934 | CloseHandle(hPipe);
|
---|
935 | continue;
|
---|
936 | }
|
---|
937 | WriteFile(hPipe,buffer,buflen,&res,NULL);
|
---|
938 | CloseHandle(hPipe);
|
---|
939 | }
|
---|
940 | return 0;
|
---|
941 | }
|
---|
942 |
|
---|
943 | /******************************************************************************
|
---|
944 | * CoRegisterClassObject [OLE32.36]
|
---|
945 | *
|
---|
946 | * This method will register the class object for a given class ID.
|
---|
947 | *
|
---|
948 | * See the Windows documentation for more details.
|
---|
949 | */
|
---|
950 | HRESULT WINAPI CoRegisterClassObject(
|
---|
951 | REFCLSID rclsid,
|
---|
952 | LPUNKNOWN pUnk,
|
---|
953 | DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
|
---|
954 | DWORD flags, /* [in] REGCLS flags indicating how connections are made */
|
---|
955 | LPDWORD lpdwRegister
|
---|
956 | )
|
---|
957 | {
|
---|
958 | RegisteredClass* newClass;
|
---|
959 | LPUNKNOWN foundObject;
|
---|
960 | HRESULT hr;
|
---|
961 |
|
---|
962 | TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
|
---|
963 | debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister);
|
---|
964 |
|
---|
965 | if ( (lpdwRegister==0) || (pUnk==0) )
|
---|
966 | return E_INVALIDARG;
|
---|
967 |
|
---|
968 | *lpdwRegister = 0;
|
---|
969 |
|
---|
970 | /*
|
---|
971 | * First, check if the class is already registered.
|
---|
972 | * If it is, this should cause an error.
|
---|
973 | */
|
---|
974 | hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
|
---|
975 | if (hr == S_OK) {
|
---|
976 | IUnknown_Release(foundObject);
|
---|
977 | return CO_E_OBJISREG;
|
---|
978 | }
|
---|
979 |
|
---|
980 | newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
|
---|
981 | if ( newClass == NULL )
|
---|
982 | return E_OUTOFMEMORY;
|
---|
983 |
|
---|
984 | EnterCriticalSection( &csRegisteredClassList );
|
---|
985 |
|
---|
986 | newClass->classIdentifier = *rclsid;
|
---|
987 | newClass->runContext = dwClsContext;
|
---|
988 | newClass->connectFlags = flags;
|
---|
989 | /*
|
---|
990 | * Use the address of the chain node as the cookie since we are sure it's
|
---|
991 | * unique.
|
---|
992 | */
|
---|
993 | newClass->dwCookie = (DWORD)newClass;
|
---|
994 | newClass->nextClass = firstRegisteredClass;
|
---|
995 |
|
---|
996 | /*
|
---|
997 | * Since we're making a copy of the object pointer, we have to increase its
|
---|
998 | * reference count.
|
---|
999 | */
|
---|
1000 | newClass->classObject = pUnk;
|
---|
1001 | IUnknown_AddRef(newClass->classObject);
|
---|
1002 |
|
---|
1003 | firstRegisteredClass = newClass;
|
---|
1004 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1005 |
|
---|
1006 | *lpdwRegister = newClass->dwCookie;
|
---|
1007 |
|
---|
1008 | if (dwClsContext & CLSCTX_LOCAL_SERVER) {
|
---|
1009 | DWORD tid;
|
---|
1010 |
|
---|
1011 | STUBMGR_Start();
|
---|
1012 | newClass->hThread=CreateThread(NULL,0,_LocalServerThread,newClass,0,&tid);
|
---|
1013 | }
|
---|
1014 | return S_OK;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | /***********************************************************************
|
---|
1018 | * CoRevokeClassObject [OLE32.40]
|
---|
1019 | *
|
---|
1020 | * This method will remove a class object from the class registry
|
---|
1021 | *
|
---|
1022 | * See the Windows documentation for more details.
|
---|
1023 | */
|
---|
1024 | HRESULT WINAPI CoRevokeClassObject(
|
---|
1025 | DWORD dwRegister)
|
---|
1026 | {
|
---|
1027 | HRESULT hr = E_INVALIDARG;
|
---|
1028 | RegisteredClass** prevClassLink;
|
---|
1029 | RegisteredClass* curClass;
|
---|
1030 |
|
---|
1031 | TRACE("(%08lx)\n",dwRegister);
|
---|
1032 |
|
---|
1033 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1034 |
|
---|
1035 | /*
|
---|
1036 | * Iterate through the whole list and try to match the cookie.
|
---|
1037 | */
|
---|
1038 | curClass = firstRegisteredClass;
|
---|
1039 | prevClassLink = &firstRegisteredClass;
|
---|
1040 |
|
---|
1041 | while (curClass != 0)
|
---|
1042 | {
|
---|
1043 | /*
|
---|
1044 | * Check if we have a match on the cookie.
|
---|
1045 | */
|
---|
1046 | if (curClass->dwCookie == dwRegister)
|
---|
1047 | {
|
---|
1048 | /*
|
---|
1049 | * Remove the class from the chain.
|
---|
1050 | */
|
---|
1051 | *prevClassLink = curClass->nextClass;
|
---|
1052 |
|
---|
1053 | /*
|
---|
1054 | * Release the reference to the class object.
|
---|
1055 | */
|
---|
1056 | IUnknown_Release(curClass->classObject);
|
---|
1057 |
|
---|
1058 | /*
|
---|
1059 | * Free the memory used by the chain node.
|
---|
1060 | */
|
---|
1061 | HeapFree(GetProcessHeap(), 0, curClass);
|
---|
1062 |
|
---|
1063 | hr = S_OK;
|
---|
1064 | goto end;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | /*
|
---|
1068 | * Step to the next class in the list.
|
---|
1069 | */
|
---|
1070 | prevClassLink = &(curClass->nextClass);
|
---|
1071 | curClass = curClass->nextClass;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | end:
|
---|
1075 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1076 | /*
|
---|
1077 | * If we get to here, we haven't found our class.
|
---|
1078 | */
|
---|
1079 | return hr;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | /***********************************************************************
|
---|
1083 | * compobj_RegReadPath [internal]
|
---|
1084 | *
|
---|
1085 | * Reads a registry value and expands it when nessesary
|
---|
1086 | */
|
---|
1087 | HRESULT compobj_RegReadPath(char * keyname, char * valuename, char * dst, int dstlen)
|
---|
1088 | {
|
---|
1089 | HRESULT hres;
|
---|
1090 | HKEY key;
|
---|
1091 | DWORD keytype;
|
---|
1092 | char src[MAX_PATH];
|
---|
1093 | DWORD dwLength = dstlen;
|
---|
1094 |
|
---|
1095 | if((hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key)) == ERROR_SUCCESS) {
|
---|
1096 | if( (hres = RegQueryValueExA(key, NULL, NULL, &keytype, (LPBYTE)src, &dwLength)) == ERROR_SUCCESS ) {
|
---|
1097 | if (keytype == REG_EXPAND_SZ) {
|
---|
1098 | if (dstlen <= ExpandEnvironmentStringsA(src, dst, dstlen)) hres = ERROR_MORE_DATA;
|
---|
1099 | } else {
|
---|
1100 | strncpy(dst, src, dstlen);
|
---|
1101 | }
|
---|
1102 | }
|
---|
1103 | RegCloseKey (key);
|
---|
1104 | }
|
---|
1105 | return hres;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | /***********************************************************************
|
---|
1109 | * CoGetClassObject [COMPOBJ.7]
|
---|
1110 | * CoGetClassObject [OLE32.16]
|
---|
1111 | *
|
---|
1112 | * FIXME. If request allows of several options and there is a failure
|
---|
1113 | * with one (other than not being registered) do we try the
|
---|
1114 | * others or return failure? (E.g. inprocess is registered but
|
---|
1115 | * the DLL is not found but the server version works)
|
---|
1116 | */
|
---|
1117 | HRESULT WINAPI CoGetClassObject(
|
---|
1118 | REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
|
---|
1119 | REFIID iid, LPVOID *ppv
|
---|
1120 | ) {
|
---|
1121 | LPUNKNOWN regClassObject;
|
---|
1122 | HRESULT hres = E_UNEXPECTED;
|
---|
1123 | char xclsid[80];
|
---|
1124 | HINSTANCE hLibrary;
|
---|
1125 | #ifdef __WIN32OS2__
|
---|
1126 | typedef HRESULT (* CALLBACK DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
|
---|
1127 | #else
|
---|
1128 | typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
|
---|
1129 | #endif
|
---|
1130 | DllGetClassObjectFunc DllGetClassObject;
|
---|
1131 |
|
---|
1132 | WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
|
---|
1133 |
|
---|
1134 | TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
|
---|
1135 |
|
---|
1136 | if (pServerInfo) {
|
---|
1137 | FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
|
---|
1138 | FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | /*
|
---|
1142 | * First, try and see if we can't match the class ID with one of the
|
---|
1143 | * registered classes.
|
---|
1144 | */
|
---|
1145 | if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
|
---|
1146 | {
|
---|
1147 | /*
|
---|
1148 | * Get the required interface from the retrieved pointer.
|
---|
1149 | */
|
---|
1150 | hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
|
---|
1151 |
|
---|
1152 | /*
|
---|
1153 | * Since QI got another reference on the pointer, we want to release the
|
---|
1154 | * one we already have. If QI was unsuccessful, this will release the object. This
|
---|
1155 | * is good since we are not returning it in the "out" parameter.
|
---|
1156 | */
|
---|
1157 | IUnknown_Release(regClassObject);
|
---|
1158 |
|
---|
1159 | return hres;
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | /* first try: in-process */
|
---|
1163 | if ((CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER) & dwClsContext) {
|
---|
1164 | char keyname[MAX_PATH];
|
---|
1165 | char dllpath[MAX_PATH+1];
|
---|
1166 |
|
---|
1167 | sprintf(keyname,"CLSID\\%s\\InprocServer32",xclsid);
|
---|
1168 |
|
---|
1169 | if ( compobj_RegReadPath(keyname, NULL, dllpath, sizeof(dllpath)) != ERROR_SUCCESS) {
|
---|
1170 | /* failure: CLSID is not found in registry */
|
---|
1171 | WARN("class %s not registred\n", xclsid);
|
---|
1172 | hres = REGDB_E_CLASSNOTREG;
|
---|
1173 | } else {
|
---|
1174 | if ((hLibrary = LoadLibraryExA(dllpath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
|
---|
1175 | /* failure: DLL could not be loaded */
|
---|
1176 | ERR("couldn't load InprocServer32 dll %s\n", dllpath);
|
---|
1177 | hres = E_ACCESSDENIED; /* FIXME: or should this be CO_E_DLLNOTFOUND? */
|
---|
1178 | } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
|
---|
1179 | /* failure: the dll did not export DllGetClassObject */
|
---|
1180 | ERR("couldn't find function DllGetClassObject in %s\n", dllpath);
|
---|
1181 | FreeLibrary( hLibrary );
|
---|
1182 | hres = CO_E_DLLNOTFOUND;
|
---|
1183 | } else {
|
---|
1184 | /* OK: get the ClassObject */
|
---|
1185 | COMPOBJ_DLLList_Add( hLibrary );
|
---|
1186 | return DllGetClassObject(rclsid, iid, ppv);
|
---|
1187 | }
|
---|
1188 | }
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | /* Next try out of process */
|
---|
1192 | if (CLSCTX_LOCAL_SERVER & dwClsContext)
|
---|
1193 | {
|
---|
1194 | return create_marshalled_proxy(rclsid,iid,ppv);
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | /* Finally try remote */
|
---|
1198 | if (CLSCTX_REMOTE_SERVER & dwClsContext)
|
---|
1199 | {
|
---|
1200 | FIXME ("CLSCTX_REMOTE_SERVER not supported\n");
|
---|
1201 | hres = E_NOINTERFACE;
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | return hres;
|
---|
1205 | }
|
---|
1206 | /***********************************************************************
|
---|
1207 | * CoResumeClassObjects (OLE32.173)
|
---|
1208 | *
|
---|
1209 | * Resumes classobjects registered with REGCLS suspended
|
---|
1210 | */
|
---|
1211 | HRESULT WINAPI CoResumeClassObjects(void)
|
---|
1212 | {
|
---|
1213 | FIXME("\n");
|
---|
1214 | return S_OK;
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | /***********************************************************************
|
---|
1218 | * GetClassFile (OLE32.67)
|
---|
1219 | *
|
---|
1220 | * This function supplies the CLSID associated with the given filename.
|
---|
1221 | */
|
---|
1222 | HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
|
---|
1223 | {
|
---|
1224 | IStorage *pstg=0;
|
---|
1225 | HRESULT res;
|
---|
1226 | int nbElm, length, i;
|
---|
1227 | LONG sizeProgId;
|
---|
1228 | LPOLESTR *pathDec=0,absFile=0,progId=0;
|
---|
1229 | LPWSTR extension;
|
---|
1230 | static const WCHAR bkslashW[] = {'\\',0};
|
---|
1231 | static const WCHAR dotW[] = {'.',0};
|
---|
1232 |
|
---|
1233 | TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
|
---|
1234 |
|
---|
1235 | /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
|
---|
1236 | if((StgIsStorageFile(filePathName))==S_OK){
|
---|
1237 |
|
---|
1238 | res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
|
---|
1239 |
|
---|
1240 | if (SUCCEEDED(res))
|
---|
1241 | res=ReadClassStg(pstg,pclsid);
|
---|
1242 |
|
---|
1243 | IStorage_Release(pstg);
|
---|
1244 |
|
---|
1245 | return res;
|
---|
1246 | }
|
---|
1247 | /* if the file is not a storage object then attemps to match various bits in the file against a
|
---|
1248 | pattern in the registry. this case is not frequently used ! so I present only the psodocode for
|
---|
1249 | this case
|
---|
1250 |
|
---|
1251 | for(i=0;i<nFileTypes;i++)
|
---|
1252 |
|
---|
1253 | for(i=0;j<nPatternsForType;j++){
|
---|
1254 |
|
---|
1255 | PATTERN pat;
|
---|
1256 | HANDLE hFile;
|
---|
1257 |
|
---|
1258 | pat=ReadPatternFromRegistry(i,j);
|
---|
1259 | hFile=CreateFileW(filePathName,,,,,,hFile);
|
---|
1260 | SetFilePosition(hFile,pat.offset);
|
---|
1261 | ReadFile(hFile,buf,pat.size,NULL,NULL);
|
---|
1262 | if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
|
---|
1263 |
|
---|
1264 | *pclsid=ReadCLSIDFromRegistry(i);
|
---|
1265 | return S_OK;
|
---|
1266 | }
|
---|
1267 | }
|
---|
1268 | */
|
---|
1269 |
|
---|
1270 | /* if the obove strategies fail then search for the extension key in the registry */
|
---|
1271 |
|
---|
1272 | /* get the last element (absolute file) in the path name */
|
---|
1273 | nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
|
---|
1274 | absFile=pathDec[nbElm-1];
|
---|
1275 |
|
---|
1276 | /* failed if the path represente a directory and not an absolute file name*/
|
---|
1277 | if (!lstrcmpW(absFile, bkslashW))
|
---|
1278 | return MK_E_INVALIDEXTENSION;
|
---|
1279 |
|
---|
1280 | /* get the extension of the file */
|
---|
1281 | extension = NULL;
|
---|
1282 | length=lstrlenW(absFile);
|
---|
1283 | for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
|
---|
1284 | /* nothing */;
|
---|
1285 |
|
---|
1286 | if (!extension || !lstrcmpW(extension, dotW))
|
---|
1287 | return MK_E_INVALIDEXTENSION;
|
---|
1288 |
|
---|
1289 | res=RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
|
---|
1290 |
|
---|
1291 | /* get the progId associated to the extension */
|
---|
1292 | progId = CoTaskMemAlloc(sizeProgId);
|
---|
1293 | res = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId);
|
---|
1294 |
|
---|
1295 | if (res==ERROR_SUCCESS)
|
---|
1296 | /* return the clsid associated to the progId */
|
---|
1297 | res= CLSIDFromProgID(progId,pclsid);
|
---|
1298 |
|
---|
1299 | for(i=0; pathDec[i]!=NULL;i++)
|
---|
1300 | CoTaskMemFree(pathDec[i]);
|
---|
1301 | CoTaskMemFree(pathDec);
|
---|
1302 |
|
---|
1303 | CoTaskMemFree(progId);
|
---|
1304 |
|
---|
1305 | if (res==ERROR_SUCCESS)
|
---|
1306 | return res;
|
---|
1307 |
|
---|
1308 | return MK_E_INVALIDEXTENSION;
|
---|
1309 | }
|
---|
1310 | /***********************************************************************
|
---|
1311 | * CoCreateInstance [COMPOBJ.13]
|
---|
1312 | * CoCreateInstance [OLE32.7]
|
---|
1313 | */
|
---|
1314 | HRESULT WINAPI CoCreateInstance(
|
---|
1315 | REFCLSID rclsid,
|
---|
1316 | LPUNKNOWN pUnkOuter,
|
---|
1317 | DWORD dwClsContext,
|
---|
1318 | REFIID iid,
|
---|
1319 | LPVOID *ppv)
|
---|
1320 | {
|
---|
1321 | HRESULT hres;
|
---|
1322 | LPCLASSFACTORY lpclf = 0;
|
---|
1323 |
|
---|
1324 | /*
|
---|
1325 | * Sanity check
|
---|
1326 | */
|
---|
1327 | if (ppv==0)
|
---|
1328 | return E_POINTER;
|
---|
1329 |
|
---|
1330 | /*
|
---|
1331 | * Initialize the "out" parameter
|
---|
1332 | */
|
---|
1333 | *ppv = 0;
|
---|
1334 |
|
---|
1335 | /*
|
---|
1336 | * Get a class factory to construct the object we want.
|
---|
1337 | */
|
---|
1338 | hres = CoGetClassObject(rclsid,
|
---|
1339 | dwClsContext,
|
---|
1340 | NULL,
|
---|
1341 | &IID_IClassFactory,
|
---|
1342 | (LPVOID)&lpclf);
|
---|
1343 |
|
---|
1344 | if (FAILED(hres)) {
|
---|
1345 | FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
|
---|
1346 | debugstr_guid(rclsid),hres);
|
---|
1347 | return hres;
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | /*
|
---|
1351 | * Create the object and don't forget to release the factory
|
---|
1352 | */
|
---|
1353 | hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
|
---|
1354 | IClassFactory_Release(lpclf);
|
---|
1355 | if(FAILED(hres))
|
---|
1356 | FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
|
---|
1357 | debugstr_guid(iid), debugstr_guid(rclsid),hres);
|
---|
1358 |
|
---|
1359 | return hres;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | /***********************************************************************
|
---|
1363 | * CoCreateInstanceEx [OLE32.165]
|
---|
1364 | */
|
---|
1365 | HRESULT WINAPI CoCreateInstanceEx(
|
---|
1366 | REFCLSID rclsid,
|
---|
1367 | LPUNKNOWN pUnkOuter,
|
---|
1368 | DWORD dwClsContext,
|
---|
1369 | COSERVERINFO* pServerInfo,
|
---|
1370 | ULONG cmq,
|
---|
1371 | MULTI_QI* pResults)
|
---|
1372 | {
|
---|
1373 | IUnknown* pUnk = NULL;
|
---|
1374 | HRESULT hr;
|
---|
1375 | ULONG index;
|
---|
1376 | int successCount = 0;
|
---|
1377 |
|
---|
1378 | TRACE("s%: (rclsid=%p, pUnkOuter=%p, dwClsContext=0x%lf, pServerInfo=%p, cmq=%p, pResults=%p)\n",
|
---|
1379 | __FUNCTION__, rclsid, pUnkOuter, dwClsContext, pServerInfo, cmq, pResults);
|
---|
1380 | /*
|
---|
1381 | * Sanity check
|
---|
1382 | */
|
---|
1383 | if ( (cmq==0) || (pResults==NULL))
|
---|
1384 | return E_INVALIDARG;
|
---|
1385 |
|
---|
1386 | if (pServerInfo!=NULL)
|
---|
1387 | FIXME("() non-NULL pServerInfo not supported!\n");
|
---|
1388 |
|
---|
1389 | /*
|
---|
1390 | * Initialize all the "out" parameters.
|
---|
1391 | */
|
---|
1392 | for (index = 0; index < cmq; index++)
|
---|
1393 | {
|
---|
1394 | pResults[index].pItf = NULL;
|
---|
1395 | pResults[index].hr = E_NOINTERFACE;
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | /*
|
---|
1399 | * Get the object and get its IUnknown pointer.
|
---|
1400 | */
|
---|
1401 | hr = CoCreateInstance(rclsid,
|
---|
1402 | pUnkOuter,
|
---|
1403 | dwClsContext,
|
---|
1404 | &IID_IUnknown,
|
---|
1405 | (VOID**)&pUnk);
|
---|
1406 |
|
---|
1407 | if (hr)
|
---|
1408 | return hr;
|
---|
1409 |
|
---|
1410 | /*
|
---|
1411 | * Then, query for all the interfaces requested.
|
---|
1412 | */
|
---|
1413 | for (index = 0; index < cmq; index++)
|
---|
1414 | {
|
---|
1415 | pResults[index].hr = IUnknown_QueryInterface(pUnk,
|
---|
1416 | pResults[index].pIID,
|
---|
1417 | (VOID**)&(pResults[index].pItf));
|
---|
1418 |
|
---|
1419 | if (pResults[index].hr == S_OK)
|
---|
1420 | successCount++;
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | /*
|
---|
1424 | * Release our temporary unknown pointer.
|
---|
1425 | */
|
---|
1426 | IUnknown_Release(pUnk);
|
---|
1427 |
|
---|
1428 | if (successCount == 0)
|
---|
1429 | return E_NOINTERFACE;
|
---|
1430 |
|
---|
1431 | if (successCount!=cmq)
|
---|
1432 | return CO_S_NOTALLINTERFACES;
|
---|
1433 |
|
---|
1434 | return S_OK;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | /***********************************************************************
|
---|
1438 | * CoLoadLibrary (OLE32.30)
|
---|
1439 | */
|
---|
1440 | HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
|
---|
1441 | {
|
---|
1442 | TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
|
---|
1443 |
|
---|
1444 | return LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
|
---|
1445 | }
|
---|
1446 |
|
---|
1447 | /***********************************************************************
|
---|
1448 | * CoFreeLibrary [OLE32.13]
|
---|
1449 | *
|
---|
1450 | * NOTES: don't belive the docu
|
---|
1451 | */
|
---|
1452 | void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
|
---|
1453 | {
|
---|
1454 | FreeLibrary(hLibrary);
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 |
|
---|
1458 | /***********************************************************************
|
---|
1459 | * CoFreeAllLibraries [OLE32.12]
|
---|
1460 | *
|
---|
1461 | * NOTES: don't belive the docu
|
---|
1462 | */
|
---|
1463 | void WINAPI CoFreeAllLibraries(void)
|
---|
1464 | {
|
---|
1465 | /* NOP */
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 |
|
---|
1469 | /***********************************************************************
|
---|
1470 | * CoFreeUnusedLibraries [COMPOBJ.17]
|
---|
1471 | * CoFreeUnusedLibraries [OLE32.14]
|
---|
1472 | *
|
---|
1473 | * FIXME: Calls to CoFreeUnusedLibraries from any thread always route
|
---|
1474 | * through the main apartment's thread to call DllCanUnloadNow
|
---|
1475 | */
|
---|
1476 | void WINAPI CoFreeUnusedLibraries(void)
|
---|
1477 | {
|
---|
1478 | COMPOBJ_DllList_FreeUnused(0);
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | /***********************************************************************
|
---|
1482 | * CoFileTimeNow [COMPOBJ.82]
|
---|
1483 | * CoFileTimeNow [OLE32.10]
|
---|
1484 | *
|
---|
1485 | * RETURNS
|
---|
1486 | * the current system time in lpFileTime
|
---|
1487 | */
|
---|
1488 | HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
|
---|
1489 | {
|
---|
1490 | GetSystemTimeAsFileTime( lpFileTime );
|
---|
1491 | return S_OK;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | /***********************************************************************
|
---|
1495 | * CoLoadLibrary (OLE32.30)
|
---|
1496 | */
|
---|
1497 | static void COM_RevokeAllClasses()
|
---|
1498 | {
|
---|
1499 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1500 |
|
---|
1501 | while (firstRegisteredClass!=0)
|
---|
1502 | {
|
---|
1503 | CoRevokeClassObject(firstRegisteredClass->dwCookie);
|
---|
1504 | }
|
---|
1505 |
|
---|
1506 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | /****************************************************************************
|
---|
1510 | * COM External Lock methods implementation
|
---|
1511 | *
|
---|
1512 | * This api provides a linked list to managed external references to
|
---|
1513 | * COM objects.
|
---|
1514 | *
|
---|
1515 | * The public interface consists of three calls:
|
---|
1516 | * COM_ExternalLockAddRef
|
---|
1517 | * COM_ExternalLockRelease
|
---|
1518 | * COM_ExternalLockFreeList
|
---|
1519 | */
|
---|
1520 |
|
---|
1521 | #define EL_END_OF_LIST 0
|
---|
1522 | #define EL_NOT_FOUND 0
|
---|
1523 |
|
---|
1524 | /*
|
---|
1525 | * Declaration of the static structure that manage the
|
---|
1526 | * external lock to COM objects.
|
---|
1527 | */
|
---|
1528 | typedef struct COM_ExternalLock COM_ExternalLock;
|
---|
1529 | typedef struct COM_ExternalLockList COM_ExternalLockList;
|
---|
1530 |
|
---|
1531 | struct COM_ExternalLock
|
---|
1532 | {
|
---|
1533 | IUnknown *pUnk; /* IUnknown referenced */
|
---|
1534 | ULONG uRefCount; /* external lock counter to IUnknown object*/
|
---|
1535 | COM_ExternalLock *next; /* Pointer to next element in list */
|
---|
1536 | };
|
---|
1537 |
|
---|
1538 | struct COM_ExternalLockList
|
---|
1539 | {
|
---|
1540 | COM_ExternalLock *head; /* head of list */
|
---|
1541 | };
|
---|
1542 |
|
---|
1543 | /*
|
---|
1544 | * Declaration and initialization of the static structure that manages
|
---|
1545 | * the external lock to COM objects.
|
---|
1546 | */
|
---|
1547 | static COM_ExternalLockList elList = { EL_END_OF_LIST };
|
---|
1548 |
|
---|
1549 | /*
|
---|
1550 | * Private methods used to managed the linked list
|
---|
1551 | */
|
---|
1552 |
|
---|
1553 |
|
---|
1554 | static COM_ExternalLock* COM_ExternalLockLocate(
|
---|
1555 | COM_ExternalLock *element,
|
---|
1556 | IUnknown *pUnk);
|
---|
1557 |
|
---|
1558 | /****************************************************************************
|
---|
1559 | * Internal - Insert a new IUnknown* to the linked list
|
---|
1560 | */
|
---|
1561 | static BOOL COM_ExternalLockInsert(
|
---|
1562 | IUnknown *pUnk)
|
---|
1563 | {
|
---|
1564 | COM_ExternalLock *newLock = NULL;
|
---|
1565 | COM_ExternalLock *previousHead = NULL;
|
---|
1566 |
|
---|
1567 | /*
|
---|
1568 | * Allocate space for the new storage object
|
---|
1569 | */
|
---|
1570 | newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
|
---|
1571 |
|
---|
1572 | if (newLock!=NULL) {
|
---|
1573 | if ( elList.head == EL_END_OF_LIST ) {
|
---|
1574 | elList.head = newLock; /* The list is empty */
|
---|
1575 | } else {
|
---|
1576 | /* insert does it at the head */
|
---|
1577 | previousHead = elList.head;
|
---|
1578 | elList.head = newLock;
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | /* Set new list item data member */
|
---|
1582 | newLock->pUnk = pUnk;
|
---|
1583 | newLock->uRefCount = 1;
|
---|
1584 | newLock->next = previousHead;
|
---|
1585 |
|
---|
1586 | return TRUE;
|
---|
1587 | }
|
---|
1588 | return FALSE;
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | /****************************************************************************
|
---|
1592 | * Internal - Method that removes an item from the linked list.
|
---|
1593 | */
|
---|
1594 | static void COM_ExternalLockDelete(
|
---|
1595 | COM_ExternalLock *itemList)
|
---|
1596 | {
|
---|
1597 | COM_ExternalLock *current = elList.head;
|
---|
1598 |
|
---|
1599 | if ( current == itemList ) {
|
---|
1600 | /* this section handles the deletion of the first node */
|
---|
1601 | elList.head = itemList->next;
|
---|
1602 | HeapFree( GetProcessHeap(), 0, itemList);
|
---|
1603 | } else {
|
---|
1604 | do {
|
---|
1605 | if ( current->next == itemList ){ /* We found the item to free */
|
---|
1606 | current->next = itemList->next; /* readjust the list pointers */
|
---|
1607 | HeapFree( GetProcessHeap(), 0, itemList);
|
---|
1608 | break;
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | /* Skip to the next item */
|
---|
1612 | current = current->next;
|
---|
1613 |
|
---|
1614 | } while ( current != EL_END_OF_LIST );
|
---|
1615 | }
|
---|
1616 | }
|
---|
1617 |
|
---|
1618 | /****************************************************************************
|
---|
1619 | * Internal - Recursivity agent for IUnknownExternalLockList_Find
|
---|
1620 | *
|
---|
1621 | * NOTES: how long can the list be ?? (recursive!!!)
|
---|
1622 | */
|
---|
1623 | static COM_ExternalLock* COM_ExternalLockLocate( COM_ExternalLock *element, IUnknown *pUnk)
|
---|
1624 | {
|
---|
1625 | if ( element == EL_END_OF_LIST )
|
---|
1626 | return EL_NOT_FOUND;
|
---|
1627 | else if ( element->pUnk == pUnk ) /* We found it */
|
---|
1628 | return element;
|
---|
1629 | else /* Not the right guy, keep on looking */
|
---|
1630 | return COM_ExternalLockLocate( element->next, pUnk);
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | /****************************************************************************
|
---|
1634 | * Public - Method that increments the count for a IUnknown* in the linked
|
---|
1635 | * list. The item is inserted if not already in the list.
|
---|
1636 | */
|
---|
1637 | static void COM_ExternalLockAddRef(IUnknown *pUnk)
|
---|
1638 | {
|
---|
1639 | COM_ExternalLock *externalLock = COM_ExternalLockLocate(elList.head, pUnk);
|
---|
1640 |
|
---|
1641 | /*
|
---|
1642 | * Add an external lock to the object. If it was already externally
|
---|
1643 | * locked, just increase the reference count. If it was not.
|
---|
1644 | * add the item to the list.
|
---|
1645 | */
|
---|
1646 | if ( externalLock == EL_NOT_FOUND )
|
---|
1647 | COM_ExternalLockInsert(pUnk);
|
---|
1648 | else
|
---|
1649 | externalLock->uRefCount++;
|
---|
1650 |
|
---|
1651 | /*
|
---|
1652 | * Add an internal lock to the object
|
---|
1653 | */
|
---|
1654 | IUnknown_AddRef(pUnk);
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | /****************************************************************************
|
---|
1658 | * Public - Method that decrements the count for a IUnknown* in the linked
|
---|
1659 | * list. The item is removed from the list if its count end up at zero or if
|
---|
1660 | * bRelAll is TRUE.
|
---|
1661 | */
|
---|
1662 | static void COM_ExternalLockRelease(
|
---|
1663 | IUnknown *pUnk,
|
---|
1664 | BOOL bRelAll)
|
---|
1665 | {
|
---|
1666 | COM_ExternalLock *externalLock = COM_ExternalLockLocate(elList.head, pUnk);
|
---|
1667 |
|
---|
1668 | if ( externalLock != EL_NOT_FOUND ) {
|
---|
1669 | do {
|
---|
1670 | externalLock->uRefCount--; /* release external locks */
|
---|
1671 | IUnknown_Release(pUnk); /* release local locks as well */
|
---|
1672 |
|
---|
1673 | if ( bRelAll == FALSE ) break; /* perform single release */
|
---|
1674 |
|
---|
1675 | } while ( externalLock->uRefCount > 0 );
|
---|
1676 |
|
---|
1677 | if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
|
---|
1678 | COM_ExternalLockDelete(externalLock);
|
---|
1679 | }
|
---|
1680 | }
|
---|
1681 | /****************************************************************************
|
---|
1682 | * Public - Method that frees the content of the list.
|
---|
1683 | */
|
---|
1684 | static void COM_ExternalLockFreeList()
|
---|
1685 | {
|
---|
1686 | COM_ExternalLock *head;
|
---|
1687 |
|
---|
1688 | head = elList.head; /* grab it by the head */
|
---|
1689 | while ( head != EL_END_OF_LIST ) {
|
---|
1690 | COM_ExternalLockDelete(head); /* get rid of the head stuff */
|
---|
1691 | head = elList.head; /* get the new head... */
|
---|
1692 | }
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | /****************************************************************************
|
---|
1696 | * Public - Method that dump the content of the list.
|
---|
1697 | */
|
---|
1698 | void COM_ExternalLockDump()
|
---|
1699 | {
|
---|
1700 | COM_ExternalLock *current = elList.head;
|
---|
1701 |
|
---|
1702 | DPRINTF("\nExternal lock list contains:\n");
|
---|
1703 |
|
---|
1704 | while ( current != EL_END_OF_LIST ) {
|
---|
1705 | DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
|
---|
1706 |
|
---|
1707 | /* Skip to the next item */
|
---|
1708 | current = current->next;
|
---|
1709 | }
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | /******************************************************************************
|
---|
1713 | * CoLockObjectExternal [OLE32.31]
|
---|
1714 | */
|
---|
1715 | HRESULT WINAPI CoLockObjectExternal(
|
---|
1716 | LPUNKNOWN pUnk, /* [in] object to be locked */
|
---|
1717 | BOOL fLock, /* [in] do lock */
|
---|
1718 | BOOL fLastUnlockReleases) /* [in] unlock all */
|
---|
1719 | {
|
---|
1720 |
|
---|
1721 | if (fLock) {
|
---|
1722 | /*
|
---|
1723 | * Increment the external lock coutner, COM_ExternalLockAddRef also
|
---|
1724 | * increment the object's internal lock counter.
|
---|
1725 | */
|
---|
1726 | COM_ExternalLockAddRef( pUnk);
|
---|
1727 | } else {
|
---|
1728 | /*
|
---|
1729 | * Decrement the external lock coutner, COM_ExternalLockRelease also
|
---|
1730 | * decrement the object's internal lock counter.
|
---|
1731 | */
|
---|
1732 | COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | return S_OK;
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 | /***********************************************************************
|
---|
1739 | * CoInitializeWOW (OLE32.27)
|
---|
1740 | */
|
---|
1741 | HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
|
---|
1742 | FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
|
---|
1743 | return 0;
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | static IUnknown * pUnkState = 0; /* FIXME: thread local */
|
---|
1747 | static int nStatCounter = 0; /* global */
|
---|
1748 | static HMODULE hOleAut32 = 0; /* global */
|
---|
1749 |
|
---|
1750 | /***********************************************************************
|
---|
1751 | * CoGetState [OLE32.24]
|
---|
1752 | *
|
---|
1753 | * NOTES: might be incomplete
|
---|
1754 | */
|
---|
1755 | HRESULT WINAPI CoGetState(IUnknown ** ppv)
|
---|
1756 | {
|
---|
1757 | FIXME("\n");
|
---|
1758 |
|
---|
1759 | if(pUnkState) {
|
---|
1760 | IUnknown_AddRef(pUnkState);
|
---|
1761 | *ppv = pUnkState;
|
---|
1762 | FIXME("-- %p\n", *ppv);
|
---|
1763 | return S_OK;
|
---|
1764 | }
|
---|
1765 | *ppv = NULL;
|
---|
1766 | return E_FAIL;
|
---|
1767 |
|
---|
1768 | }
|
---|
1769 |
|
---|
1770 | /***********************************************************************
|
---|
1771 | * CoSetState [OLE32.42]
|
---|
1772 | *
|
---|
1773 | * NOTES: FIXME: protect this with a crst
|
---|
1774 | */
|
---|
1775 | HRESULT WINAPI CoSetState(IUnknown * pv)
|
---|
1776 | {
|
---|
1777 | FIXME("(%p),stub!\n", pv);
|
---|
1778 |
|
---|
1779 | if (pv) {
|
---|
1780 | IUnknown_AddRef(pv);
|
---|
1781 | nStatCounter++;
|
---|
1782 | if (nStatCounter == 1) LoadLibraryA("OLEAUT32.DLL");
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | if (pUnkState) {
|
---|
1786 | TRACE("-- release %p now\n", pUnkState);
|
---|
1787 | IUnknown_Release(pUnkState);
|
---|
1788 | nStatCounter--;
|
---|
1789 | if (!nStatCounter) FreeLibrary(hOleAut32);
|
---|
1790 | }
|
---|
1791 | pUnkState = pv;
|
---|
1792 | return S_OK;
|
---|
1793 | }
|
---|
1794 |
|
---|
1795 |
|
---|
1796 | /******************************************************************************
|
---|
1797 | * OleGetAutoConvert [OLE32.104]
|
---|
1798 | */
|
---|
1799 | HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
|
---|
1800 | {
|
---|
1801 | HKEY hkey = 0;
|
---|
1802 | char buf[200];
|
---|
1803 | WCHAR wbuf[200];
|
---|
1804 | DWORD len;
|
---|
1805 | HRESULT res = S_OK;
|
---|
1806 |
|
---|
1807 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
1808 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
1809 | {
|
---|
1810 | res = REGDB_E_CLASSNOTREG;
|
---|
1811 | goto done;
|
---|
1812 | }
|
---|
1813 | len = 200;
|
---|
1814 | /* we can just query for the default value of AutoConvertTo key like that,
|
---|
1815 | without opening the AutoConvertTo key and querying for NULL (default) */
|
---|
1816 | if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
|
---|
1817 | {
|
---|
1818 | res = REGDB_E_KEYMISSING;
|
---|
1819 | goto done;
|
---|
1820 | }
|
---|
1821 | MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
|
---|
1822 | CLSIDFromString(wbuf,pClsidNew);
|
---|
1823 | done:
|
---|
1824 | if (hkey) RegCloseKey(hkey);
|
---|
1825 | return res;
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | /******************************************************************************
|
---|
1829 | * OleSetAutoConvert [OLE32.126]
|
---|
1830 | */
|
---|
1831 | HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
|
---|
1832 | {
|
---|
1833 | HKEY hkey = 0;
|
---|
1834 | char buf[200], szClsidNew[200];
|
---|
1835 | HRESULT res = S_OK;
|
---|
1836 |
|
---|
1837 | TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
---|
1838 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
1839 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
---|
1840 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
1841 | {
|
---|
1842 | res = REGDB_E_CLASSNOTREG;
|
---|
1843 | goto done;
|
---|
1844 | }
|
---|
1845 | if (RegSetValueA(hkey, "AutoConvertTo", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
---|
1846 | {
|
---|
1847 | res = REGDB_E_WRITEREGDB;
|
---|
1848 | goto done;
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | done:
|
---|
1852 | if (hkey) RegCloseKey(hkey);
|
---|
1853 | return res;
|
---|
1854 | }
|
---|
1855 |
|
---|
1856 | /******************************************************************************
|
---|
1857 | * CoTreatAsClass [OLE32.46]
|
---|
1858 | */
|
---|
1859 | HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
|
---|
1860 | {
|
---|
1861 | HKEY hkey = 0;
|
---|
1862 | char buf[200], szClsidNew[200];
|
---|
1863 | HRESULT res = S_OK;
|
---|
1864 |
|
---|
1865 | FIXME("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
---|
1866 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
1867 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
---|
1868 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
1869 | {
|
---|
1870 | res = REGDB_E_CLASSNOTREG;
|
---|
1871 | goto done;
|
---|
1872 | }
|
---|
1873 | if (RegSetValueA(hkey, "AutoTreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
---|
1874 | {
|
---|
1875 | res = REGDB_E_WRITEREGDB;
|
---|
1876 | goto done;
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | done:
|
---|
1880 | if (hkey) RegCloseKey(hkey);
|
---|
1881 | return res;
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 |
|
---|
1885 | /***********************************************************************
|
---|
1886 | * IsEqualGUID [OLE32.76]
|
---|
1887 | *
|
---|
1888 | * Compares two Unique Identifiers.
|
---|
1889 | *
|
---|
1890 | * RETURNS
|
---|
1891 | * TRUE if equal
|
---|
1892 | */
|
---|
1893 | #undef IsEqualGUID
|
---|
1894 | BOOL WINAPI IsEqualGUID(
|
---|
1895 | REFGUID rguid1, /* [in] unique id 1 */
|
---|
1896 | REFGUID rguid2 /* [in] unique id 2 */
|
---|
1897 | )
|
---|
1898 | {
|
---|
1899 | return !memcmp(rguid1,rguid2,sizeof(GUID));
|
---|
1900 | }
|
---|
1901 |
|
---|
1902 | /***********************************************************************
|
---|
1903 | * CoInitializeSecurity [OLE32.164]
|
---|
1904 | */
|
---|
1905 | HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc,
|
---|
1906 | SOLE_AUTHENTICATION_SERVICE* asAuthSvc,
|
---|
1907 | void* pReserved1, DWORD dwAuthnLevel,
|
---|
1908 | DWORD dwImpLevel, void* pReserved2,
|
---|
1909 | DWORD dwCapabilities, void* pReserved3)
|
---|
1910 | {
|
---|
1911 | FIXME("(%p,%ld,%p,%p,%ld,%ld,%p,%ld,%p) - stub!\n", pSecDesc, cAuthSvc,
|
---|
1912 | asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pReserved2,
|
---|
1913 | dwCapabilities, pReserved3);
|
---|
1914 | return S_OK;
|
---|
1915 | }
|
---|