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 "wine/winbase16.h"
|
---|
49 | #include "compobj_private.h"
|
---|
50 | #include "ifs.h"
|
---|
51 |
|
---|
52 | #include "wine/debug.h"
|
---|
53 |
|
---|
54 | WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
---|
55 |
|
---|
56 | /****************************************************************************
|
---|
57 | * COM External Lock structures and methods declaration
|
---|
58 | *
|
---|
59 | * This api provides a linked list to managed external references to
|
---|
60 | * COM objects.
|
---|
61 | *
|
---|
62 | * The public interface consists of three calls:
|
---|
63 | * COM_ExternalLockAddRef
|
---|
64 | * COM_ExternalLockRelease
|
---|
65 | * COM_ExternalLockFreeList
|
---|
66 | */
|
---|
67 |
|
---|
68 | #define EL_END_OF_LIST 0
|
---|
69 | #define EL_NOT_FOUND 0
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * Declaration of the static structure that manage the
|
---|
73 | * external lock to COM objects.
|
---|
74 | */
|
---|
75 | typedef struct COM_ExternalLock COM_ExternalLock;
|
---|
76 | typedef struct COM_ExternalLockList COM_ExternalLockList;
|
---|
77 |
|
---|
78 | struct COM_ExternalLock
|
---|
79 | {
|
---|
80 | IUnknown *pUnk; /* IUnknown referenced */
|
---|
81 | ULONG uRefCount; /* external lock counter to IUnknown object*/
|
---|
82 | COM_ExternalLock *next; /* Pointer to next element in list */
|
---|
83 | };
|
---|
84 |
|
---|
85 | struct COM_ExternalLockList
|
---|
86 | {
|
---|
87 | COM_ExternalLock *head; /* head of list */
|
---|
88 | };
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * Declaration and initialization of the static structure that manages
|
---|
92 | * the external lock to COM objects.
|
---|
93 | */
|
---|
94 | static COM_ExternalLockList elList = { EL_END_OF_LIST };
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * Public Interface to the external lock list
|
---|
98 | */
|
---|
99 | static void COM_ExternalLockFreeList();
|
---|
100 | static void COM_ExternalLockAddRef(IUnknown *pUnk);
|
---|
101 | static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
|
---|
102 | void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Private methods used to managed the linked list
|
---|
106 | */
|
---|
107 | static BOOL COM_ExternalLockInsert(
|
---|
108 | IUnknown *pUnk);
|
---|
109 |
|
---|
110 | static void COM_ExternalLockDelete(
|
---|
111 | COM_ExternalLock *element);
|
---|
112 |
|
---|
113 | static COM_ExternalLock* COM_ExternalLockFind(
|
---|
114 | IUnknown *pUnk);
|
---|
115 |
|
---|
116 | static COM_ExternalLock* COM_ExternalLockLocate(
|
---|
117 | COM_ExternalLock *element,
|
---|
118 | IUnknown *pUnk);
|
---|
119 |
|
---|
120 | /****************************************************************************
|
---|
121 | * This section defines variables internal to the COM module.
|
---|
122 | *
|
---|
123 | * TODO: Most of these things will have to be made thread-safe.
|
---|
124 | */
|
---|
125 | HINSTANCE16 COMPOBJ_hInstance = 0;
|
---|
126 | HINSTANCE COMPOBJ_hInstance32 = 0;
|
---|
127 | static int COMPOBJ_Attach = 0;
|
---|
128 |
|
---|
129 | LPMALLOC16 currentMalloc16=NULL;
|
---|
130 | LPMALLOC currentMalloc32=NULL;
|
---|
131 |
|
---|
132 | HTASK16 hETask = 0;
|
---|
133 | WORD Table_ETask[62];
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * This lock count counts the number of times CoInitialize is called. It is
|
---|
137 | * decreased every time CoUninitialize is called. When it hits 0, the COM
|
---|
138 | * libraries are freed
|
---|
139 | */
|
---|
140 | static LONG s_COMLockCount = 0;
|
---|
141 |
|
---|
142 | /*
|
---|
143 | * This linked list contains the list of registered class objects. These
|
---|
144 | * are mostly used to register the factories for out-of-proc servers of OLE
|
---|
145 | * objects.
|
---|
146 | *
|
---|
147 | * TODO: Make this data structure aware of inter-process communication. This
|
---|
148 | * means that parts of this will be exported to the Wine Server.
|
---|
149 | */
|
---|
150 | typedef struct tagRegisteredClass
|
---|
151 | {
|
---|
152 | CLSID classIdentifier;
|
---|
153 | LPUNKNOWN classObject;
|
---|
154 | DWORD runContext;
|
---|
155 | DWORD connectFlags;
|
---|
156 | DWORD dwCookie;
|
---|
157 | HANDLE hThread; /* only for localserver */
|
---|
158 | struct tagRegisteredClass* nextClass;
|
---|
159 | } RegisteredClass;
|
---|
160 |
|
---|
161 | static CRITICAL_SECTION csRegisteredClassList;
|
---|
162 | static RegisteredClass* firstRegisteredClass = NULL;
|
---|
163 |
|
---|
164 | /* this open DLL table belongs in a per process table, but my guess is that
|
---|
165 | * it shouldn't live in the kernel, so I'll put them out here in DLL
|
---|
166 | * space assuming that there is one OLE32 per process.
|
---|
167 | */
|
---|
168 | typedef struct tagOpenDll {
|
---|
169 | HINSTANCE hLibrary;
|
---|
170 | struct tagOpenDll *next;
|
---|
171 | } OpenDll;
|
---|
172 |
|
---|
173 | static CRITICAL_SECTION csOpenDllList;
|
---|
174 | static OpenDll *openDllList = NULL; /* linked list of open dlls */
|
---|
175 |
|
---|
176 | /*****************************************************************************
|
---|
177 | * This section contains prototypes to internal methods for this
|
---|
178 | * module
|
---|
179 | */
|
---|
180 | static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
|
---|
181 | DWORD dwClsContext,
|
---|
182 | LPUNKNOWN* ppUnk);
|
---|
183 |
|
---|
184 | static void COM_RevokeAllClasses();
|
---|
185 |
|
---|
186 |
|
---|
187 | /******************************************************************************
|
---|
188 | * Initialize/Uninitialize critical sections.
|
---|
189 | */
|
---|
190 | void COMPOBJ_InitProcess( void )
|
---|
191 | {
|
---|
192 | InitializeCriticalSection( &csRegisteredClassList );
|
---|
193 | InitializeCriticalSection( &csOpenDllList );
|
---|
194 | }
|
---|
195 |
|
---|
196 | void COMPOBJ_UninitProcess( void )
|
---|
197 | {
|
---|
198 | DeleteCriticalSection( &csRegisteredClassList );
|
---|
199 | DeleteCriticalSection( &csOpenDllList );
|
---|
200 | }
|
---|
201 |
|
---|
202 | /******************************************************************************
|
---|
203 | * CoBuildVersion [COMPOBJ.1]
|
---|
204 | * CoBuildVersion [OLE32.4]
|
---|
205 | *
|
---|
206 | * RETURNS
|
---|
207 | * Current build version, hiword is majornumber, loword is minornumber
|
---|
208 | */
|
---|
209 | DWORD WINAPI CoBuildVersion(void)
|
---|
210 | {
|
---|
211 | TRACE("Returning version %d, build %d.\n", rmm, rup);
|
---|
212 | return (rmm<<16)+rup;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /******************************************************************************
|
---|
216 | * CoInitialize [COMPOBJ.2]
|
---|
217 | * Set the win16 IMalloc used for memory management
|
---|
218 | */
|
---|
219 | HRESULT WINAPI CoInitialize16(
|
---|
220 | LPVOID lpReserved /* [in] pointer to win16 malloc interface */
|
---|
221 | ) {
|
---|
222 | currentMalloc16 = (LPMALLOC16)lpReserved;
|
---|
223 | return S_OK;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /******************************************************************************
|
---|
227 | * CoInitialize [OLE32.26]
|
---|
228 | *
|
---|
229 | * Initializes the COM libraries.
|
---|
230 | *
|
---|
231 | * See CoInitializeEx
|
---|
232 | */
|
---|
233 | HRESULT WINAPI CoInitialize(
|
---|
234 | LPVOID lpReserved /* [in] pointer to win32 malloc interface
|
---|
235 | (obsolete, should be NULL) */
|
---|
236 | )
|
---|
237 | {
|
---|
238 | /*
|
---|
239 | * Just delegate to the newer method.
|
---|
240 | */
|
---|
241 | return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /******************************************************************************
|
---|
245 | * CoInitializeEx [OLE32.163]
|
---|
246 | *
|
---|
247 | * Initializes the COM libraries. The behavior used to set the win32 IMalloc
|
---|
248 | * used for memory management is obsolete.
|
---|
249 | *
|
---|
250 | * RETURNS
|
---|
251 | * S_OK if successful,
|
---|
252 | * S_FALSE if this function was called already.
|
---|
253 | * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
|
---|
254 | * threading model.
|
---|
255 | *
|
---|
256 | * BUGS
|
---|
257 | * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
|
---|
258 | * is never returned.
|
---|
259 | *
|
---|
260 | * See the windows documentation for more details.
|
---|
261 | */
|
---|
262 | HRESULT WINAPI CoInitializeEx(
|
---|
263 | LPVOID lpReserved, /* [in] pointer to win32 malloc interface
|
---|
264 | (obsolete, should be NULL) */
|
---|
265 | DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
|
---|
266 | )
|
---|
267 | {
|
---|
268 | HRESULT hr;
|
---|
269 |
|
---|
270 | TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
|
---|
271 |
|
---|
272 | if (lpReserved!=NULL)
|
---|
273 | {
|
---|
274 | ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
|
---|
275 | }
|
---|
276 |
|
---|
277 | /*
|
---|
278 | * Check for unsupported features.
|
---|
279 | */
|
---|
280 | if (dwCoInit!=COINIT_APARTMENTTHREADED)
|
---|
281 | {
|
---|
282 | FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
|
---|
283 | /* Hope for the best and continue anyway */
|
---|
284 | }
|
---|
285 |
|
---|
286 | /*
|
---|
287 | * Check the lock count. If this is the first time going through the initialize
|
---|
288 | * process, we have to initialize the libraries.
|
---|
289 | *
|
---|
290 | * And crank-up that lock count.
|
---|
291 | */
|
---|
292 | if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
|
---|
293 | {
|
---|
294 | /*
|
---|
295 | * Initialize the various COM libraries and data structures.
|
---|
296 | */
|
---|
297 | TRACE("() - Initializing the COM libraries\n");
|
---|
298 |
|
---|
299 |
|
---|
300 | RunningObjectTableImpl_Initialize();
|
---|
301 |
|
---|
302 | hr = S_OK;
|
---|
303 | }
|
---|
304 | else
|
---|
305 | hr = S_FALSE;
|
---|
306 |
|
---|
307 | return hr;
|
---|
308 | }
|
---|
309 |
|
---|
310 | /***********************************************************************
|
---|
311 | * CoUninitialize [COMPOBJ.3]
|
---|
312 | * Don't know what it does.
|
---|
313 | * 3-Nov-98 -- this was originally misspelled, I changed it to what I
|
---|
314 | * believe is the correct spelling
|
---|
315 | */
|
---|
316 | void WINAPI CoUninitialize16(void)
|
---|
317 | {
|
---|
318 | TRACE("()\n");
|
---|
319 | CoFreeAllLibraries();
|
---|
320 | }
|
---|
321 |
|
---|
322 | /***********************************************************************
|
---|
323 | * CoUninitialize [OLE32.47]
|
---|
324 | *
|
---|
325 | * This method will release the COM libraries.
|
---|
326 | *
|
---|
327 | * See the windows documentation for more details.
|
---|
328 | */
|
---|
329 | void WINAPI CoUninitialize(void)
|
---|
330 | {
|
---|
331 | LONG lCOMRefCnt;
|
---|
332 | TRACE("()\n");
|
---|
333 |
|
---|
334 | /*
|
---|
335 | * Decrease the reference count.
|
---|
336 | * If we are back to 0 locks on the COM library, make sure we free
|
---|
337 | * all the associated data structures.
|
---|
338 | */
|
---|
339 | lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
|
---|
340 | if (lCOMRefCnt==1)
|
---|
341 | {
|
---|
342 | /*
|
---|
343 | * Release the various COM libraries and data structures.
|
---|
344 | */
|
---|
345 | TRACE("() - Releasing the COM libraries\n");
|
---|
346 |
|
---|
347 | RunningObjectTableImpl_UnInitialize();
|
---|
348 | /*
|
---|
349 | * Release the references to the registered class objects.
|
---|
350 | */
|
---|
351 | COM_RevokeAllClasses();
|
---|
352 |
|
---|
353 | /*
|
---|
354 | * This will free the loaded COM Dlls.
|
---|
355 | */
|
---|
356 | CoFreeAllLibraries();
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * This will free list of external references to COM objects.
|
---|
360 | */
|
---|
361 | COM_ExternalLockFreeList();
|
---|
362 |
|
---|
363 | }
|
---|
364 | else if (lCOMRefCnt<1) {
|
---|
365 | ERR( "CoUninitialize() - not CoInitialized.\n" );
|
---|
366 | InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | #ifndef __WIN32OS2__
|
---|
371 | /***********************************************************************
|
---|
372 | * CoGetMalloc [COMPOBJ.4]
|
---|
373 | * RETURNS
|
---|
374 | * The current win16 IMalloc
|
---|
375 | */
|
---|
376 | HRESULT WINAPI CoGetMalloc16(
|
---|
377 | DWORD dwMemContext, /* [in] unknown */
|
---|
378 | LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
|
---|
379 | ) {
|
---|
380 | if(!currentMalloc16)
|
---|
381 | currentMalloc16 = IMalloc16_Constructor();
|
---|
382 | *lpMalloc = currentMalloc16;
|
---|
383 | return S_OK;
|
---|
384 | }
|
---|
385 | #endif
|
---|
386 | /******************************************************************************
|
---|
387 | * CoGetMalloc [OLE32.20]
|
---|
388 | *
|
---|
389 | * RETURNS
|
---|
390 | * The current win32 IMalloc
|
---|
391 | */
|
---|
392 | HRESULT WINAPI CoGetMalloc(
|
---|
393 | DWORD dwMemContext, /* [in] unknown */
|
---|
394 | LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
|
---|
395 | ) {
|
---|
396 | if(!currentMalloc32)
|
---|
397 | currentMalloc32 = IMalloc_Constructor();
|
---|
398 | *lpMalloc = currentMalloc32;
|
---|
399 | return S_OK;
|
---|
400 | }
|
---|
401 | #ifndef __WIN32OS2__
|
---|
402 | /***********************************************************************
|
---|
403 | * CoCreateStandardMalloc [COMPOBJ.71]
|
---|
404 | */
|
---|
405 | HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
|
---|
406 | LPMALLOC16 *lpMalloc)
|
---|
407 | {
|
---|
408 | /* FIXME: docu says we shouldn't return the same allocator as in
|
---|
409 | * CoGetMalloc16 */
|
---|
410 | *lpMalloc = IMalloc16_Constructor();
|
---|
411 | return S_OK;
|
---|
412 | }
|
---|
413 | #endif
|
---|
414 | /******************************************************************************
|
---|
415 | * CoDisconnectObject [COMPOBJ.15]
|
---|
416 | * CoDisconnectObject [OLE32.8]
|
---|
417 | */
|
---|
418 | HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
|
---|
419 | {
|
---|
420 | TRACE("(%p, %lx)\n",lpUnk,reserved);
|
---|
421 | return S_OK;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /***********************************************************************
|
---|
425 | * IsEqualGUID [COMPOBJ.18]
|
---|
426 | *
|
---|
427 | * Compares two Unique Identifiers.
|
---|
428 | *
|
---|
429 | * RETURNS
|
---|
430 | * TRUE if equal
|
---|
431 | */
|
---|
432 | BOOL16 WINAPI IsEqualGUID16(
|
---|
433 | GUID* g1, /* [in] unique id 1 */
|
---|
434 | GUID* g2 /* [in] unique id 2 */
|
---|
435 | ) {
|
---|
436 | return !memcmp( g1, g2, sizeof(GUID) );
|
---|
437 | }
|
---|
438 |
|
---|
439 | /******************************************************************************
|
---|
440 | * CLSIDFromString [COMPOBJ.20]
|
---|
441 | * Converts a unique identifier from its string representation into
|
---|
442 | * the GUID struct.
|
---|
443 | *
|
---|
444 | * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
|
---|
445 | *
|
---|
446 | * RETURNS
|
---|
447 | * the converted GUID
|
---|
448 | */
|
---|
449 | HRESULT WINAPI CLSIDFromString16(
|
---|
450 | LPCOLESTR16 idstr, /* [in] string representation of guid */
|
---|
451 | CLSID *id /* [out] GUID converted from string */
|
---|
452 | ) {
|
---|
453 | BYTE *s = (BYTE *) idstr;
|
---|
454 | BYTE *p;
|
---|
455 | int i;
|
---|
456 | BYTE table[256];
|
---|
457 |
|
---|
458 | if (!s)
|
---|
459 | s = "{00000000-0000-0000-0000-000000000000}";
|
---|
460 | else { /* validate the CLSID string */
|
---|
461 |
|
---|
462 | if (strlen(s) != 38)
|
---|
463 | return CO_E_CLASSSTRING;
|
---|
464 |
|
---|
465 | if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
|
---|
466 | return CO_E_CLASSSTRING;
|
---|
467 |
|
---|
468 | for (i=1; i<37; i++)
|
---|
469 | {
|
---|
470 | if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
|
---|
471 | if (!(((s[i] >= '0') && (s[i] <= '9')) ||
|
---|
472 | ((s[i] >= 'a') && (s[i] <= 'f')) ||
|
---|
473 | ((s[i] >= 'A') && (s[i] <= 'F')))
|
---|
474 | )
|
---|
475 | return CO_E_CLASSSTRING;
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | TRACE("%s -> %p\n", s, id);
|
---|
480 |
|
---|
481 | /* quick lookup table */
|
---|
482 | memset(table, 0, 256);
|
---|
483 |
|
---|
484 | for (i = 0; i < 10; i++) {
|
---|
485 | table['0' + i] = i;
|
---|
486 | }
|
---|
487 | for (i = 0; i < 6; i++) {
|
---|
488 | table['A' + i] = i+10;
|
---|
489 | table['a' + i] = i+10;
|
---|
490 | }
|
---|
491 |
|
---|
492 | /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
|
---|
493 |
|
---|
494 | p = (BYTE *) id;
|
---|
495 |
|
---|
496 | s++; /* skip leading brace */
|
---|
497 | for (i = 0; i < 4; i++) {
|
---|
498 | p[3 - i] = table[*s]<<4 | table[*(s+1)];
|
---|
499 | s += 2;
|
---|
500 | }
|
---|
501 | p += 4;
|
---|
502 | s++; /* skip - */
|
---|
503 |
|
---|
504 | for (i = 0; i < 2; i++) {
|
---|
505 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
---|
506 | s += 2;
|
---|
507 | }
|
---|
508 | p += 2;
|
---|
509 | s++; /* skip - */
|
---|
510 |
|
---|
511 | for (i = 0; i < 2; i++) {
|
---|
512 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
---|
513 | s += 2;
|
---|
514 | }
|
---|
515 | p += 2;
|
---|
516 | s++; /* skip - */
|
---|
517 |
|
---|
518 | /* these are just sequential bytes */
|
---|
519 | for (i = 0; i < 2; i++) {
|
---|
520 | *p++ = table[*s]<<4 | table[*(s+1)];
|
---|
521 | s += 2;
|
---|
522 | }
|
---|
523 | s++; /* skip - */
|
---|
524 |
|
---|
525 | for (i = 0; i < 6; i++) {
|
---|
526 | *p++ = table[*s]<<4 | table[*(s+1)];
|
---|
527 | s += 2;
|
---|
528 | }
|
---|
529 |
|
---|
530 | return S_OK;
|
---|
531 | }
|
---|
532 |
|
---|
533 | /******************************************************************************
|
---|
534 | * CoCreateGuid[OLE32.6]
|
---|
535 | *
|
---|
536 | */
|
---|
537 | HRESULT WINAPI CoCreateGuid(
|
---|
538 | GUID *pguid /* [out] points to the GUID to initialize */
|
---|
539 | ) {
|
---|
540 | return UuidCreate(pguid);
|
---|
541 | }
|
---|
542 |
|
---|
543 | /******************************************************************************
|
---|
544 | * CLSIDFromString [OLE32.3]
|
---|
545 | * IIDFromString [OLE32.74]
|
---|
546 | * Converts a unique identifier from its string representation into
|
---|
547 | * the GUID struct.
|
---|
548 | *
|
---|
549 | * UNDOCUMENTED
|
---|
550 | * If idstr is not a valid CLSID string then it gets treated as a ProgID
|
---|
551 | *
|
---|
552 | * RETURNS
|
---|
553 | * the converted GUID
|
---|
554 | */
|
---|
555 | HRESULT WINAPI CLSIDFromString(
|
---|
556 | LPCOLESTR idstr, /* [in] string representation of GUID */
|
---|
557 | CLSID *id ) /* [out] GUID represented by above string */
|
---|
558 | {
|
---|
559 | char xid[40];
|
---|
560 | HRESULT ret;
|
---|
561 |
|
---|
562 | if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL ))
|
---|
563 | return CO_E_CLASSSTRING;
|
---|
564 | ret = CLSIDFromString16(xid,id);
|
---|
565 | if(ret != S_OK) { /* It appears a ProgID is also valid */
|
---|
566 | ret = CLSIDFromProgID(idstr, id);
|
---|
567 | }
|
---|
568 | return ret;
|
---|
569 | }
|
---|
570 |
|
---|
571 | /******************************************************************************
|
---|
572 | * WINE_StringFromCLSID [Internal]
|
---|
573 | * Converts a GUID into the respective string representation.
|
---|
574 | *
|
---|
575 | * NOTES
|
---|
576 | *
|
---|
577 | * RETURNS
|
---|
578 | * the string representation and HRESULT
|
---|
579 | */
|
---|
580 | HRESULT WINE_StringFromCLSID(
|
---|
581 | const CLSID *id, /* [in] GUID to be converted */
|
---|
582 | LPSTR idstr /* [out] pointer to buffer to contain converted guid */
|
---|
583 | ) {
|
---|
584 | static const char *hex = "0123456789ABCDEF";
|
---|
585 | char *s;
|
---|
586 | int i;
|
---|
587 |
|
---|
588 | if (!id)
|
---|
589 | { ERR("called with id=Null\n");
|
---|
590 | *idstr = 0x00;
|
---|
591 | return E_FAIL;
|
---|
592 | }
|
---|
593 |
|
---|
594 | sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
|
---|
595 | id->Data1, id->Data2, id->Data3,
|
---|
596 | id->Data4[0], id->Data4[1]);
|
---|
597 | s = &idstr[25];
|
---|
598 |
|
---|
599 | /* 6 hex bytes */
|
---|
600 | for (i = 2; i < 8; i++) {
|
---|
601 | *s++ = hex[id->Data4[i]>>4];
|
---|
602 | *s++ = hex[id->Data4[i] & 0xf];
|
---|
603 | }
|
---|
604 |
|
---|
605 | *s++ = '}';
|
---|
606 | *s++ = '\0';
|
---|
607 |
|
---|
608 | TRACE("%p->%s\n", id, idstr);
|
---|
609 |
|
---|
610 | return S_OK;
|
---|
611 | }
|
---|
612 | #ifndef __WIN32OS2__
|
---|
613 | /******************************************************************************
|
---|
614 | * StringFromCLSID [COMPOBJ.19]
|
---|
615 | * Converts a GUID into the respective string representation.
|
---|
616 | * The target string is allocated using the OLE IMalloc.
|
---|
617 | * RETURNS
|
---|
618 | * the string representation and HRESULT
|
---|
619 | */
|
---|
620 | HRESULT WINAPI StringFromCLSID16(
|
---|
621 | REFCLSID id, /* [in] the GUID to be converted */
|
---|
622 | LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
|
---|
623 |
|
---|
624 | ) {
|
---|
625 | extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
|
---|
626 | DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
|
---|
627 | LPMALLOC16 mllc;
|
---|
628 | HRESULT ret;
|
---|
629 | DWORD args[2];
|
---|
630 |
|
---|
631 | ret = CoGetMalloc16(0,&mllc);
|
---|
632 | if (ret) return ret;
|
---|
633 |
|
---|
634 | args[0] = (DWORD)mllc;
|
---|
635 | args[1] = 40;
|
---|
636 |
|
---|
637 | /* No need for a Callback entry, we have WOWCallback16Ex which does
|
---|
638 | * everything we need.
|
---|
639 | */
|
---|
640 | if (!K32WOWCallback16Ex(
|
---|
641 | (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
|
---|
642 | (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
|
---|
643 | )->Alloc,
|
---|
644 | WCB16_CDECL,
|
---|
645 | 2*sizeof(DWORD),
|
---|
646 | (LPVOID)args,
|
---|
647 | (LPDWORD)idstr
|
---|
648 | )) {
|
---|
649 | WARN("CallTo16 IMalloc16 failed\n");
|
---|
650 | return E_FAIL;
|
---|
651 | }
|
---|
652 | return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
|
---|
653 | }
|
---|
654 | #endif
|
---|
655 | /******************************************************************************
|
---|
656 | * StringFromCLSID [OLE32.151]
|
---|
657 | * StringFromIID [OLE32.153]
|
---|
658 | * Converts a GUID into the respective string representation.
|
---|
659 | * The target string is allocated using the OLE IMalloc.
|
---|
660 | * RETURNS
|
---|
661 | * the string representation and HRESULT
|
---|
662 | */
|
---|
663 | HRESULT WINAPI StringFromCLSID(
|
---|
664 | REFCLSID id, /* [in] the GUID to be converted */
|
---|
665 | LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
|
---|
666 | ) {
|
---|
667 | char buf[80];
|
---|
668 | HRESULT ret;
|
---|
669 | LPMALLOC mllc;
|
---|
670 |
|
---|
671 | if ((ret=CoGetMalloc(0,&mllc)))
|
---|
672 | return ret;
|
---|
673 |
|
---|
674 | ret=WINE_StringFromCLSID(id,buf);
|
---|
675 | if (!ret) {
|
---|
676 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
|
---|
677 | *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
|
---|
678 | MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
|
---|
679 | }
|
---|
680 | return ret;
|
---|
681 | }
|
---|
682 |
|
---|
683 | /******************************************************************************
|
---|
684 | * StringFromGUID2 [COMPOBJ.76]
|
---|
685 | * StringFromGUID2 [OLE32.152]
|
---|
686 | *
|
---|
687 | * Converts a global unique identifier into a string of an API-
|
---|
688 | * specified fixed format. (The usual {.....} stuff.)
|
---|
689 | *
|
---|
690 | * RETURNS
|
---|
691 | * The (UNICODE) string representation of the GUID in 'str'
|
---|
692 | * The length of the resulting string, 0 if there was any problem.
|
---|
693 | */
|
---|
694 | INT WINAPI
|
---|
695 | StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
|
---|
696 | {
|
---|
697 | char xguid[80];
|
---|
698 |
|
---|
699 | if (WINE_StringFromCLSID(id,xguid))
|
---|
700 | return 0;
|
---|
701 | return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
|
---|
702 | }
|
---|
703 |
|
---|
704 | /******************************************************************************
|
---|
705 | * ProgIDFromCLSID [OLE32.133]
|
---|
706 | * Converts a class id into the respective Program ID. (By using a registry lookup)
|
---|
707 | * RETURNS S_OK on success
|
---|
708 | * riid associated with the progid
|
---|
709 | */
|
---|
710 |
|
---|
711 | HRESULT WINAPI ProgIDFromCLSID(
|
---|
712 | REFCLSID clsid, /* [in] class id as found in registry */
|
---|
713 | LPOLESTR *lplpszProgID/* [out] associated Prog ID */
|
---|
714 | )
|
---|
715 | {
|
---|
716 | char strCLSID[50], *buf, *buf2;
|
---|
717 | DWORD buf2len;
|
---|
718 | HKEY xhkey;
|
---|
719 | LPMALLOC mllc;
|
---|
720 | HRESULT ret = S_OK;
|
---|
721 |
|
---|
722 | WINE_StringFromCLSID(clsid, strCLSID);
|
---|
723 |
|
---|
724 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
|
---|
725 | sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
|
---|
726 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
---|
727 | ret = REGDB_E_CLASSNOTREG;
|
---|
728 |
|
---|
729 | HeapFree(GetProcessHeap(), 0, buf);
|
---|
730 |
|
---|
731 | if (ret == S_OK)
|
---|
732 | {
|
---|
733 | buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
|
---|
734 | buf2len = 255;
|
---|
735 | if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
|
---|
736 | ret = REGDB_E_CLASSNOTREG;
|
---|
737 |
|
---|
738 | if (ret == S_OK)
|
---|
739 | {
|
---|
740 | if (CoGetMalloc(0,&mllc))
|
---|
741 | ret = E_OUTOFMEMORY;
|
---|
742 | else
|
---|
743 | {
|
---|
744 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
|
---|
745 | *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
|
---|
746 | MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
|
---|
747 | }
|
---|
748 | }
|
---|
749 | HeapFree(GetProcessHeap(), 0, buf2);
|
---|
750 | }
|
---|
751 |
|
---|
752 | RegCloseKey(xhkey);
|
---|
753 | return ret;
|
---|
754 | }
|
---|
755 |
|
---|
756 | /******************************************************************************
|
---|
757 | * CLSIDFromProgID [COMPOBJ.61]
|
---|
758 | * Converts a program id into the respective GUID. (By using a registry lookup)
|
---|
759 | * RETURNS
|
---|
760 | * riid associated with the progid
|
---|
761 | */
|
---|
762 | HRESULT WINAPI CLSIDFromProgID16(
|
---|
763 | LPCOLESTR16 progid, /* [in] program id as found in registry */
|
---|
764 | LPCLSID riid /* [out] associated CLSID */
|
---|
765 | ) {
|
---|
766 | char *buf,buf2[80];
|
---|
767 | DWORD buf2len;
|
---|
768 | HRESULT err;
|
---|
769 | HKEY xhkey;
|
---|
770 |
|
---|
771 | buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
|
---|
772 | sprintf(buf,"%s\\CLSID",progid);
|
---|
773 | if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
|
---|
774 | HeapFree(GetProcessHeap(),0,buf);
|
---|
775 | return CO_E_CLASSSTRING;
|
---|
776 | }
|
---|
777 | HeapFree(GetProcessHeap(),0,buf);
|
---|
778 | buf2len = sizeof(buf2);
|
---|
779 | if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
|
---|
780 | RegCloseKey(xhkey);
|
---|
781 | return CO_E_CLASSSTRING;
|
---|
782 | }
|
---|
783 | RegCloseKey(xhkey);
|
---|
784 | return CLSIDFromString16(buf2,riid);
|
---|
785 | }
|
---|
786 |
|
---|
787 | /******************************************************************************
|
---|
788 | * CLSIDFromProgID [OLE32.2]
|
---|
789 | * Converts a program id into the respective GUID. (By using a registry lookup)
|
---|
790 | * RETURNS
|
---|
791 | * riid associated with the progid
|
---|
792 | */
|
---|
793 | HRESULT WINAPI CLSIDFromProgID(
|
---|
794 | LPCOLESTR progid, /* [in] program id as found in registry */
|
---|
795 | LPCLSID riid ) /* [out] associated CLSID */
|
---|
796 | {
|
---|
797 | static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
|
---|
798 | char buf2[80];
|
---|
799 | DWORD buf2len = sizeof(buf2);
|
---|
800 | HKEY xhkey;
|
---|
801 |
|
---|
802 | WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
|
---|
803 | strcpyW( buf, progid );
|
---|
804 | strcatW( buf, clsidW );
|
---|
805 | if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
|
---|
806 | {
|
---|
807 | HeapFree(GetProcessHeap(),0,buf);
|
---|
808 | return CO_E_CLASSSTRING;
|
---|
809 | }
|
---|
810 | HeapFree(GetProcessHeap(),0,buf);
|
---|
811 |
|
---|
812 | if (RegQueryValueA(xhkey,NULL,buf2,&buf2len))
|
---|
813 | {
|
---|
814 | RegCloseKey(xhkey);
|
---|
815 | return CO_E_CLASSSTRING;
|
---|
816 | }
|
---|
817 | RegCloseKey(xhkey);
|
---|
818 | return CLSIDFromString16(buf2,riid);
|
---|
819 | }
|
---|
820 |
|
---|
821 |
|
---|
822 |
|
---|
823 | /*****************************************************************************
|
---|
824 | * CoGetPSClsid [OLE32.22]
|
---|
825 | *
|
---|
826 | * This function returns the CLSID of the DLL that implements the proxy and stub
|
---|
827 | * for the specified interface.
|
---|
828 | *
|
---|
829 | * It determines this by searching the
|
---|
830 | * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
|
---|
831 | * and any interface id registered by CoRegisterPSClsid within the current process.
|
---|
832 | *
|
---|
833 | * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
|
---|
834 | */
|
---|
835 | HRESULT WINAPI CoGetPSClsid(
|
---|
836 | REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
|
---|
837 | CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
|
---|
838 | {
|
---|
839 | char *buf, buf2[40];
|
---|
840 | DWORD buf2len;
|
---|
841 | HKEY xhkey;
|
---|
842 |
|
---|
843 | TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
|
---|
844 |
|
---|
845 | /* Get the input iid as a string */
|
---|
846 | WINE_StringFromCLSID(riid, buf2);
|
---|
847 | /* Allocate memory for the registry key we will construct.
|
---|
848 | (length of iid string plus constant length of static text */
|
---|
849 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
|
---|
850 | if (buf == NULL)
|
---|
851 | {
|
---|
852 | return (E_OUTOFMEMORY);
|
---|
853 | }
|
---|
854 |
|
---|
855 | /* Construct the registry key we want */
|
---|
856 | sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
|
---|
857 |
|
---|
858 | /* Open the key.. */
|
---|
859 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
---|
860 | {
|
---|
861 | HeapFree(GetProcessHeap(),0,buf);
|
---|
862 | return (E_INVALIDARG);
|
---|
863 | }
|
---|
864 | HeapFree(GetProcessHeap(),0,buf);
|
---|
865 |
|
---|
866 | /* ... Once we have the key, query the registry to get the
|
---|
867 | value of CLSID as a string, and convert it into a
|
---|
868 | proper CLSID structure to be passed back to the app */
|
---|
869 | buf2len = sizeof(buf2);
|
---|
870 | if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
|
---|
871 | {
|
---|
872 | RegCloseKey(xhkey);
|
---|
873 | return E_INVALIDARG;
|
---|
874 | }
|
---|
875 | RegCloseKey(xhkey);
|
---|
876 |
|
---|
877 | /* We have the CLSid we want back from the registry as a string, so
|
---|
878 | lets convert it into a CLSID structure */
|
---|
879 | if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
|
---|
880 | {
|
---|
881 | return E_INVALIDARG;
|
---|
882 | }
|
---|
883 |
|
---|
884 | TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
|
---|
885 | return (S_OK);
|
---|
886 | }
|
---|
887 |
|
---|
888 |
|
---|
889 |
|
---|
890 | /***********************************************************************
|
---|
891 | * WriteClassStm (OLE32.159)
|
---|
892 | *
|
---|
893 | * This function write a CLSID on stream
|
---|
894 | */
|
---|
895 | HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
|
---|
896 | {
|
---|
897 | TRACE("(%p,%p)\n",pStm,rclsid);
|
---|
898 |
|
---|
899 | if (rclsid==NULL)
|
---|
900 | return E_INVALIDARG;
|
---|
901 |
|
---|
902 | return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
|
---|
903 | }
|
---|
904 |
|
---|
905 | /***********************************************************************
|
---|
906 | * ReadClassStm (OLE32.135)
|
---|
907 | *
|
---|
908 | * This function read a CLSID from a stream
|
---|
909 | */
|
---|
910 | HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
|
---|
911 | {
|
---|
912 | ULONG nbByte;
|
---|
913 | HRESULT res;
|
---|
914 |
|
---|
915 | TRACE("(%p,%p)\n",pStm,pclsid);
|
---|
916 |
|
---|
917 | if (pclsid==NULL)
|
---|
918 | return E_INVALIDARG;
|
---|
919 |
|
---|
920 | res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
|
---|
921 |
|
---|
922 | if (FAILED(res))
|
---|
923 | return res;
|
---|
924 |
|
---|
925 | if (nbByte != sizeof(CLSID))
|
---|
926 | return S_FALSE;
|
---|
927 | else
|
---|
928 | return S_OK;
|
---|
929 | }
|
---|
930 | #ifndef __WIN32OS2__
|
---|
931 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
---|
932 | /***********************************************************************
|
---|
933 | * LookupETask (COMPOBJ.94)
|
---|
934 | */
|
---|
935 | HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
|
---|
936 | FIXME("(%p,%p),stub!\n",hTask,p);
|
---|
937 | if ((*hTask = GetCurrentTask()) == hETask) {
|
---|
938 | memcpy(p, Table_ETask, sizeof(Table_ETask));
|
---|
939 | }
|
---|
940 | return 0;
|
---|
941 | }
|
---|
942 |
|
---|
943 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
---|
944 | /***********************************************************************
|
---|
945 | * SetETask (COMPOBJ.95)
|
---|
946 | */
|
---|
947 | HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
|
---|
948 | FIXME("(%04x,%p),stub!\n",hTask,p);
|
---|
949 | hETask = hTask;
|
---|
950 | return 0;
|
---|
951 | }
|
---|
952 |
|
---|
953 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
---|
954 | /***********************************************************************
|
---|
955 | * CALLOBJECTINWOW (COMPOBJ.201)
|
---|
956 | */
|
---|
957 | HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
|
---|
958 | FIXME("(%p,%p),stub!\n",p1,p2);
|
---|
959 | return 0;
|
---|
960 | }
|
---|
961 |
|
---|
962 | /******************************************************************************
|
---|
963 | * CoRegisterClassObject [COMPOBJ.5]
|
---|
964 | *
|
---|
965 | * Don't know where it registers it ...
|
---|
966 | */
|
---|
967 | HRESULT WINAPI CoRegisterClassObject16(
|
---|
968 | REFCLSID rclsid,
|
---|
969 | LPUNKNOWN pUnk,
|
---|
970 | DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
|
---|
971 | DWORD flags, /* [in] REGCLS flags indicating how connections are made */
|
---|
972 | LPDWORD lpdwRegister
|
---|
973 | ) {
|
---|
974 | char buf[80];
|
---|
975 |
|
---|
976 | WINE_StringFromCLSID(rclsid,buf);
|
---|
977 |
|
---|
978 | FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
|
---|
979 | buf,pUnk,dwClsContext,flags,lpdwRegister
|
---|
980 | );
|
---|
981 | return 0;
|
---|
982 | }
|
---|
983 |
|
---|
984 |
|
---|
985 | /******************************************************************************
|
---|
986 | * CoRevokeClassObject [COMPOBJ.6]
|
---|
987 | *
|
---|
988 | */
|
---|
989 | HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
|
---|
990 | {
|
---|
991 | FIXME("(0x%08lx),stub!\n", dwRegister);
|
---|
992 | return 0;
|
---|
993 | }
|
---|
994 |
|
---|
995 | /******************************************************************************
|
---|
996 | * CoFileTimeToDosDateTime [COMPOBJ.30]
|
---|
997 | */
|
---|
998 | BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
|
---|
999 | {
|
---|
1000 | return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /******************************************************************************
|
---|
1004 | * CoDosDateTimeToFileTime [COMPOBJ.31]
|
---|
1005 | */
|
---|
1006 | BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
|
---|
1007 | {
|
---|
1008 | return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
|
---|
1009 | }
|
---|
1010 | #endif
|
---|
1011 | /***
|
---|
1012 | * COM_GetRegisteredClassObject
|
---|
1013 | *
|
---|
1014 | * This internal method is used to scan the registered class list to
|
---|
1015 | * find a class object.
|
---|
1016 | *
|
---|
1017 | * Params:
|
---|
1018 | * rclsid Class ID of the class to find.
|
---|
1019 | * dwClsContext Class context to match.
|
---|
1020 | * ppv [out] returns a pointer to the class object. Complying
|
---|
1021 | * to normal COM usage, this method will increase the
|
---|
1022 | * reference count on this object.
|
---|
1023 | */
|
---|
1024 | static HRESULT COM_GetRegisteredClassObject(
|
---|
1025 | REFCLSID rclsid,
|
---|
1026 | DWORD dwClsContext,
|
---|
1027 | LPUNKNOWN* ppUnk)
|
---|
1028 | {
|
---|
1029 | HRESULT hr = S_FALSE;
|
---|
1030 | RegisteredClass* curClass;
|
---|
1031 |
|
---|
1032 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1033 |
|
---|
1034 | /*
|
---|
1035 | * Sanity check
|
---|
1036 | */
|
---|
1037 | assert(ppUnk!=0);
|
---|
1038 |
|
---|
1039 | /*
|
---|
1040 | * Iterate through the whole list and try to match the class ID.
|
---|
1041 | */
|
---|
1042 | curClass = firstRegisteredClass;
|
---|
1043 |
|
---|
1044 | while (curClass != 0)
|
---|
1045 | {
|
---|
1046 | /*
|
---|
1047 | * Check if we have a match on the class ID.
|
---|
1048 | */
|
---|
1049 | if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
|
---|
1050 | {
|
---|
1051 | /*
|
---|
1052 | * Since we don't do out-of process or DCOM just right away, let's ignore the
|
---|
1053 | * class context.
|
---|
1054 | */
|
---|
1055 |
|
---|
1056 | /*
|
---|
1057 | * We have a match, return the pointer to the class object.
|
---|
1058 | */
|
---|
1059 | *ppUnk = curClass->classObject;
|
---|
1060 |
|
---|
1061 | IUnknown_AddRef(curClass->classObject);
|
---|
1062 |
|
---|
1063 | hr = S_OK;
|
---|
1064 | goto end;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | /*
|
---|
1068 | * Step to the next class in the list.
|
---|
1069 | */
|
---|
1070 | curClass = curClass->nextClass;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | end:
|
---|
1074 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1075 | /*
|
---|
1076 | * If we get to here, we haven't found our class.
|
---|
1077 | */
|
---|
1078 | return hr;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | static DWORD WINAPI
|
---|
1082 | _LocalServerThread(LPVOID param) {
|
---|
1083 | HANDLE hPipe;
|
---|
1084 | char pipefn[200];
|
---|
1085 | RegisteredClass *newClass = (RegisteredClass*)param;
|
---|
1086 | HRESULT hres;
|
---|
1087 | IStream *pStm;
|
---|
1088 | STATSTG ststg;
|
---|
1089 | unsigned char *buffer;
|
---|
1090 | int buflen;
|
---|
1091 | IClassFactory *classfac;
|
---|
1092 | LARGE_INTEGER seekto;
|
---|
1093 | ULARGE_INTEGER newpos;
|
---|
1094 | ULONG res;
|
---|
1095 |
|
---|
1096 | TRACE("Starting threader for %s.\n",debugstr_guid(&newClass->classIdentifier));
|
---|
1097 | strcpy(pipefn,PIPEPREF);
|
---|
1098 | WINE_StringFromCLSID(&newClass->classIdentifier,pipefn+strlen(PIPEPREF));
|
---|
1099 |
|
---|
1100 | hres = IUnknown_QueryInterface(newClass->classObject,&IID_IClassFactory,(LPVOID*)&classfac);
|
---|
1101 | if (hres) return hres;
|
---|
1102 |
|
---|
1103 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
---|
1104 | if (hres) {
|
---|
1105 | FIXME("Failed to create stream on hglobal.\n");
|
---|
1106 | return hres;
|
---|
1107 | }
|
---|
1108 | hres = CoMarshalInterface(pStm,&IID_IClassFactory,(LPVOID)classfac,0,NULL,0);
|
---|
1109 | if (hres) {
|
---|
1110 | FIXME("CoMarshalInterface failed, %lx!\n",hres);
|
---|
1111 | return hres;
|
---|
1112 | }
|
---|
1113 | hres = IStream_Stat(pStm,&ststg,0);
|
---|
1114 | if (hres) return hres;
|
---|
1115 |
|
---|
1116 | buflen = ststg.cbSize.s.LowPart;
|
---|
1117 | buffer = HeapAlloc(GetProcessHeap(),0,buflen);
|
---|
1118 | seekto.s.LowPart = 0;
|
---|
1119 | seekto.s.HighPart = 0;
|
---|
1120 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
---|
1121 | if (hres) {
|
---|
1122 | FIXME("IStream_Seek failed, %lx\n",hres);
|
---|
1123 | return hres;
|
---|
1124 | }
|
---|
1125 | hres = IStream_Read(pStm,buffer,buflen,&res);
|
---|
1126 | if (hres) {
|
---|
1127 | FIXME("Stream Read failed, %lx\n",hres);
|
---|
1128 | return hres;
|
---|
1129 | }
|
---|
1130 | IStream_Release(pStm);
|
---|
1131 |
|
---|
1132 | while (1) {
|
---|
1133 | hPipe = CreateNamedPipeA(
|
---|
1134 | pipefn,
|
---|
1135 | PIPE_ACCESS_DUPLEX,
|
---|
1136 | PIPE_TYPE_BYTE|PIPE_WAIT,
|
---|
1137 | PIPE_UNLIMITED_INSTANCES,
|
---|
1138 | 4096,
|
---|
1139 | 4096,
|
---|
1140 | NMPWAIT_USE_DEFAULT_WAIT,
|
---|
1141 | NULL
|
---|
1142 | );
|
---|
1143 | if (hPipe == INVALID_HANDLE_VALUE) {
|
---|
1144 | FIXME("pipe creation failed for %s, le is %lx\n",pipefn,GetLastError());
|
---|
1145 | return 1;
|
---|
1146 | }
|
---|
1147 | if (!ConnectNamedPipe(hPipe,NULL)) {
|
---|
1148 | ERR("Failure during ConnectNamedPipe %lx, ABORT!\n",GetLastError());
|
---|
1149 | CloseHandle(hPipe);
|
---|
1150 | continue;
|
---|
1151 | }
|
---|
1152 | WriteFile(hPipe,buffer,buflen,&res,NULL);
|
---|
1153 | CloseHandle(hPipe);
|
---|
1154 | }
|
---|
1155 | return 0;
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | /******************************************************************************
|
---|
1159 | * CoRegisterClassObject [OLE32.36]
|
---|
1160 | *
|
---|
1161 | * This method will register the class object for a given class ID.
|
---|
1162 | *
|
---|
1163 | * See the Windows documentation for more details.
|
---|
1164 | */
|
---|
1165 | HRESULT WINAPI CoRegisterClassObject(
|
---|
1166 | REFCLSID rclsid,
|
---|
1167 | LPUNKNOWN pUnk,
|
---|
1168 | DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
|
---|
1169 | DWORD flags, /* [in] REGCLS flags indicating how connections are made */
|
---|
1170 | LPDWORD lpdwRegister
|
---|
1171 | )
|
---|
1172 | {
|
---|
1173 | RegisteredClass* newClass;
|
---|
1174 | LPUNKNOWN foundObject;
|
---|
1175 | HRESULT hr;
|
---|
1176 |
|
---|
1177 | TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
|
---|
1178 | debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister);
|
---|
1179 |
|
---|
1180 | if ( (lpdwRegister==0) || (pUnk==0) )
|
---|
1181 | return E_INVALIDARG;
|
---|
1182 |
|
---|
1183 | *lpdwRegister = 0;
|
---|
1184 |
|
---|
1185 | /*
|
---|
1186 | * First, check if the class is already registered.
|
---|
1187 | * If it is, this should cause an error.
|
---|
1188 | */
|
---|
1189 | hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
|
---|
1190 | if (hr == S_OK) {
|
---|
1191 | IUnknown_Release(foundObject);
|
---|
1192 | return CO_E_OBJISREG;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
|
---|
1196 | if ( newClass == NULL )
|
---|
1197 | return E_OUTOFMEMORY;
|
---|
1198 |
|
---|
1199 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1200 |
|
---|
1201 | newClass->classIdentifier = *rclsid;
|
---|
1202 | newClass->runContext = dwClsContext;
|
---|
1203 | newClass->connectFlags = flags;
|
---|
1204 | /*
|
---|
1205 | * Use the address of the chain node as the cookie since we are sure it's
|
---|
1206 | * unique.
|
---|
1207 | */
|
---|
1208 | newClass->dwCookie = (DWORD)newClass;
|
---|
1209 | newClass->nextClass = firstRegisteredClass;
|
---|
1210 |
|
---|
1211 | /*
|
---|
1212 | * Since we're making a copy of the object pointer, we have to increase its
|
---|
1213 | * reference count.
|
---|
1214 | */
|
---|
1215 | newClass->classObject = pUnk;
|
---|
1216 | IUnknown_AddRef(newClass->classObject);
|
---|
1217 |
|
---|
1218 | firstRegisteredClass = newClass;
|
---|
1219 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1220 |
|
---|
1221 | *lpdwRegister = newClass->dwCookie;
|
---|
1222 |
|
---|
1223 | if (dwClsContext & CLSCTX_LOCAL_SERVER) {
|
---|
1224 | DWORD tid;
|
---|
1225 |
|
---|
1226 | STUBMGR_Start();
|
---|
1227 | newClass->hThread=CreateThread(NULL,0,_LocalServerThread,newClass,0,&tid);
|
---|
1228 | }
|
---|
1229 | return S_OK;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | /***********************************************************************
|
---|
1233 | * CoRevokeClassObject [OLE32.40]
|
---|
1234 | *
|
---|
1235 | * This method will remove a class object from the class registry
|
---|
1236 | *
|
---|
1237 | * See the Windows documentation for more details.
|
---|
1238 | */
|
---|
1239 | HRESULT WINAPI CoRevokeClassObject(
|
---|
1240 | DWORD dwRegister)
|
---|
1241 | {
|
---|
1242 | HRESULT hr = E_INVALIDARG;
|
---|
1243 | RegisteredClass** prevClassLink;
|
---|
1244 | RegisteredClass* curClass;
|
---|
1245 |
|
---|
1246 | TRACE("(%08lx)\n",dwRegister);
|
---|
1247 |
|
---|
1248 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1249 |
|
---|
1250 | /*
|
---|
1251 | * Iterate through the whole list and try to match the cookie.
|
---|
1252 | */
|
---|
1253 | curClass = firstRegisteredClass;
|
---|
1254 | prevClassLink = &firstRegisteredClass;
|
---|
1255 |
|
---|
1256 | while (curClass != 0)
|
---|
1257 | {
|
---|
1258 | /*
|
---|
1259 | * Check if we have a match on the cookie.
|
---|
1260 | */
|
---|
1261 | if (curClass->dwCookie == dwRegister)
|
---|
1262 | {
|
---|
1263 | /*
|
---|
1264 | * Remove the class from the chain.
|
---|
1265 | */
|
---|
1266 | *prevClassLink = curClass->nextClass;
|
---|
1267 |
|
---|
1268 | /*
|
---|
1269 | * Release the reference to the class object.
|
---|
1270 | */
|
---|
1271 | IUnknown_Release(curClass->classObject);
|
---|
1272 |
|
---|
1273 | /*
|
---|
1274 | * Free the memory used by the chain node.
|
---|
1275 | */
|
---|
1276 | HeapFree(GetProcessHeap(), 0, curClass);
|
---|
1277 |
|
---|
1278 | hr = S_OK;
|
---|
1279 | goto end;
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | /*
|
---|
1283 | * Step to the next class in the list.
|
---|
1284 | */
|
---|
1285 | prevClassLink = &(curClass->nextClass);
|
---|
1286 | curClass = curClass->nextClass;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | end:
|
---|
1290 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1291 | /*
|
---|
1292 | * If we get to here, we haven't found our class.
|
---|
1293 | */
|
---|
1294 | return hr;
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | /***********************************************************************
|
---|
1298 | * CoGetClassObject [COMPOBJ.7]
|
---|
1299 | * CoGetClassObject [OLE32.16]
|
---|
1300 | *
|
---|
1301 | * FIXME. If request allows of several options and there is a failure
|
---|
1302 | * with one (other than not being registered) do we try the
|
---|
1303 | * others or return failure? (E.g. inprocess is registered but
|
---|
1304 | * the DLL is not found but the server version works)
|
---|
1305 | */
|
---|
1306 | HRESULT WINAPI CoGetClassObject(
|
---|
1307 | REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
|
---|
1308 | REFIID iid, LPVOID *ppv
|
---|
1309 | ) {
|
---|
1310 | LPUNKNOWN regClassObject;
|
---|
1311 | HRESULT hres = E_UNEXPECTED;
|
---|
1312 | char xclsid[80];
|
---|
1313 | WCHAR ProviderName[MAX_PATH+1];
|
---|
1314 | DWORD ProviderNameLen = sizeof(ProviderName);
|
---|
1315 | HINSTANCE hLibrary;
|
---|
1316 | #ifdef __WIN32OS2__
|
---|
1317 | typedef HRESULT (* CALLBACK DllGetClassObjectFunc)(REFCLSID clsid,
|
---|
1318 | REFIID iid, LPVOID *ppv);
|
---|
1319 | #else
|
---|
1320 | typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid,
|
---|
1321 | REFIID iid, LPVOID *ppv);
|
---|
1322 | #endif
|
---|
1323 | DllGetClassObjectFunc DllGetClassObject;
|
---|
1324 |
|
---|
1325 | WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
|
---|
1326 |
|
---|
1327 | TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
|
---|
1328 | debugstr_guid(rclsid),
|
---|
1329 | debugstr_guid(iid)
|
---|
1330 | );
|
---|
1331 |
|
---|
1332 | if (pServerInfo) {
|
---|
1333 | FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
|
---|
1334 | FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /*
|
---|
1338 | * First, try and see if we can't match the class ID with one of the
|
---|
1339 | * registered classes.
|
---|
1340 | */
|
---|
1341 | if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
|
---|
1342 | {
|
---|
1343 | /*
|
---|
1344 | * Get the required interface from the retrieved pointer.
|
---|
1345 | */
|
---|
1346 | hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
|
---|
1347 |
|
---|
1348 | /*
|
---|
1349 | * Since QI got another reference on the pointer, we want to release the
|
---|
1350 | * one we already have. If QI was unsuccessful, this will release the object. This
|
---|
1351 | * is good since we are not returning it in the "out" parameter.
|
---|
1352 | */
|
---|
1353 | IUnknown_Release(regClassObject);
|
---|
1354 |
|
---|
1355 | return hres;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
|
---|
1359 | HKEY key;
|
---|
1360 | char buf[200];
|
---|
1361 |
|
---|
1362 | memset(ProviderName,0,sizeof(ProviderName));
|
---|
1363 | sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
|
---|
1364 | if (((hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key)) != ERROR_SUCCESS) ||
|
---|
1365 | ((hres = RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)ProviderName,&ProviderNameLen)),
|
---|
1366 | RegCloseKey (key),
|
---|
1367 | hres != ERROR_SUCCESS))
|
---|
1368 | {
|
---|
1369 | hres = REGDB_E_CLASSNOTREG;
|
---|
1370 | }
|
---|
1371 | /* Don't ask me. MSDN says that CoGetClassObject does NOT call CoLoadLibrary */
|
---|
1372 | else if ((hLibrary = CoLoadLibrary(ProviderName, TRUE)) == 0)
|
---|
1373 | {
|
---|
1374 | FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(ProviderName));
|
---|
1375 | hres = E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
|
---|
1376 | }
|
---|
1377 | else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject")))
|
---|
1378 | {
|
---|
1379 | /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
|
---|
1380 | FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(ProviderName));
|
---|
1381 | hres = E_ACCESSDENIED;
|
---|
1382 | }
|
---|
1383 | else
|
---|
1384 | {
|
---|
1385 | /* Ask the DLL for its class object. (there was a note here about
|
---|
1386 | * class factories but this is good.
|
---|
1387 | */
|
---|
1388 | return DllGetClassObject(rclsid, iid, ppv);
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 |
|
---|
1393 | /* Next try out of process */
|
---|
1394 | if (CLSCTX_LOCAL_SERVER & dwClsContext)
|
---|
1395 | {
|
---|
1396 | return create_marshalled_proxy(rclsid,iid,ppv);
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /* Finally try remote */
|
---|
1400 | if (CLSCTX_REMOTE_SERVER & dwClsContext)
|
---|
1401 | {
|
---|
1402 | FIXME ("CLSCTX_REMOTE_SERVER not supported\n");
|
---|
1403 | hres = E_NOINTERFACE;
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | return hres;
|
---|
1407 | }
|
---|
1408 | /***********************************************************************
|
---|
1409 | * CoResumeClassObjects (OLE32.173)
|
---|
1410 | *
|
---|
1411 | * Resumes classobjects registered with REGCLS suspended
|
---|
1412 | */
|
---|
1413 | HRESULT WINAPI CoResumeClassObjects(void)
|
---|
1414 | {
|
---|
1415 | FIXME("\n");
|
---|
1416 | return S_OK;
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | /***********************************************************************
|
---|
1420 | * GetClassFile (OLE32.67)
|
---|
1421 | *
|
---|
1422 | * This function supplies the CLSID associated with the given filename.
|
---|
1423 | */
|
---|
1424 | HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
|
---|
1425 | {
|
---|
1426 | IStorage *pstg=0;
|
---|
1427 | HRESULT res;
|
---|
1428 | int nbElm=0,length=0,i=0;
|
---|
1429 | LONG sizeProgId=20;
|
---|
1430 | LPOLESTR *pathDec=0,absFile=0,progId=0;
|
---|
1431 | WCHAR extention[100]={0};
|
---|
1432 |
|
---|
1433 | TRACE("()\n");
|
---|
1434 |
|
---|
1435 | /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
|
---|
1436 | if((StgIsStorageFile(filePathName))==S_OK){
|
---|
1437 |
|
---|
1438 | res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
|
---|
1439 |
|
---|
1440 | if (SUCCEEDED(res))
|
---|
1441 | res=ReadClassStg(pstg,pclsid);
|
---|
1442 |
|
---|
1443 | IStorage_Release(pstg);
|
---|
1444 |
|
---|
1445 | return res;
|
---|
1446 | }
|
---|
1447 | /* if the file is not a storage object then attemps to match various bits in the file against a
|
---|
1448 | pattern in the registry. this case is not frequently used ! so I present only the psodocode for
|
---|
1449 | this case
|
---|
1450 |
|
---|
1451 | for(i=0;i<nFileTypes;i++)
|
---|
1452 |
|
---|
1453 | for(i=0;j<nPatternsForType;j++){
|
---|
1454 |
|
---|
1455 | PATTERN pat;
|
---|
1456 | HANDLE hFile;
|
---|
1457 |
|
---|
1458 | pat=ReadPatternFromRegistry(i,j);
|
---|
1459 | hFile=CreateFileW(filePathName,,,,,,hFile);
|
---|
1460 | SetFilePosition(hFile,pat.offset);
|
---|
1461 | ReadFile(hFile,buf,pat.size,NULL,NULL);
|
---|
1462 | if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
|
---|
1463 |
|
---|
1464 | *pclsid=ReadCLSIDFromRegistry(i);
|
---|
1465 | return S_OK;
|
---|
1466 | }
|
---|
1467 | }
|
---|
1468 | */
|
---|
1469 |
|
---|
1470 | /* if the obove strategies fail then search for the extension key in the registry */
|
---|
1471 |
|
---|
1472 | /* get the last element (absolute file) in the path name */
|
---|
1473 | nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
|
---|
1474 | absFile=pathDec[nbElm-1];
|
---|
1475 |
|
---|
1476 | /* failed if the path represente a directory and not an absolute file name*/
|
---|
1477 | if (lstrcmpW(absFile,(LPOLESTR)"\\"))
|
---|
1478 | return MK_E_INVALIDEXTENSION;
|
---|
1479 |
|
---|
1480 | /* get the extension of the file */
|
---|
1481 | length=lstrlenW(absFile);
|
---|
1482 | for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
|
---|
1483 |
|
---|
1484 | /* get the progId associated to the extension */
|
---|
1485 | progId=CoTaskMemAlloc(sizeProgId);
|
---|
1486 |
|
---|
1487 | res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
|
---|
1488 |
|
---|
1489 | if (res==ERROR_MORE_DATA){
|
---|
1490 |
|
---|
1491 | progId = CoTaskMemRealloc(progId,sizeProgId);
|
---|
1492 | res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
|
---|
1493 | }
|
---|
1494 | if (res==ERROR_SUCCESS)
|
---|
1495 | /* return the clsid associated to the progId */
|
---|
1496 | res= CLSIDFromProgID(progId,pclsid);
|
---|
1497 |
|
---|
1498 | for(i=0; pathDec[i]!=NULL;i++)
|
---|
1499 | CoTaskMemFree(pathDec[i]);
|
---|
1500 | CoTaskMemFree(pathDec);
|
---|
1501 |
|
---|
1502 | CoTaskMemFree(progId);
|
---|
1503 |
|
---|
1504 | if (res==ERROR_SUCCESS)
|
---|
1505 | return res;
|
---|
1506 |
|
---|
1507 | return MK_E_INVALIDEXTENSION;
|
---|
1508 | }
|
---|
1509 | /******************************************************************************
|
---|
1510 | * CoRegisterMessageFilter [COMPOBJ.27]
|
---|
1511 | */
|
---|
1512 | HRESULT WINAPI CoRegisterMessageFilter16(
|
---|
1513 | LPMESSAGEFILTER lpMessageFilter,
|
---|
1514 | LPMESSAGEFILTER *lplpMessageFilter
|
---|
1515 | ) {
|
---|
1516 | FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
|
---|
1517 | return 0;
|
---|
1518 | }
|
---|
1519 |
|
---|
1520 | /***********************************************************************
|
---|
1521 | * CoCreateInstance [COMPOBJ.13]
|
---|
1522 | * CoCreateInstance [OLE32.7]
|
---|
1523 | */
|
---|
1524 | HRESULT WINAPI CoCreateInstance(
|
---|
1525 | REFCLSID rclsid,
|
---|
1526 | LPUNKNOWN pUnkOuter,
|
---|
1527 | DWORD dwClsContext,
|
---|
1528 | REFIID iid,
|
---|
1529 | LPVOID *ppv)
|
---|
1530 | {
|
---|
1531 | HRESULT hres;
|
---|
1532 | LPCLASSFACTORY lpclf = 0;
|
---|
1533 |
|
---|
1534 | /*
|
---|
1535 | * Sanity check
|
---|
1536 | */
|
---|
1537 | if (ppv==0)
|
---|
1538 | return E_POINTER;
|
---|
1539 |
|
---|
1540 | /*
|
---|
1541 | * Initialize the "out" parameter
|
---|
1542 | */
|
---|
1543 | *ppv = 0;
|
---|
1544 |
|
---|
1545 | /*
|
---|
1546 | * Get a class factory to construct the object we want.
|
---|
1547 | */
|
---|
1548 | hres = CoGetClassObject(rclsid,
|
---|
1549 | dwClsContext,
|
---|
1550 | NULL,
|
---|
1551 | &IID_IClassFactory,
|
---|
1552 | (LPVOID)&lpclf);
|
---|
1553 |
|
---|
1554 | if (FAILED(hres)) {
|
---|
1555 | FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
|
---|
1556 | debugstr_guid(rclsid),hres);
|
---|
1557 | return hres;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | /*
|
---|
1561 | * Create the object and don't forget to release the factory
|
---|
1562 | */
|
---|
1563 | hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
|
---|
1564 | IClassFactory_Release(lpclf);
|
---|
1565 | if(FAILED(hres))
|
---|
1566 | FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
|
---|
1567 | debugstr_guid(iid), debugstr_guid(rclsid),hres);
|
---|
1568 |
|
---|
1569 | return hres;
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | /***********************************************************************
|
---|
1573 | * CoCreateInstanceEx [OLE32.165]
|
---|
1574 | */
|
---|
1575 | HRESULT WINAPI CoCreateInstanceEx(
|
---|
1576 | REFCLSID rclsid,
|
---|
1577 | LPUNKNOWN pUnkOuter,
|
---|
1578 | DWORD dwClsContext,
|
---|
1579 | COSERVERINFO* pServerInfo,
|
---|
1580 | ULONG cmq,
|
---|
1581 | MULTI_QI* pResults)
|
---|
1582 | {
|
---|
1583 | IUnknown* pUnk = NULL;
|
---|
1584 | HRESULT hr;
|
---|
1585 | ULONG index;
|
---|
1586 | int successCount = 0;
|
---|
1587 |
|
---|
1588 | /*
|
---|
1589 | * Sanity check
|
---|
1590 | */
|
---|
1591 | if ( (cmq==0) || (pResults==NULL))
|
---|
1592 | return E_INVALIDARG;
|
---|
1593 |
|
---|
1594 | if (pServerInfo!=NULL)
|
---|
1595 | FIXME("() non-NULL pServerInfo not supported!\n");
|
---|
1596 |
|
---|
1597 | /*
|
---|
1598 | * Initialize all the "out" parameters.
|
---|
1599 | */
|
---|
1600 | for (index = 0; index < cmq; index++)
|
---|
1601 | {
|
---|
1602 | pResults[index].pItf = NULL;
|
---|
1603 | pResults[index].hr = E_NOINTERFACE;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | /*
|
---|
1607 | * Get the object and get its IUnknown pointer.
|
---|
1608 | */
|
---|
1609 | hr = CoCreateInstance(rclsid,
|
---|
1610 | pUnkOuter,
|
---|
1611 | dwClsContext,
|
---|
1612 | &IID_IUnknown,
|
---|
1613 | (VOID**)&pUnk);
|
---|
1614 |
|
---|
1615 | if (hr)
|
---|
1616 | return hr;
|
---|
1617 |
|
---|
1618 | /*
|
---|
1619 | * Then, query for all the interfaces requested.
|
---|
1620 | */
|
---|
1621 | for (index = 0; index < cmq; index++)
|
---|
1622 | {
|
---|
1623 | pResults[index].hr = IUnknown_QueryInterface(pUnk,
|
---|
1624 | pResults[index].pIID,
|
---|
1625 | (VOID**)&(pResults[index].pItf));
|
---|
1626 |
|
---|
1627 | if (pResults[index].hr == S_OK)
|
---|
1628 | successCount++;
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | /*
|
---|
1632 | * Release our temporary unknown pointer.
|
---|
1633 | */
|
---|
1634 | IUnknown_Release(pUnk);
|
---|
1635 |
|
---|
1636 | if (successCount == 0)
|
---|
1637 | return E_NOINTERFACE;
|
---|
1638 |
|
---|
1639 | if (successCount!=cmq)
|
---|
1640 | return CO_S_NOTALLINTERFACES;
|
---|
1641 |
|
---|
1642 | return S_OK;
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | /***********************************************************************
|
---|
1646 | * CoFreeLibrary [OLE32.13]
|
---|
1647 | */
|
---|
1648 | void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
|
---|
1649 | {
|
---|
1650 | OpenDll *ptr, *prev;
|
---|
1651 | OpenDll *tmp;
|
---|
1652 |
|
---|
1653 | EnterCriticalSection( &csOpenDllList );
|
---|
1654 |
|
---|
1655 | /* lookup library in linked list */
|
---|
1656 | prev = NULL;
|
---|
1657 | for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
|
---|
1658 | if (ptr->hLibrary == hLibrary) {
|
---|
1659 | break;
|
---|
1660 | }
|
---|
1661 | prev = ptr;
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | if (ptr == NULL) {
|
---|
1665 | /* shouldn't happen if user passed in a valid hLibrary */
|
---|
1666 | goto end;
|
---|
1667 | }
|
---|
1668 | /* assert: ptr points to the library entry to free */
|
---|
1669 |
|
---|
1670 | /* free library and remove node from list */
|
---|
1671 | FreeLibrary(hLibrary);
|
---|
1672 | if (ptr == openDllList) {
|
---|
1673 | tmp = openDllList->next;
|
---|
1674 | HeapFree(GetProcessHeap(), 0, openDllList);
|
---|
1675 | openDllList = tmp;
|
---|
1676 | } else {
|
---|
1677 | tmp = ptr->next;
|
---|
1678 | HeapFree(GetProcessHeap(), 0, ptr);
|
---|
1679 | prev->next = tmp;
|
---|
1680 | }
|
---|
1681 | end:
|
---|
1682 | LeaveCriticalSection( &csOpenDllList );
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 |
|
---|
1686 | /***********************************************************************
|
---|
1687 | * CoFreeAllLibraries [OLE32.12]
|
---|
1688 | */
|
---|
1689 | void WINAPI CoFreeAllLibraries(void)
|
---|
1690 | {
|
---|
1691 | OpenDll *ptr, *tmp;
|
---|
1692 |
|
---|
1693 | EnterCriticalSection( &csOpenDllList );
|
---|
1694 |
|
---|
1695 | for (ptr = openDllList; ptr != NULL; ) {
|
---|
1696 | tmp=ptr->next;
|
---|
1697 | CoFreeLibrary(ptr->hLibrary);
|
---|
1698 | ptr = tmp;
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | LeaveCriticalSection( &csOpenDllList );
|
---|
1702 | }
|
---|
1703 |
|
---|
1704 |
|
---|
1705 |
|
---|
1706 | /***********************************************************************
|
---|
1707 | * CoFreeUnusedLibraries [COMPOBJ.17]
|
---|
1708 | * CoFreeUnusedLibraries [OLE32.14]
|
---|
1709 | */
|
---|
1710 | void WINAPI CoFreeUnusedLibraries(void)
|
---|
1711 | {
|
---|
1712 | OpenDll *ptr, *tmp;
|
---|
1713 | typedef HRESULT(*DllCanUnloadNowFunc)(void);
|
---|
1714 | DllCanUnloadNowFunc DllCanUnloadNow;
|
---|
1715 |
|
---|
1716 | EnterCriticalSection( &csOpenDllList );
|
---|
1717 |
|
---|
1718 | for (ptr = openDllList; ptr != NULL; ) {
|
---|
1719 | DllCanUnloadNow = (DllCanUnloadNowFunc)
|
---|
1720 | GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
|
---|
1721 |
|
---|
1722 | if ( (DllCanUnloadNow != NULL) &&
|
---|
1723 | (DllCanUnloadNow() == S_OK) ) {
|
---|
1724 | tmp=ptr->next;
|
---|
1725 | CoFreeLibrary(ptr->hLibrary);
|
---|
1726 | ptr = tmp;
|
---|
1727 | } else {
|
---|
1728 | ptr=ptr->next;
|
---|
1729 | }
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | LeaveCriticalSection( &csOpenDllList );
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | /***********************************************************************
|
---|
1736 | * CoFileTimeNow [COMPOBJ.82]
|
---|
1737 | * CoFileTimeNow [OLE32.10]
|
---|
1738 | *
|
---|
1739 | * RETURNS
|
---|
1740 | * the current system time in lpFileTime
|
---|
1741 | */
|
---|
1742 | HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
|
---|
1743 | {
|
---|
1744 | GetSystemTimeAsFileTime( lpFileTime );
|
---|
1745 | return S_OK;
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 | /***********************************************************************
|
---|
1749 | * CoTaskMemAlloc (OLE32.43)
|
---|
1750 | * RETURNS
|
---|
1751 | * pointer to newly allocated block
|
---|
1752 | */
|
---|
1753 | LPVOID WINAPI CoTaskMemAlloc(
|
---|
1754 | ULONG size /* [in] size of memoryblock to be allocated */
|
---|
1755 | ) {
|
---|
1756 | LPMALLOC lpmalloc;
|
---|
1757 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
---|
1758 |
|
---|
1759 | if (FAILED(ret))
|
---|
1760 | return NULL;
|
---|
1761 |
|
---|
1762 | return IMalloc_Alloc(lpmalloc,size);
|
---|
1763 | }
|
---|
1764 | /***********************************************************************
|
---|
1765 | * CoTaskMemFree (OLE32.44)
|
---|
1766 | */
|
---|
1767 | VOID WINAPI CoTaskMemFree(
|
---|
1768 | LPVOID ptr /* [in] pointer to be freed */
|
---|
1769 | ) {
|
---|
1770 | LPMALLOC lpmalloc;
|
---|
1771 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
---|
1772 |
|
---|
1773 | if (FAILED(ret))
|
---|
1774 | return;
|
---|
1775 |
|
---|
1776 | IMalloc_Free(lpmalloc, ptr);
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | /***********************************************************************
|
---|
1780 | * CoTaskMemRealloc (OLE32.45)
|
---|
1781 | * RETURNS
|
---|
1782 | * pointer to newly allocated block
|
---|
1783 | */
|
---|
1784 | LPVOID WINAPI CoTaskMemRealloc(
|
---|
1785 | LPVOID pvOld,
|
---|
1786 | ULONG size) /* [in] size of memoryblock to be allocated */
|
---|
1787 | {
|
---|
1788 | LPMALLOC lpmalloc;
|
---|
1789 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
---|
1790 |
|
---|
1791 | if (FAILED(ret))
|
---|
1792 | return NULL;
|
---|
1793 |
|
---|
1794 | return IMalloc_Realloc(lpmalloc, pvOld, size);
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | /***********************************************************************
|
---|
1798 | * CoLoadLibrary (OLE32.30)
|
---|
1799 | */
|
---|
1800 | HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
|
---|
1801 | {
|
---|
1802 | HINSTANCE hLibrary;
|
---|
1803 | OpenDll *ptr;
|
---|
1804 | OpenDll *tmp;
|
---|
1805 |
|
---|
1806 | TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
|
---|
1807 |
|
---|
1808 | hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
|
---|
1809 |
|
---|
1810 | if (!bAutoFree)
|
---|
1811 | return hLibrary;
|
---|
1812 |
|
---|
1813 | EnterCriticalSection( &csOpenDllList );
|
---|
1814 |
|
---|
1815 | if (openDllList == NULL) {
|
---|
1816 | /* empty list -- add first node */
|
---|
1817 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
---|
1818 | openDllList->hLibrary=hLibrary;
|
---|
1819 | openDllList->next = NULL;
|
---|
1820 | } else {
|
---|
1821 | /* search for this dll */
|
---|
1822 | int found = FALSE;
|
---|
1823 | for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
|
---|
1824 | if (ptr->hLibrary == hLibrary) {
|
---|
1825 | found = TRUE;
|
---|
1826 | break;
|
---|
1827 | }
|
---|
1828 | }
|
---|
1829 | if (!found) {
|
---|
1830 | /* dll not found, add it */
|
---|
1831 | tmp = openDllList;
|
---|
1832 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
---|
1833 | openDllList->hLibrary = hLibrary;
|
---|
1834 | openDllList->next = tmp;
|
---|
1835 | }
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | LeaveCriticalSection( &csOpenDllList );
|
---|
1839 |
|
---|
1840 | return hLibrary;
|
---|
1841 | }
|
---|
1842 |
|
---|
1843 | /***********************************************************************
|
---|
1844 | * CoInitializeWOW (OLE32.27)
|
---|
1845 | */
|
---|
1846 | HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
|
---|
1847 | FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
|
---|
1848 | return 0;
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | /******************************************************************************
|
---|
1852 | * CoLockObjectExternal [COMPOBJ.63]
|
---|
1853 | */
|
---|
1854 | HRESULT WINAPI CoLockObjectExternal16(
|
---|
1855 | LPUNKNOWN pUnk, /* [in] object to be locked */
|
---|
1856 | BOOL16 fLock, /* [in] do lock */
|
---|
1857 | BOOL16 fLastUnlockReleases /* [in] ? */
|
---|
1858 | ) {
|
---|
1859 | FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
|
---|
1860 | return S_OK;
|
---|
1861 | }
|
---|
1862 |
|
---|
1863 | /******************************************************************************
|
---|
1864 | * CoLockObjectExternal [OLE32.31]
|
---|
1865 | */
|
---|
1866 | HRESULT WINAPI CoLockObjectExternal(
|
---|
1867 | LPUNKNOWN pUnk, /* [in] object to be locked */
|
---|
1868 | BOOL fLock, /* [in] do lock */
|
---|
1869 | BOOL fLastUnlockReleases) /* [in] unlock all */
|
---|
1870 | {
|
---|
1871 |
|
---|
1872 | if (fLock)
|
---|
1873 | {
|
---|
1874 | /*
|
---|
1875 | * Increment the external lock coutner, COM_ExternalLockAddRef also
|
---|
1876 | * increment the object's internal lock counter.
|
---|
1877 | */
|
---|
1878 | COM_ExternalLockAddRef( pUnk);
|
---|
1879 | }
|
---|
1880 | else
|
---|
1881 | {
|
---|
1882 | /*
|
---|
1883 | * Decrement the external lock coutner, COM_ExternalLockRelease also
|
---|
1884 | * decrement the object's internal lock counter.
|
---|
1885 | */
|
---|
1886 | COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | return S_OK;
|
---|
1890 | }
|
---|
1891 |
|
---|
1892 | /***********************************************************************
|
---|
1893 | * CoGetState [COMPOBJ.115]
|
---|
1894 | */
|
---|
1895 | HRESULT WINAPI CoGetState16(LPDWORD state)
|
---|
1896 | {
|
---|
1897 | FIXME("(%p),stub!\n", state);
|
---|
1898 | *state = 0;
|
---|
1899 | return S_OK;
|
---|
1900 | }
|
---|
1901 | /***********************************************************************
|
---|
1902 | * CoSetState [OLE32.42]
|
---|
1903 | */
|
---|
1904 | HRESULT WINAPI CoSetState(LPDWORD state)
|
---|
1905 | {
|
---|
1906 | FIXME("(%p),stub!\n", state);
|
---|
1907 | if (state) *state = 0;
|
---|
1908 | return S_OK;
|
---|
1909 | }
|
---|
1910 | /***********************************************************************
|
---|
1911 | * CoCreateFreeThreadedMarshaler [OLE32.5]
|
---|
1912 | */
|
---|
1913 | HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
|
---|
1914 | {
|
---|
1915 | FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
|
---|
1916 |
|
---|
1917 | return S_OK;
|
---|
1918 | }
|
---|
1919 |
|
---|
1920 | /***
|
---|
1921 | * COM_RevokeAllClasses
|
---|
1922 | *
|
---|
1923 | * This method is called when the COM libraries are uninitialized to
|
---|
1924 | * release all the references to the class objects registered with
|
---|
1925 | * the library
|
---|
1926 | */
|
---|
1927 | static void COM_RevokeAllClasses()
|
---|
1928 | {
|
---|
1929 | EnterCriticalSection( &csRegisteredClassList );
|
---|
1930 |
|
---|
1931 | while (firstRegisteredClass!=0)
|
---|
1932 | {
|
---|
1933 | CoRevokeClassObject(firstRegisteredClass->dwCookie);
|
---|
1934 | }
|
---|
1935 |
|
---|
1936 | LeaveCriticalSection( &csRegisteredClassList );
|
---|
1937 | }
|
---|
1938 |
|
---|
1939 | /****************************************************************************
|
---|
1940 | * COM External Lock methods implementation
|
---|
1941 | */
|
---|
1942 |
|
---|
1943 | /****************************************************************************
|
---|
1944 | * Public - Method that increments the count for a IUnknown* in the linked
|
---|
1945 | * list. The item is inserted if not already in the list.
|
---|
1946 | */
|
---|
1947 | static void COM_ExternalLockAddRef(
|
---|
1948 | IUnknown *pUnk)
|
---|
1949 | {
|
---|
1950 | COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
|
---|
1951 |
|
---|
1952 | /*
|
---|
1953 | * Add an external lock to the object. If it was already externally
|
---|
1954 | * locked, just increase the reference count. If it was not.
|
---|
1955 | * add the item to the list.
|
---|
1956 | */
|
---|
1957 | if ( externalLock == EL_NOT_FOUND )
|
---|
1958 | COM_ExternalLockInsert(pUnk);
|
---|
1959 | else
|
---|
1960 | externalLock->uRefCount++;
|
---|
1961 |
|
---|
1962 | /*
|
---|
1963 | * Add an internal lock to the object
|
---|
1964 | */
|
---|
1965 | IUnknown_AddRef(pUnk);
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | /****************************************************************************
|
---|
1969 | * Public - Method that decrements the count for a IUnknown* in the linked
|
---|
1970 | * list. The item is removed from the list if its count end up at zero or if
|
---|
1971 | * bRelAll is TRUE.
|
---|
1972 | */
|
---|
1973 | static void COM_ExternalLockRelease(
|
---|
1974 | IUnknown *pUnk,
|
---|
1975 | BOOL bRelAll)
|
---|
1976 | {
|
---|
1977 | COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
|
---|
1978 |
|
---|
1979 | if ( externalLock != EL_NOT_FOUND )
|
---|
1980 | {
|
---|
1981 | do
|
---|
1982 | {
|
---|
1983 | externalLock->uRefCount--; /* release external locks */
|
---|
1984 | IUnknown_Release(pUnk); /* release local locks as well */
|
---|
1985 |
|
---|
1986 | if ( bRelAll == FALSE )
|
---|
1987 | break; /* perform single release */
|
---|
1988 |
|
---|
1989 | } while ( externalLock->uRefCount > 0 );
|
---|
1990 |
|
---|
1991 | if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
|
---|
1992 | COM_ExternalLockDelete(externalLock);
|
---|
1993 | }
|
---|
1994 | }
|
---|
1995 | /****************************************************************************
|
---|
1996 | * Public - Method that frees the content of the list.
|
---|
1997 | */
|
---|
1998 | static void COM_ExternalLockFreeList()
|
---|
1999 | {
|
---|
2000 | COM_ExternalLock *head;
|
---|
2001 |
|
---|
2002 | head = elList.head; /* grab it by the head */
|
---|
2003 | while ( head != EL_END_OF_LIST )
|
---|
2004 | {
|
---|
2005 | COM_ExternalLockDelete(head); /* get rid of the head stuff */
|
---|
2006 |
|
---|
2007 | head = elList.head; /* get the new head... */
|
---|
2008 | }
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /****************************************************************************
|
---|
2012 | * Public - Method that dump the content of the list.
|
---|
2013 | */
|
---|
2014 | void COM_ExternalLockDump()
|
---|
2015 | {
|
---|
2016 | COM_ExternalLock *current = elList.head;
|
---|
2017 |
|
---|
2018 | DPRINTF("\nExternal lock list contains:\n");
|
---|
2019 |
|
---|
2020 | while ( current != EL_END_OF_LIST )
|
---|
2021 | {
|
---|
2022 | DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
|
---|
2023 |
|
---|
2024 | /* Skip to the next item */
|
---|
2025 | current = current->next;
|
---|
2026 | }
|
---|
2027 |
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | /****************************************************************************
|
---|
2031 | * Internal - Find a IUnknown* in the linked list
|
---|
2032 | */
|
---|
2033 | static COM_ExternalLock* COM_ExternalLockFind(
|
---|
2034 | IUnknown *pUnk)
|
---|
2035 | {
|
---|
2036 | return COM_ExternalLockLocate(elList.head, pUnk);
|
---|
2037 | }
|
---|
2038 |
|
---|
2039 | /****************************************************************************
|
---|
2040 | * Internal - Recursivity agent for IUnknownExternalLockList_Find
|
---|
2041 | */
|
---|
2042 | static COM_ExternalLock* COM_ExternalLockLocate(
|
---|
2043 | COM_ExternalLock *element,
|
---|
2044 | IUnknown *pUnk)
|
---|
2045 | {
|
---|
2046 | if ( element == EL_END_OF_LIST )
|
---|
2047 | return EL_NOT_FOUND;
|
---|
2048 |
|
---|
2049 | else if ( element->pUnk == pUnk ) /* We found it */
|
---|
2050 | return element;
|
---|
2051 |
|
---|
2052 | else /* Not the right guy, keep on looking */
|
---|
2053 | return COM_ExternalLockLocate( element->next, pUnk);
|
---|
2054 | }
|
---|
2055 |
|
---|
2056 | /****************************************************************************
|
---|
2057 | * Internal - Insert a new IUnknown* to the linked list
|
---|
2058 | */
|
---|
2059 | static BOOL COM_ExternalLockInsert(
|
---|
2060 | IUnknown *pUnk)
|
---|
2061 | {
|
---|
2062 | COM_ExternalLock *newLock = NULL;
|
---|
2063 | COM_ExternalLock *previousHead = NULL;
|
---|
2064 |
|
---|
2065 | /*
|
---|
2066 | * Allocate space for the new storage object
|
---|
2067 | */
|
---|
2068 | newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
|
---|
2069 |
|
---|
2070 | if (newLock!=NULL)
|
---|
2071 | {
|
---|
2072 | if ( elList.head == EL_END_OF_LIST )
|
---|
2073 | {
|
---|
2074 | elList.head = newLock; /* The list is empty */
|
---|
2075 | }
|
---|
2076 | else
|
---|
2077 | {
|
---|
2078 | /*
|
---|
2079 | * insert does it at the head
|
---|
2080 | */
|
---|
2081 | previousHead = elList.head;
|
---|
2082 | elList.head = newLock;
|
---|
2083 | }
|
---|
2084 |
|
---|
2085 | /*
|
---|
2086 | * Set new list item data member
|
---|
2087 | */
|
---|
2088 | newLock->pUnk = pUnk;
|
---|
2089 | newLock->uRefCount = 1;
|
---|
2090 | newLock->next = previousHead;
|
---|
2091 |
|
---|
2092 | return TRUE;
|
---|
2093 | }
|
---|
2094 | else
|
---|
2095 | return FALSE;
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | /****************************************************************************
|
---|
2099 | * Internal - Method that removes an item from the linked list.
|
---|
2100 | */
|
---|
2101 | static void COM_ExternalLockDelete(
|
---|
2102 | COM_ExternalLock *itemList)
|
---|
2103 | {
|
---|
2104 | COM_ExternalLock *current = elList.head;
|
---|
2105 |
|
---|
2106 | if ( current == itemList )
|
---|
2107 | {
|
---|
2108 | /*
|
---|
2109 | * this section handles the deletion of the first node
|
---|
2110 | */
|
---|
2111 | elList.head = itemList->next;
|
---|
2112 | HeapFree( GetProcessHeap(), 0, itemList);
|
---|
2113 | }
|
---|
2114 | else
|
---|
2115 | {
|
---|
2116 | do
|
---|
2117 | {
|
---|
2118 | if ( current->next == itemList ) /* We found the item to free */
|
---|
2119 | {
|
---|
2120 | current->next = itemList->next; /* readjust the list pointers */
|
---|
2121 |
|
---|
2122 | HeapFree( GetProcessHeap(), 0, itemList);
|
---|
2123 | break;
|
---|
2124 | }
|
---|
2125 |
|
---|
2126 | /* Skip to the next item */
|
---|
2127 | current = current->next;
|
---|
2128 |
|
---|
2129 | } while ( current != EL_END_OF_LIST );
|
---|
2130 | }
|
---|
2131 | }
|
---|
2132 |
|
---|
2133 | /***********************************************************************
|
---|
2134 | * DllEntryPoint [COMPOBJ.116]
|
---|
2135 | *
|
---|
2136 | * Initialization code for the COMPOBJ DLL
|
---|
2137 | *
|
---|
2138 | * RETURNS:
|
---|
2139 | */
|
---|
2140 | BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
|
---|
2141 | {
|
---|
2142 | TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
|
---|
2143 | res1, res2);
|
---|
2144 | switch(Reason)
|
---|
2145 | {
|
---|
2146 | case DLL_PROCESS_ATTACH:
|
---|
2147 | if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
|
---|
2148 | break;
|
---|
2149 |
|
---|
2150 | case DLL_PROCESS_DETACH:
|
---|
2151 | if(!--COMPOBJ_Attach)
|
---|
2152 | COMPOBJ_hInstance = 0;
|
---|
2153 | break;
|
---|
2154 | }
|
---|
2155 | return TRUE;
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | /******************************************************************************
|
---|
2159 | * OleGetAutoConvert [OLE32.104]
|
---|
2160 | */
|
---|
2161 | HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
|
---|
2162 | {
|
---|
2163 | HKEY hkey = 0;
|
---|
2164 | char buf[200];
|
---|
2165 | WCHAR wbuf[200];
|
---|
2166 | DWORD len;
|
---|
2167 | HRESULT res = S_OK;
|
---|
2168 |
|
---|
2169 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
2170 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
2171 | {
|
---|
2172 | res = REGDB_E_CLASSNOTREG;
|
---|
2173 | goto done;
|
---|
2174 | }
|
---|
2175 | len = 200;
|
---|
2176 | /* we can just query for the default value of AutoConvertTo key like that,
|
---|
2177 | without opening the AutoConvertTo key and querying for NULL (default) */
|
---|
2178 | if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
|
---|
2179 | {
|
---|
2180 | res = REGDB_E_KEYMISSING;
|
---|
2181 | goto done;
|
---|
2182 | }
|
---|
2183 | MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
|
---|
2184 | CLSIDFromString(wbuf,pClsidNew);
|
---|
2185 | done:
|
---|
2186 | if (hkey) RegCloseKey(hkey);
|
---|
2187 |
|
---|
2188 | return res;
|
---|
2189 | }
|
---|
2190 |
|
---|
2191 | /******************************************************************************
|
---|
2192 | * OleSetAutoConvert [OLE32.126]
|
---|
2193 | */
|
---|
2194 | HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
|
---|
2195 | {
|
---|
2196 | HKEY hkey = 0;
|
---|
2197 | char buf[200], szClsidNew[200];
|
---|
2198 | HRESULT res = S_OK;
|
---|
2199 |
|
---|
2200 | TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
---|
2201 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
2202 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
---|
2203 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
2204 | {
|
---|
2205 | res = REGDB_E_CLASSNOTREG;
|
---|
2206 | goto done;
|
---|
2207 | }
|
---|
2208 | if (RegSetValueA(hkey, "AutoConvertTo", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
---|
2209 | {
|
---|
2210 | res = REGDB_E_WRITEREGDB;
|
---|
2211 | goto done;
|
---|
2212 | }
|
---|
2213 |
|
---|
2214 | done:
|
---|
2215 | if (hkey) RegCloseKey(hkey);
|
---|
2216 | return res;
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | /******************************************************************************
|
---|
2220 | * CoTreatAsClass [OLE32.46]
|
---|
2221 | */
|
---|
2222 | HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
|
---|
2223 | {
|
---|
2224 | HKEY hkey = 0;
|
---|
2225 | char buf[200], szClsidNew[200];
|
---|
2226 | HRESULT res = S_OK;
|
---|
2227 |
|
---|
2228 | FIXME("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
---|
2229 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
---|
2230 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
---|
2231 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
---|
2232 | {
|
---|
2233 | res = REGDB_E_CLASSNOTREG;
|
---|
2234 | goto done;
|
---|
2235 | }
|
---|
2236 | if (RegSetValueA(hkey, "AutoTreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
---|
2237 | {
|
---|
2238 | res = REGDB_E_WRITEREGDB;
|
---|
2239 | goto done;
|
---|
2240 | }
|
---|
2241 |
|
---|
2242 | done:
|
---|
2243 | if (hkey) RegCloseKey(hkey);
|
---|
2244 | return res;
|
---|
2245 | }
|
---|
2246 |
|
---|
2247 |
|
---|
2248 | /***********************************************************************
|
---|
2249 | * IsEqualGUID [OLE32.76]
|
---|
2250 | *
|
---|
2251 | * Compares two Unique Identifiers.
|
---|
2252 | *
|
---|
2253 | * RETURNS
|
---|
2254 | * TRUE if equal
|
---|
2255 | */
|
---|
2256 | #undef IsEqualGUID
|
---|
2257 | BOOL WINAPI IsEqualGUID(
|
---|
2258 | REFGUID rguid1, /* [in] unique id 1 */
|
---|
2259 | REFGUID rguid2 /* [in] unique id 2 */
|
---|
2260 | )
|
---|
2261 | {
|
---|
2262 | return !memcmp(rguid1,rguid2,sizeof(GUID));
|
---|
2263 | }
|
---|