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 * Copyright 2004 Mike Hearn
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 1. COINIT_MULTITHREADED is 0; it is the lack of COINIT_APARTMENTTHREADED
27 * Therefore do not test against COINIT_MULTITHREADED
29 * TODO list: (items bunched together depend on each other)
31 * - Implement the service control manager (in rpcss) to keep track
32 * of registered class objects: ISCM::ServerRegisterClsid et al
33 * - Implement the OXID resolver so we don't need magic endpoint names for
34 * clients and servers to meet up
36 * - Pump the message loop during RPC calls.
37 * - Call IMessageFilter functions.
39 * - Make all ole interface marshaling use NDR to be wire compatible with
41 * - Use & interpret ORPCTHIS & ORPCTHAT.
54 #define NONAMELESSUNION
55 #define NONAMELESSSTRUCT
67 #include "wine/unicode.h"
69 #include "compobj_private.h"
71 #include "wine/debug.h"
73 WINE_DEFAULT_DEBUG_CHANNEL(ole);
75 typedef LPCSTR LPCOLESTR16;
77 HINSTANCE OLE32_hInstance = 0; /* FIXME: make static ... */
79 #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
81 /****************************************************************************
82 * This section defines variables internal to the COM module.
84 * TODO: Most of these things will have to be made thread-safe.
87 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid, DWORD dwClsContext, LPUNKNOWN* ppUnk);
88 static void COM_RevokeAllClasses(void);
90 const CLSID CLSID_StdGlobalInterfaceTable = { 0x00000323, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46} };
92 APARTMENT *MTA; /* protected by csApartment */
93 static struct list apts = LIST_INIT( apts ); /* protected by csApartment */
95 static CRITICAL_SECTION csApartment;
96 static CRITICAL_SECTION_DEBUG critsect_debug =
99 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
100 0, 0, { 0, (DWORD)(__FILE__ ": csApartment") }
102 static CRITICAL_SECTION csApartment = { &critsect_debug, -1, 0, 0, 0, 0 };
105 * This lock count counts the number of times CoInitialize is called. It is
106 * decreased every time CoUninitialize is called. When it hits 0, the COM
107 * libraries are freed
109 static LONG s_COMLockCount = 0;
112 * This linked list contains the list of registered class objects. These
113 * are mostly used to register the factories for out-of-proc servers of OLE
116 * TODO: Make this data structure aware of inter-process communication. This
117 * means that parts of this will be exported to the Wine Server.
119 typedef struct tagRegisteredClass
121 CLSID classIdentifier;
122 LPUNKNOWN classObject;
126 LPSTREAM pMarshaledData; /* FIXME: only really need to store OXID and IPID */
127 struct tagRegisteredClass* nextClass;
130 static RegisteredClass* firstRegisteredClass = NULL;
132 static CRITICAL_SECTION csRegisteredClassList;
133 static CRITICAL_SECTION_DEBUG class_cs_debug =
135 0, 0, &csRegisteredClassList,
136 { &class_cs_debug.ProcessLocksList, &class_cs_debug.ProcessLocksList },
137 0, 0, { 0, (DWORD)(__FILE__ ": csRegisteredClassList") }
139 static CRITICAL_SECTION csRegisteredClassList = { &class_cs_debug, -1, 0, 0, 0, 0 };
141 /*****************************************************************************
142 * This section contains OpenDllList definitions
144 * The OpenDllList contains only handles of dll loaded by CoGetClassObject or
145 * other functions that do LoadLibrary _without_ giving back a HMODULE.
146 * Without this list these handles would never be freed.
148 * FIXME: a DLL that says OK when asked for unloading is unloaded in the
149 * next unload-call but not before 600 sec.
152 typedef struct tagOpenDll {
154 struct tagOpenDll *next;
157 static OpenDll *openDllList = NULL; /* linked list of open dlls */
159 static CRITICAL_SECTION csOpenDllList;
160 static CRITICAL_SECTION_DEBUG dll_cs_debug =
162 0, 0, &csOpenDllList,
163 { &dll_cs_debug.ProcessLocksList, &dll_cs_debug.ProcessLocksList },
164 0, 0, { 0, (DWORD)(__FILE__ ": csOpenDllList") }
166 static CRITICAL_SECTION csOpenDllList = { &dll_cs_debug, -1, 0, 0, 0, 0 };
168 static const WCHAR wszAptWinClass[] = {'O','l','e','M','a','i','n','T','h','r','e','a','d','W','n','d','C','l','a','s','s',' ',
169 '0','x','#','#','#','#','#','#','#','#',' ',0};
170 static LRESULT CALLBACK apartment_wndproc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
172 static void COMPOBJ_DLLList_Add(HANDLE hLibrary);
173 static void COMPOBJ_DllList_FreeUnused(int Timeout);
175 static void COMPOBJ_InitProcess( void )
179 /* Dispatching to the correct thread in an apartment is done through
180 * window messages rather than RPC transports. When an interface is
181 * marshalled into another apartment in the same process, a window of the
182 * following class is created. The *caller* of CoMarshalInterface (ie the
183 * application) is responsible for pumping the message loop in that thread.
184 * The WM_USER messages which point to the RPCs are then dispatched to
185 * COM_AptWndProc by the user's code from the apartment in which the interface
188 memset(&wclass, 0, sizeof(wclass));
189 wclass.lpfnWndProc = apartment_wndproc;
190 wclass.hInstance = OLE32_hInstance;
191 wclass.lpszClassName = wszAptWinClass;
192 RegisterClassW(&wclass);
195 static void COMPOBJ_UninitProcess( void )
197 UnregisterClassW(wszAptWinClass, OLE32_hInstance);
200 static void COM_TlsDestroy(void)
202 struct oletls *info = NtCurrentTeb()->ReservedForOle;
205 if (info->apt) apartment_release(info->apt);
206 if (info->errorinfo) IErrorInfo_Release(info->errorinfo);
207 if (info->state) IUnknown_Release(info->state);
208 HeapFree(GetProcessHeap(), 0, info);
209 NtCurrentTeb()->ReservedForOle = NULL;
213 /******************************************************************************
217 /* allocates memory and fills in the necessary fields for a new apartment
219 static APARTMENT *apartment_construct(DWORD model)
223 TRACE("creating new apartment, model=%ld\n", model);
225 apt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*apt));
226 apt->tid = GetCurrentThreadId();
227 DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
228 GetCurrentProcess(), &apt->thread,
229 THREAD_ALL_ACCESS, FALSE, 0);
231 list_init(&apt->proxies);
232 list_init(&apt->stubmgrs);
235 apt->remunk_exported = FALSE;
237 InitializeCriticalSection(&apt->cs);
238 DEBUG_SET_CRITSEC_NAME(&apt->cs, "apartment");
242 if (model & COINIT_APARTMENTTHREADED)
244 /* FIXME: should be randomly generated by in an RPC call to rpcss */
245 apt->oxid = ((OXID)GetCurrentProcessId() << 32) | GetCurrentThreadId();
246 apt->win = CreateWindowW(wszAptWinClass, NULL, 0,
248 0, 0, OLE32_hInstance, NULL);
252 /* FIXME: should be randomly generated by in an RPC call to rpcss */
253 apt->oxid = ((OXID)GetCurrentProcessId() << 32) | 0xcafe;
256 TRACE("Created apartment on OXID %s\n", wine_dbgstr_longlong(apt->oxid));
258 /* the locking here is not currently needed for the MTA case, but it
259 * doesn't hurt and makes the code simpler */
260 EnterCriticalSection(&csApartment);
261 list_add_head(&apts, &apt->entry);
262 LeaveCriticalSection(&csApartment);
267 /* gets and existing apartment if one exists or otherwise creates an apartment
268 * structure which stores OLE apartment-local information and stores a pointer
269 * to it in the thread-local storage */
270 static APARTMENT *apartment_get_or_create(DWORD model)
272 APARTMENT *apt = COM_CurrentApt();
276 if (model & COINIT_APARTMENTTHREADED)
278 apt = apartment_construct(model);
279 COM_CurrentInfo()->apt = apt;
283 EnterCriticalSection(&csApartment);
285 /* The multi-threaded apartment (MTA) contains zero or more threads interacting
286 * with free threaded (ie thread safe) COM objects. There is only ever one MTA
290 TRACE("entering the multithreaded apartment %s\n", wine_dbgstr_longlong(MTA->oxid));
291 apartment_addref(MTA);
294 MTA = apartment_construct(model);
297 COM_CurrentInfo()->apt = apt;
299 LeaveCriticalSection(&csApartment);
306 DWORD apartment_addref(struct apartment *apt)
308 DWORD refs = InterlockedIncrement(&apt->refs);
309 TRACE("%s: before = %ld\n", wine_dbgstr_longlong(apt->oxid), refs - 1);
313 DWORD apartment_release(struct apartment *apt)
317 EnterCriticalSection(&csApartment);
319 ret = InterlockedDecrement(&apt->refs);
320 TRACE("%s: after = %ld\n", wine_dbgstr_longlong(apt->oxid), ret);
321 /* destruction stuff that needs to happen under csApartment CS */
324 if (apt == MTA) MTA = NULL;
325 list_remove(&apt->entry);
328 LeaveCriticalSection(&csApartment);
332 struct list *cursor, *cursor2;
334 TRACE("destroying apartment %p, oxid %s\n", apt, wine_dbgstr_longlong(apt->oxid));
336 /* no locking is needed for this apartment, because no other thread
337 * can access it at this point */
339 apartment_disconnectproxies(apt);
341 if (apt->win) DestroyWindow(apt->win);
343 LIST_FOR_EACH_SAFE(cursor, cursor2, &apt->stubmgrs)
345 struct stub_manager *stubmgr = LIST_ENTRY(cursor, struct stub_manager, entry);
346 /* release the implicit reference given by the fact that the
347 * stub has external references (it must do since it is in the
348 * stub manager list in the apartment and all non-apartment users
349 * must have a ref on the apartment and so it cannot be destroyed).
351 stub_manager_int_release(stubmgr);
354 /* if this assert fires, then another thread took a reference to a
355 * stub manager without taking a reference to the containing
356 * apartment, which it must do. */
357 assert(list_empty(&apt->stubmgrs));
359 if (apt->filter) IUnknown_Release(apt->filter);
361 DEBUG_CLEAR_CRITSEC_NAME(&apt->cs);
362 DeleteCriticalSection(&apt->cs);
363 CloseHandle(apt->thread);
365 HeapFree(GetProcessHeap(), 0, apt);
371 /* The given OXID must be local to this process:
373 * The ref parameter is here mostly to ensure people remember that
374 * they get one, you should normally take a ref for thread safety.
376 APARTMENT *apartment_findfromoxid(OXID oxid, BOOL ref)
378 APARTMENT *result = NULL;
381 EnterCriticalSection(&csApartment);
382 LIST_FOR_EACH( cursor, &apts )
384 struct apartment *apt = LIST_ENTRY( cursor, struct apartment, entry );
385 if (apt->oxid == oxid)
388 if (ref) apartment_addref(result);
392 LeaveCriticalSection(&csApartment);
397 /* gets the apartment which has a given creator thread ID. The caller must
398 * release the reference from the apartment as soon as the apartment pointer
399 * is no longer required. */
400 APARTMENT *apartment_findfromtid(DWORD tid)
402 APARTMENT *result = NULL;
405 EnterCriticalSection(&csApartment);
406 LIST_FOR_EACH( cursor, &apts )
408 struct apartment *apt = LIST_ENTRY( cursor, struct apartment, entry );
412 apartment_addref(result);
416 LeaveCriticalSection(&csApartment);
421 static LRESULT CALLBACK apartment_wndproc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
426 return RPC_ExecuteCall((struct dispatch_params *)lParam);
428 return DefWindowProcW(hWnd, msg, wParam, lParam);
432 /*****************************************************************************
433 * This section contains OpenDllList implemantation
436 static void COMPOBJ_DLLList_Add(HANDLE hLibrary)
443 EnterCriticalSection( &csOpenDllList );
445 if (openDllList == NULL) {
446 /* empty list -- add first node */
447 openDllList = HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
448 openDllList->hLibrary=hLibrary;
449 openDllList->next = NULL;
451 /* search for this dll */
453 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
454 if (ptr->hLibrary == hLibrary) {
460 /* dll not found, add it */
462 openDllList = HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
463 openDllList->hLibrary = hLibrary;
464 openDllList->next = tmp;
468 LeaveCriticalSection( &csOpenDllList );
471 static void COMPOBJ_DllList_FreeUnused(int Timeout)
473 OpenDll *curr, *next, *prev = NULL;
474 typedef HRESULT (WINAPI *DllCanUnloadNowFunc)(void);
475 DllCanUnloadNowFunc DllCanUnloadNow;
479 EnterCriticalSection( &csOpenDllList );
481 for (curr = openDllList; curr != NULL; ) {
482 DllCanUnloadNow = (DllCanUnloadNowFunc) GetProcAddress(curr->hLibrary, "DllCanUnloadNow");
484 if ( (DllCanUnloadNow != NULL) && (DllCanUnloadNow() == S_OK) ) {
487 TRACE("freeing %p\n", curr->hLibrary);
488 FreeLibrary(curr->hLibrary);
490 HeapFree(GetProcessHeap(), 0, curr);
491 if (curr == openDllList) {
504 LeaveCriticalSection( &csOpenDllList );
507 /******************************************************************************
508 * CoBuildVersion [OLE32.@]
509 * CoBuildVersion [COMPOBJ.1]
511 * Gets the build version of the DLL.
516 * Current build version, hiword is majornumber, loword is minornumber
518 DWORD WINAPI CoBuildVersion(void)
520 TRACE("Returning version %d, build %d.\n", rmm, rup);
521 return (rmm<<16)+rup;
524 /******************************************************************************
525 * CoInitialize [OLE32.@]
527 * Initializes the COM libraries by calling CoInitializeEx with
528 * COINIT_APARTMENTTHREADED, ie it enters a STA thread.
531 * lpReserved [I] Pointer to IMalloc interface (obsolete, should be NULL).
534 * Success: S_OK if not already initialized, S_FALSE otherwise.
535 * Failure: HRESULT code.
540 HRESULT WINAPI CoInitialize(LPVOID lpReserved)
543 * Just delegate to the newer method.
545 return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
548 /******************************************************************************
549 * CoInitializeEx [OLE32.@]
551 * Initializes the COM libraries.
554 * lpReserved [I] Pointer to IMalloc interface (obsolete, should be NULL).
555 * dwCoInit [I] One or more flags from the COINIT enumeration. See notes.
558 * S_OK if successful,
559 * S_FALSE if this function was called already.
560 * RPC_E_CHANGED_MODE if a previous call to CoInitializeEx specified another
565 * The behavior used to set the IMalloc used for memory management is
567 * The dwCoInit parameter must specify of of the following apartment
569 *| COINIT_APARTMENTTHREADED - A single-threaded apartment (STA).
570 *| COINIT_MULTITHREADED - A multi-threaded apartment (MTA).
571 * The parameter may also specify zero or more of the following flags:
572 *| COINIT_DISABLE_OLE1DDE - Don't use DDE for OLE1 support.
573 *| COINIT_SPEED_OVER_MEMORY - Trade memory for speed.
578 HRESULT WINAPI CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
583 TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
585 if (lpReserved!=NULL)
587 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
591 * Check the lock count. If this is the first time going through the initialize
592 * process, we have to initialize the libraries.
594 * And crank-up that lock count.
596 if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
599 * Initialize the various COM libraries and data structures.
601 TRACE("() - Initializing the COM libraries\n");
603 /* we may need to defer this until after apartment initialisation */
604 RunningObjectTableImpl_Initialize();
607 if (!(apt = COM_CurrentInfo()->apt))
609 apt = apartment_get_or_create(dwCoInit);
610 if (!apt) return E_OUTOFMEMORY;
612 else if (dwCoInit != apt->model)
614 /* Changing the threading model after it's been set is illegal. If this warning is triggered by Wine
615 code then we are probably using the wrong threading model to implement that API. */
616 ERR("Attempt to change threading model of this apartment from 0x%lx to 0x%lx\n", apt->model, dwCoInit);
617 return RPC_E_CHANGED_MODE;
622 COM_CurrentInfo()->inits++;
627 /* On COM finalization for a STA thread, the message queue is flushed to ensure no
628 pending RPCs are ignored. Non-COM messages are discarded at this point.
630 static void COM_FlushMessageQueue(void)
633 APARTMENT *apt = COM_CurrentApt();
635 if (!apt || !apt->win) return;
637 TRACE("Flushing STA message queue\n");
639 while (PeekMessageA(&message, NULL, 0, 0, PM_REMOVE))
641 if (message.hwnd != apt->win)
643 WARN("discarding message 0x%x for window %p\n", message.message, message.hwnd);
647 TranslateMessage(&message);
648 DispatchMessageA(&message);
652 /***********************************************************************
653 * CoUninitialize [OLE32.@]
655 * This method will decrement the refcount on the current apartment, freeing
656 * the resources associated with it if it is the last thread in the apartment.
657 * If the last apartment is freed, the function will additionally release
658 * any COM resources associated with the process.
668 void WINAPI CoUninitialize(void)
670 struct oletls * info = COM_CurrentInfo();
675 /* will only happen on OOM */
681 ERR("Mismatched CoUninitialize\n");
687 apartment_release(info->apt);
692 * Decrease the reference count.
693 * If we are back to 0 locks on the COM library, make sure we free
694 * all the associated data structures.
696 lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
699 TRACE("() - Releasing the COM libraries\n");
701 RunningObjectTableImpl_UnInitialize();
703 /* Release the references to the registered class objects */
704 COM_RevokeAllClasses();
706 /* This will free the loaded COM Dlls */
707 CoFreeAllLibraries();
709 /* This ensures we deal with any pending RPCs */
710 COM_FlushMessageQueue();
712 else if (lCOMRefCnt<1) {
713 ERR( "CoUninitialize() - not CoInitialized.\n" );
714 InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
718 /******************************************************************************
719 * CoDisconnectObject [OLE32.@]
720 * CoDisconnectObject [COMPOBJ.15]
722 * Disconnects all connections to this object from remote processes. Dispatches
723 * pending RPCs while blocking new RPCs from occurring, and then calls
724 * IMarshal::DisconnectObject on the given object.
726 * Typically called when the object server is forced to shut down, for instance by
730 * lpUnk [I] The object whose stub should be disconnected.
731 * reserved [I] Reserved. Should be set to 0.
735 * Failure: HRESULT code.
738 * CoMarshalInterface, CoReleaseMarshalData, CoLockObjectExternal
740 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
746 TRACE("(%p, 0x%08lx)\n", lpUnk, reserved);
748 hr = IUnknown_QueryInterface(lpUnk, &IID_IMarshal, (void **)&marshal);
751 hr = IMarshal_DisconnectObject(marshal, reserved);
752 IMarshal_Release(marshal);
756 apt = COM_CurrentApt();
758 return CO_E_NOTINITIALIZED;
760 apartment_disconnectobject(apt, lpUnk);
762 /* Note: native is pretty broken here because it just silently
763 * fails, without returning an appropriate error code if the object was
764 * not found, making apps think that the object was disconnected, when
765 * it actually wasn't */
770 /******************************************************************************
771 * CoCreateGuid [OLE32.@]
773 * Simply forwards to UuidCreate in RPCRT4.
776 * pguid [O] Points to the GUID to initialize.
780 * Failure: HRESULT code.
785 HRESULT WINAPI CoCreateGuid(GUID *pguid)
787 return UuidCreate(pguid);
790 /******************************************************************************
791 * CLSIDFromString [OLE32.@]
792 * IIDFromString [OLE32.@]
794 * Converts a unique identifier from its string representation into
798 * idstr [I] The string representation of the GUID.
799 * id [O] GUID converted from the string.
803 * CO_E_CLASSSTRING if idstr is not a valid CLSID
807 * In Windows, if idstr is not a valid CLSID string then it gets
808 * treated as a ProgID. Wine currently doesn't do this. If idstr is
809 * NULL it's treated as an all-zero GUID.
814 HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id)
816 const BYTE *s = (const BYTE *) idstr;
821 s = "{00000000-0000-0000-0000-000000000000}";
822 else { /* validate the CLSID string */
825 return CO_E_CLASSSTRING;
827 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
828 return CO_E_CLASSSTRING;
830 for (i=1; i<37; i++) {
831 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
832 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
833 ((s[i] >= 'a') && (s[i] <= 'f')) ||
834 ((s[i] >= 'A') && (s[i] <= 'F'))))
835 return CO_E_CLASSSTRING;
839 TRACE("%s -> %p\n", s, id);
841 /* quick lookup table */
842 memset(table, 0, 256);
844 for (i = 0; i < 10; i++) {
847 for (i = 0; i < 6; i++) {
848 table['A' + i] = i+10;
849 table['a' + i] = i+10;
852 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
854 id->Data1 = (table[s[1]] << 28 | table[s[2]] << 24 | table[s[3]] << 20 | table[s[4]] << 16 |
855 table[s[5]] << 12 | table[s[6]] << 8 | table[s[7]] << 4 | table[s[8]]);
856 id->Data2 = table[s[10]] << 12 | table[s[11]] << 8 | table[s[12]] << 4 | table[s[13]];
857 id->Data3 = table[s[15]] << 12 | table[s[16]] << 8 | table[s[17]] << 4 | table[s[18]];
859 /* these are just sequential bytes */
860 id->Data4[0] = table[s[20]] << 4 | table[s[21]];
861 id->Data4[1] = table[s[22]] << 4 | table[s[23]];
862 id->Data4[2] = table[s[25]] << 4 | table[s[26]];
863 id->Data4[3] = table[s[27]] << 4 | table[s[28]];
864 id->Data4[4] = table[s[29]] << 4 | table[s[30]];
865 id->Data4[5] = table[s[31]] << 4 | table[s[32]];
866 id->Data4[6] = table[s[33]] << 4 | table[s[34]];
867 id->Data4[7] = table[s[35]] << 4 | table[s[36]];
872 /*****************************************************************************/
874 HRESULT WINAPI CLSIDFromString(LPOLESTR idstr, CLSID *id )
879 if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL ))
880 return CO_E_CLASSSTRING;
883 ret = __CLSIDFromStringA(xid,id);
884 if(ret != S_OK) { /* It appears a ProgID is also valid */
885 ret = CLSIDFromProgID(idstr, id);
890 /* Converts a GUID into the respective string representation. */
891 HRESULT WINE_StringFromCLSID(
892 const CLSID *id, /* [in] GUID to be converted */
893 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
895 static const char *hex = "0123456789ABCDEF";
900 { ERR("called with id=Null\n");
905 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
906 id->Data1, id->Data2, id->Data3,
907 id->Data4[0], id->Data4[1]);
911 for (i = 2; i < 8; i++) {
912 *s++ = hex[id->Data4[i]>>4];
913 *s++ = hex[id->Data4[i] & 0xf];
919 TRACE("%p->%s\n", id, idstr);
925 /******************************************************************************
926 * StringFromCLSID [OLE32.@]
927 * StringFromIID [OLE32.@]
929 * Converts a GUID into the respective string representation.
930 * The target string is allocated using the OLE IMalloc.
933 * id [I] the GUID to be converted.
934 * idstr [O] A pointer to a to-be-allocated pointer pointing to the resulting string.
941 * StringFromGUID2, CLSIDFromString
943 HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR *idstr)
949 if ((ret = CoGetMalloc(0,&mllc)))
952 ret=WINE_StringFromCLSID(id,buf);
954 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
955 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
956 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
961 /******************************************************************************
962 * StringFromGUID2 [OLE32.@]
963 * StringFromGUID2 [COMPOBJ.76]
965 * Modified version of StringFromCLSID that allows you to specify max
969 * id [I] GUID to convert to string.
970 * str [O] Buffer where the result will be stored.
971 * cmax [I] Size of the buffer in characters.
974 * Success: The length of the resulting string in characters.
977 INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
981 if (WINE_StringFromCLSID(id,xguid))
983 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
986 /* open HKCR\\CLSID\\{string form of clsid} key */
987 DWORD COM_OpenKeyForCLSID(REFCLSID clsid, REGSAM access, HKEY *key)
989 static const WCHAR wszCLSIDSlash[] = {'C','L','S','I','D','\\',0};
990 WCHAR path[CHARS_IN_GUID + ARRAYSIZE(wszCLSIDSlash) - 1];
991 strcpyW(path, wszCLSIDSlash);
992 StringFromGUID2(clsid, path + strlenW(wszCLSIDSlash), CHARS_IN_GUID);
993 return RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, access, key);
996 /******************************************************************************
997 * ProgIDFromCLSID [OLE32.@]
999 * Converts a class id into the respective program ID.
1002 * clsid [I] Class ID, as found in registry.
1003 * lplpszProgID [O] Associated ProgID.
1008 * REGDB_E_CLASSNOTREG if the given clsid has no associated ProgID
1010 HRESULT WINAPI ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID)
1012 static const WCHAR wszProgID[] = {'P','r','o','g','I','D',0};
1017 if (ERROR_SUCCESS != COM_OpenKeyForCLSID(clsid, KEY_READ, &hkey_clsid))
1018 ret = REGDB_E_CLASSNOTREG;
1022 if (RegOpenKeyExW(hkey_clsid, wszProgID, 0, KEY_READ, &hkey))
1023 ret = REGDB_E_CLASSNOTREG;
1024 RegCloseKey(hkey_clsid);
1029 DWORD progidlen = 0;
1031 if (RegQueryValueW(hkey, NULL, NULL, &progidlen))
1032 ret = REGDB_E_CLASSNOTREG;
1036 *lplpszProgID = CoTaskMemAlloc(progidlen * sizeof(WCHAR));
1039 if (RegQueryValueW(hkey, NULL, *lplpszProgID, &progidlen))
1040 ret = REGDB_E_CLASSNOTREG;
1043 ret = E_OUTOFMEMORY;
1051 /******************************************************************************
1052 * CLSIDFromProgID [COMPOBJ.61]
1054 * Converts a program ID into the respective GUID.
1057 * progid [I] program id as found in registry
1058 * riid [O] associated CLSID
1062 * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
1064 HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid)
1071 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
1072 sprintf(buf,"%s\\CLSID",progid);
1073 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
1074 HeapFree(GetProcessHeap(),0,buf);
1075 return CO_E_CLASSSTRING;
1077 HeapFree(GetProcessHeap(),0,buf);
1078 buf2len = sizeof(buf2);
1079 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
1081 return CO_E_CLASSSTRING;
1084 return __CLSIDFromStringA(buf2,riid);
1087 /******************************************************************************
1088 * CLSIDFromProgID [OLE32.@]
1090 * Converts a program id into the respective GUID.
1093 * progid [I] Unicode program ID, as found in registry.
1094 * riid [O] Associated CLSID.
1098 * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found.
1100 HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID riid)
1102 static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
1103 WCHAR buf2[CHARS_IN_GUID];
1104 DWORD buf2len = sizeof(buf2);
1107 WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
1108 strcpyW( buf, progid );
1109 strcatW( buf, clsidW );
1110 if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
1112 HeapFree(GetProcessHeap(),0,buf);
1113 return CO_E_CLASSSTRING;
1115 HeapFree(GetProcessHeap(),0,buf);
1117 if (RegQueryValueW(xhkey,NULL,buf2,&buf2len))
1120 return CO_E_CLASSSTRING;
1123 return CLSIDFromString(buf2,riid);
1128 /*****************************************************************************
1129 * CoGetPSClsid [OLE32.@]
1131 * Retrieves the CLSID of the proxy/stub factory that implements
1132 * IPSFactoryBuffer for the specified interface.
1135 * riid [I] Interface whose proxy/stub CLSID is to be returned.
1136 * pclsid [O] Where to store returned proxy/stub CLSID.
1141 * REGDB_E_IIDNOTREG if no PSFactoryBuffer is associated with the IID, or it could not be parsed
1145 * The standard marshaller activates the object with the CLSID
1146 * returned and uses the CreateProxy and CreateStub methods on its
1147 * IPSFactoryBuffer interface to construct the proxies and stubs for a
1150 * CoGetPSClsid determines this CLSID by searching the
1151 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32
1152 * in the registry and any interface id registered by
1153 * CoRegisterPSClsid within the current process.
1157 * We only search the registry, not ids registered with
1158 * CoRegisterPSClsid.
1159 * Also, native returns S_OK for interfaces with a key in HKCR\Interface, but
1160 * without a ProxyStubClsid32 key and leaves garbage in pclsid. This should be
1161 * considered a bug in native unless an application depends on this (unlikely).
1163 HRESULT WINAPI CoGetPSClsid(REFIID riid, CLSID *pclsid)
1165 static const WCHAR wszInterface[] = {'I','n','t','e','r','f','a','c','e','\\',0};
1166 static const WCHAR wszPSC[] = {'\\','P','r','o','x','y','S','t','u','b','C','l','s','i','d','3','2',0};
1167 WCHAR path[ARRAYSIZE(wszInterface) - 1 + CHARS_IN_GUID - 1 + ARRAYSIZE(wszPSC)];
1168 WCHAR value[CHARS_IN_GUID];
1172 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
1174 /* Interface\\{string form of riid}\\ProxyStubClsid32 */
1175 strcpyW(path, wszInterface);
1176 StringFromGUID2(riid, path + ARRAYSIZE(wszInterface) - 1, CHARS_IN_GUID);
1177 strcpyW(path + ARRAYSIZE(wszInterface) - 1 + CHARS_IN_GUID - 1, wszPSC);
1179 /* Open the key.. */
1180 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, KEY_READ, &hkey))
1182 WARN("No PSFactoryBuffer object is registered for IID %s\n", debugstr_guid(riid));
1183 return REGDB_E_IIDNOTREG;
1186 /* ... Once we have the key, query the registry to get the
1187 value of CLSID as a string, and convert it into a
1188 proper CLSID structure to be passed back to the app */
1189 len = sizeof(value);
1190 if (ERROR_SUCCESS != RegQueryValueW(hkey, NULL, value, &len))
1193 return REGDB_E_IIDNOTREG;
1197 /* We have the CLSid we want back from the registry as a string, so
1198 lets convert it into a CLSID structure */
1199 if (CLSIDFromString(value, pclsid) != NOERROR)
1200 return REGDB_E_IIDNOTREG;
1202 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
1208 /***********************************************************************
1209 * WriteClassStm (OLE32.@)
1211 * Writes a CLSID to a stream.
1214 * pStm [I] Stream to write to.
1215 * rclsid [I] CLSID to write.
1219 * Failure: HRESULT code.
1221 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
1223 TRACE("(%p,%p)\n",pStm,rclsid);
1226 return E_INVALIDARG;
1228 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
1231 /***********************************************************************
1232 * ReadClassStm (OLE32.@)
1234 * Reads a CLSID from a stream.
1237 * pStm [I] Stream to read from.
1238 * rclsid [O] CLSID to read.
1242 * Failure: HRESULT code.
1244 HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
1249 TRACE("(%p,%p)\n",pStm,pclsid);
1252 return E_INVALIDARG;
1254 res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
1259 if (nbByte != sizeof(CLSID))
1267 * COM_GetRegisteredClassObject
1269 * This internal method is used to scan the registered class list to
1270 * find a class object.
1273 * rclsid Class ID of the class to find.
1274 * dwClsContext Class context to match.
1275 * ppv [out] returns a pointer to the class object. Complying
1276 * to normal COM usage, this method will increase the
1277 * reference count on this object.
1279 static HRESULT COM_GetRegisteredClassObject(
1284 HRESULT hr = S_FALSE;
1285 RegisteredClass* curClass;
1287 EnterCriticalSection( &csRegisteredClassList );
1295 * Iterate through the whole list and try to match the class ID.
1297 curClass = firstRegisteredClass;
1299 while (curClass != 0)
1302 * Check if we have a match on the class ID.
1304 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
1307 * Since we don't do out-of process or DCOM just right away, let's ignore the
1312 * We have a match, return the pointer to the class object.
1314 *ppUnk = curClass->classObject;
1316 IUnknown_AddRef(curClass->classObject);
1323 * Step to the next class in the list.
1325 curClass = curClass->nextClass;
1329 LeaveCriticalSection( &csRegisteredClassList );
1331 * If we get to here, we haven't found our class.
1336 /******************************************************************************
1337 * CoRegisterClassObject [OLE32.@]
1339 * Registers the class object for a given class ID. Servers housed in EXE
1340 * files use this method instead of exporting DllGetClassObject to allow
1341 * other code to connect to their objects.
1344 * rclsid [I] CLSID of the object to register.
1345 * pUnk [I] IUnknown of the object.
1346 * dwClsContext [I] CLSCTX flags indicating the context in which to run the executable.
1347 * flags [I] REGCLS flags indicating how connections are made.
1348 * lpdwRegister [I] A unique cookie that can be passed to CoRevokeClassObject.
1352 * E_INVALIDARG if lpdwRegister or pUnk are NULL,
1353 * CO_E_OBJISREG if the object is already registered. We should not return this.
1356 * CoRevokeClassObject, CoGetClassObject
1359 * MSDN claims that multiple interface registrations are legal, but we
1360 * can't do that with our current implementation.
1362 HRESULT WINAPI CoRegisterClassObject(
1367 LPDWORD lpdwRegister)
1369 RegisteredClass* newClass;
1370 LPUNKNOWN foundObject;
1373 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1374 debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister);
1376 if ( (lpdwRegister==0) || (pUnk==0) )
1377 return E_INVALIDARG;
1379 if (!COM_CurrentApt())
1381 ERR("COM was not initialized\n");
1382 return CO_E_NOTINITIALIZED;
1388 * First, check if the class is already registered.
1389 * If it is, this should cause an error.
1391 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1393 IUnknown_Release(foundObject);
1394 return CO_E_OBJISREG;
1397 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1398 if ( newClass == NULL )
1399 return E_OUTOFMEMORY;
1401 EnterCriticalSection( &csRegisteredClassList );
1403 newClass->classIdentifier = *rclsid;
1404 newClass->runContext = dwClsContext;
1405 newClass->connectFlags = flags;
1407 * Use the address of the chain node as the cookie since we are sure it's
1408 * unique. FIXME: not on 64-bit platforms.
1410 newClass->dwCookie = (DWORD)newClass;
1411 newClass->nextClass = firstRegisteredClass;
1414 * Since we're making a copy of the object pointer, we have to increase its
1417 newClass->classObject = pUnk;
1418 IUnknown_AddRef(newClass->classObject);
1420 firstRegisteredClass = newClass;
1421 LeaveCriticalSection( &csRegisteredClassList );
1423 *lpdwRegister = newClass->dwCookie;
1425 if (dwClsContext & CLSCTX_LOCAL_SERVER) {
1426 IClassFactory *classfac;
1428 hr = IUnknown_QueryInterface(newClass->classObject, &IID_IClassFactory,
1429 (LPVOID*)&classfac);
1432 hr = CreateStreamOnHGlobal(0, TRUE, &newClass->pMarshaledData);
1434 FIXME("Failed to create stream on hglobal, %lx\n", hr);
1435 IUnknown_Release(classfac);
1438 hr = CoMarshalInterface(newClass->pMarshaledData, &IID_IClassFactory,
1439 (LPVOID)classfac, MSHCTX_LOCAL, NULL,
1440 MSHLFLAGS_TABLESTRONG);
1442 FIXME("CoMarshalInterface failed, %lx!\n",hr);
1443 IUnknown_Release(classfac);
1447 IUnknown_Release(classfac);
1449 RPC_StartLocalServer(&newClass->classIdentifier, newClass->pMarshaledData);
1454 /***********************************************************************
1455 * CoRevokeClassObject [OLE32.@]
1457 * Removes a class object from the class registry.
1460 * dwRegister [I] Cookie returned from CoRegisterClassObject().
1464 * Failure: HRESULT code.
1467 * CoRegisterClassObject
1469 HRESULT WINAPI CoRevokeClassObject(
1472 HRESULT hr = E_INVALIDARG;
1473 RegisteredClass** prevClassLink;
1474 RegisteredClass* curClass;
1476 TRACE("(%08lx)\n",dwRegister);
1478 EnterCriticalSection( &csRegisteredClassList );
1481 * Iterate through the whole list and try to match the cookie.
1483 curClass = firstRegisteredClass;
1484 prevClassLink = &firstRegisteredClass;
1486 while (curClass != 0)
1489 * Check if we have a match on the cookie.
1491 if (curClass->dwCookie == dwRegister)
1494 * Remove the class from the chain.
1496 *prevClassLink = curClass->nextClass;
1499 * Release the reference to the class object.
1501 IUnknown_Release(curClass->classObject);
1503 if (curClass->pMarshaledData)
1506 memset(&zero, 0, sizeof(zero));
1507 /* FIXME: stop local server thread */
1508 IStream_Seek(curClass->pMarshaledData, zero, SEEK_SET, NULL);
1509 CoReleaseMarshalData(curClass->pMarshaledData);
1513 * Free the memory used by the chain node.
1515 HeapFree(GetProcessHeap(), 0, curClass);
1522 * Step to the next class in the list.
1524 prevClassLink = &(curClass->nextClass);
1525 curClass = curClass->nextClass;
1529 LeaveCriticalSection( &csRegisteredClassList );
1531 * If we get to here, we haven't found our class.
1536 /***********************************************************************
1537 * COM_RegReadPath [internal]
1539 * Reads a registry value and expands it when necessary
1541 HRESULT COM_RegReadPath(HKEY hkeyroot, const WCHAR *keyname, const WCHAR *valuename, WCHAR * dst, DWORD dstlen)
1546 WCHAR src[MAX_PATH];
1547 DWORD dwLength = dstlen * sizeof(WCHAR);
1549 if((hres = RegOpenKeyExW(hkeyroot, keyname, 0, KEY_READ, &key)) == ERROR_SUCCESS) {
1550 if( (hres = RegQueryValueExW(key, NULL, NULL, &keytype, (LPBYTE)src, &dwLength)) == ERROR_SUCCESS ) {
1551 if (keytype == REG_EXPAND_SZ) {
1552 if (dstlen <= ExpandEnvironmentStringsW(src, dst, dstlen)) hres = ERROR_MORE_DATA;
1554 lstrcpynW(dst, src, dstlen);
1562 /***********************************************************************
1563 * CoGetClassObject [COMPOBJ.7]
1564 * CoGetClassObject [OLE32.@]
1566 * FIXME. If request allows of several options and there is a failure
1567 * with one (other than not being registered) do we try the
1568 * others or return failure? (E.g. inprocess is registered but
1569 * the DLL is not found but the server version works)
1571 HRESULT WINAPI CoGetClassObject(
1572 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1573 REFIID iid, LPVOID *ppv)
1575 LPUNKNOWN regClassObject;
1576 HRESULT hres = E_UNEXPECTED;
1578 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
1581 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
1582 FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
1586 * First, try and see if we can't match the class ID with one of the
1587 * registered classes.
1589 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1591 /* Get the required interface from the retrieved pointer. */
1592 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1595 * Since QI got another reference on the pointer, we want to release the
1596 * one we already have. If QI was unsuccessful, this will release the object. This
1597 * is good since we are not returning it in the "out" parameter.
1599 IUnknown_Release(regClassObject);
1604 /* first try: in-process */
1605 if ((CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER) & dwClsContext)
1607 static const WCHAR wszInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
1609 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
1610 DllGetClassObjectFunc DllGetClassObject;
1611 WCHAR dllpath[MAX_PATH+1];
1614 if (ERROR_SUCCESS != COM_OpenKeyForCLSID(rclsid, KEY_READ, &hkey))
1616 ERR("class %s not registered\n", debugstr_guid(rclsid));
1617 hres = REGDB_E_CLASSNOTREG;
1620 if (COM_RegReadPath(hkey, wszInprocServer32, NULL, dllpath, ARRAYSIZE(dllpath)) != ERROR_SUCCESS)
1622 /* failure: CLSID is not found in registry */
1623 WARN("class %s not registered inproc\n", debugstr_guid(rclsid));
1624 hres = REGDB_E_CLASSNOTREG;
1628 if ((hLibrary = LoadLibraryExW(dllpath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0)
1630 /* failure: DLL could not be loaded */
1631 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(dllpath));
1632 hres = E_ACCESSDENIED; /* FIXME: or should this be CO_E_DLLNOTFOUND? */
1634 else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject")))
1636 /* failure: the dll did not export DllGetClassObject */
1637 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllpath));
1638 FreeLibrary( hLibrary );
1639 hres = CO_E_DLLNOTFOUND;
1643 /* OK: get the ClassObject */
1644 COMPOBJ_DLLList_Add( hLibrary );
1645 return DllGetClassObject(rclsid, iid, ppv);
1650 /* Next try out of process */
1651 if (CLSCTX_LOCAL_SERVER & dwClsContext)
1653 return RPC_GetLocalClassObject(rclsid,iid,ppv);
1656 /* Finally try remote: this requires networked DCOM (a lot of work) */
1657 if (CLSCTX_REMOTE_SERVER & dwClsContext)
1659 FIXME ("CLSCTX_REMOTE_SERVER not supported\n");
1660 hres = E_NOINTERFACE;
1665 /***********************************************************************
1666 * CoResumeClassObjects (OLE32.@)
1668 * Resumes all class objects registered with REGCLS_SUSPENDED.
1672 * Failure: HRESULT code.
1674 HRESULT WINAPI CoResumeClassObjects(void)
1680 /***********************************************************************
1681 * GetClassFile (OLE32.@)
1683 * This function supplies the CLSID associated with the given filename.
1685 HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
1689 int nbElm, length, i;
1691 LPOLESTR *pathDec=0,absFile=0,progId=0;
1693 static const WCHAR bkslashW[] = {'\\',0};
1694 static const WCHAR dotW[] = {'.',0};
1696 TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
1698 /* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/
1699 if((StgIsStorageFile(filePathName))==S_OK){
1701 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1704 res=ReadClassStg(pstg,pclsid);
1706 IStorage_Release(pstg);
1710 /* if the file is not a storage object then attemps to match various bits in the file against a
1711 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1714 for(i=0;i<nFileTypes;i++)
1716 for(i=0;j<nPatternsForType;j++){
1721 pat=ReadPatternFromRegistry(i,j);
1722 hFile=CreateFileW(filePathName,,,,,,hFile);
1723 SetFilePosition(hFile,pat.offset);
1724 ReadFile(hFile,buf,pat.size,&r,NULL);
1725 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1727 *pclsid=ReadCLSIDFromRegistry(i);
1733 /* if the above strategies fail then search for the extension key in the registry */
1735 /* get the last element (absolute file) in the path name */
1736 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1737 absFile=pathDec[nbElm-1];
1739 /* failed if the path represente a directory and not an absolute file name*/
1740 if (!lstrcmpW(absFile, bkslashW))
1741 return MK_E_INVALIDEXTENSION;
1743 /* get the extension of the file */
1745 length=lstrlenW(absFile);
1746 for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
1749 if (!extension || !lstrcmpW(extension, dotW))
1750 return MK_E_INVALIDEXTENSION;
1752 res=RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
1754 /* get the progId associated to the extension */
1755 progId = CoTaskMemAlloc(sizeProgId);
1756 res = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId);
1758 if (res==ERROR_SUCCESS)
1759 /* return the clsid associated to the progId */
1760 res= CLSIDFromProgID(progId,pclsid);
1762 for(i=0; pathDec[i]!=NULL;i++)
1763 CoTaskMemFree(pathDec[i]);
1764 CoTaskMemFree(pathDec);
1766 CoTaskMemFree(progId);
1768 if (res==ERROR_SUCCESS)
1771 return MK_E_INVALIDEXTENSION;
1773 /***********************************************************************
1774 * CoCreateInstance [COMPOBJ.13]
1775 * CoCreateInstance [OLE32.@]
1777 HRESULT WINAPI CoCreateInstance(
1779 LPUNKNOWN pUnkOuter,
1785 LPCLASSFACTORY lpclf = 0;
1787 if (!COM_CurrentApt()) return CO_E_NOTINITIALIZED;
1796 * Initialize the "out" parameter
1801 * The Standard Global Interface Table (GIT) object is a process-wide singleton.
1802 * Rather than create a class factory, we can just check for it here
1804 if (IsEqualIID(rclsid, &CLSID_StdGlobalInterfaceTable)) {
1805 if (StdGlobalInterfaceTableInstance == NULL)
1806 StdGlobalInterfaceTableInstance = StdGlobalInterfaceTable_Construct();
1807 hres = IGlobalInterfaceTable_QueryInterface( (IGlobalInterfaceTable*) StdGlobalInterfaceTableInstance, iid, ppv);
1808 if (hres) return hres;
1810 TRACE("Retrieved GIT (%p)\n", *ppv);
1815 * Get a class factory to construct the object we want.
1817 hres = CoGetClassObject(rclsid,
1824 FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
1825 debugstr_guid(rclsid),hres);
1830 * Create the object and don't forget to release the factory
1832 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1833 IClassFactory_Release(lpclf);
1835 FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
1836 debugstr_guid(iid), debugstr_guid(rclsid),hres);
1841 /***********************************************************************
1842 * CoCreateInstanceEx [OLE32.@]
1844 HRESULT WINAPI CoCreateInstanceEx(
1846 LPUNKNOWN pUnkOuter,
1848 COSERVERINFO* pServerInfo,
1852 IUnknown* pUnk = NULL;
1855 ULONG successCount = 0;
1860 if ( (cmq==0) || (pResults==NULL))
1861 return E_INVALIDARG;
1863 if (pServerInfo!=NULL)
1864 FIXME("() non-NULL pServerInfo not supported!\n");
1867 * Initialize all the "out" parameters.
1869 for (index = 0; index < cmq; index++)
1871 pResults[index].pItf = NULL;
1872 pResults[index].hr = E_NOINTERFACE;
1876 * Get the object and get its IUnknown pointer.
1878 hr = CoCreateInstance(rclsid,
1888 * Then, query for all the interfaces requested.
1890 for (index = 0; index < cmq; index++)
1892 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1893 pResults[index].pIID,
1894 (VOID**)&(pResults[index].pItf));
1896 if (pResults[index].hr == S_OK)
1901 * Release our temporary unknown pointer.
1903 IUnknown_Release(pUnk);
1905 if (successCount == 0)
1906 return E_NOINTERFACE;
1908 if (successCount!=cmq)
1909 return CO_S_NOTALLINTERFACES;
1914 /***********************************************************************
1915 * CoLoadLibrary (OLE32.@)
1920 * lpszLibName [I] Path to library.
1921 * bAutoFree [I] Whether the library should automatically be freed.
1924 * Success: Handle to loaded library.
1928 * CoFreeLibrary, CoFreeAllLibraries, CoFreeUnusedLibraries
1930 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1932 TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
1934 return LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1937 /***********************************************************************
1938 * CoFreeLibrary [OLE32.@]
1940 * Unloads a library from memory.
1943 * hLibrary [I] Handle to library to unload.
1949 * CoLoadLibrary, CoFreeAllLibraries, CoFreeUnusedLibraries
1951 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1953 FreeLibrary(hLibrary);
1957 /***********************************************************************
1958 * CoFreeAllLibraries [OLE32.@]
1960 * Function for backwards compatibility only. Does nothing.
1966 * CoLoadLibrary, CoFreeLibrary, CoFreeUnusedLibraries
1968 void WINAPI CoFreeAllLibraries(void)
1974 /***********************************************************************
1975 * CoFreeUnusedLibraries [OLE32.@]
1976 * CoFreeUnusedLibraries [COMPOBJ.17]
1978 * Frees any unused libraries. Unused are identified as those that return
1979 * S_OK from their DllCanUnloadNow function.
1985 * CoLoadLibrary, CoFreeAllLibraries, CoFreeLibrary
1987 void WINAPI CoFreeUnusedLibraries(void)
1989 /* FIXME: Calls to CoFreeUnusedLibraries from any thread always route
1990 * through the main apartment's thread to call DllCanUnloadNow */
1991 COMPOBJ_DllList_FreeUnused(0);
1994 /***********************************************************************
1995 * CoFileTimeNow [OLE32.@]
1996 * CoFileTimeNow [COMPOBJ.82]
1998 * Retrieves the current time in FILETIME format.
2001 * lpFileTime [O] The current time.
2006 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime )
2008 GetSystemTimeAsFileTime( lpFileTime );
2012 static void COM_RevokeAllClasses()
2014 EnterCriticalSection( &csRegisteredClassList );
2016 while (firstRegisteredClass!=0)
2018 CoRevokeClassObject(firstRegisteredClass->dwCookie);
2021 LeaveCriticalSection( &csRegisteredClassList );
2024 /******************************************************************************
2025 * CoLockObjectExternal [OLE32.@]
2027 * Increments or decrements the external reference count of a stub object.
2030 * pUnk [I] Stub object.
2031 * fLock [I] If TRUE then increments the external ref-count,
2032 * otherwise decrements.
2033 * fLastUnlockReleases [I] If TRUE then the last unlock has the effect of
2034 * calling CoDisconnectObject.
2038 * Failure: HRESULT code.
2040 HRESULT WINAPI CoLockObjectExternal(
2043 BOOL fLastUnlockReleases)
2045 struct stub_manager *stubmgr;
2046 struct apartment *apt;
2048 TRACE("pUnk=%p, fLock=%s, fLastUnlockReleases=%s\n",
2049 pUnk, fLock ? "TRUE" : "FALSE", fLastUnlockReleases ? "TRUE" : "FALSE");
2051 apt = COM_CurrentApt();
2052 if (!apt) return CO_E_NOTINITIALIZED;
2054 stubmgr = get_stub_manager_from_object(apt, pUnk);
2059 stub_manager_ext_addref(stubmgr, 1);
2061 stub_manager_ext_release(stubmgr, 1);
2063 stub_manager_int_release(stubmgr);
2069 WARN("stub object not found %p\n", pUnk);
2070 /* Note: native is pretty broken here because it just silently
2071 * fails, without returning an appropriate error code, making apps
2072 * think that the object was disconnected, when it actually wasn't */
2077 /***********************************************************************
2078 * CoInitializeWOW (OLE32.@)
2080 * WOW equivalent of CoInitialize?
2089 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y)
2091 FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
2095 /***********************************************************************
2096 * CoGetState [OLE32.@]
2098 * Retrieves the thread state object previously stored by CoSetState().
2101 * ppv [I] Address where pointer to object will be stored.
2105 * Failure: E_OUTOFMEMORY.
2108 * Crashes on all invalid ppv addresses, including NULL.
2109 * If the function returns a non-NULL object then the caller must release its
2110 * reference on the object when the object is no longer required.
2115 HRESULT WINAPI CoGetState(IUnknown ** ppv)
2117 struct oletls *info = COM_CurrentInfo();
2118 if (!info) return E_OUTOFMEMORY;
2124 IUnknown_AddRef(info->state);
2126 TRACE("apt->state=%p\n", info->state);
2132 /***********************************************************************
2133 * CoSetState [OLE32.@]
2135 * Sets the thread state object.
2138 * pv [I] Pointer to state object to be stored.
2141 * The system keeps a reference on the object while the object stored.
2145 * Failure: E_OUTOFMEMORY.
2147 HRESULT WINAPI CoSetState(IUnknown * pv)
2149 struct oletls *info = COM_CurrentInfo();
2150 if (!info) return E_OUTOFMEMORY;
2152 if (pv) IUnknown_AddRef(pv);
2156 TRACE("-- release %p now\n", info->state);
2157 IUnknown_Release(info->state);
2166 /******************************************************************************
2167 * OleGetAutoConvert [OLE32.@]
2169 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2171 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2173 WCHAR buf[CHARS_IN_GUID];
2177 if (ERROR_SUCCESS != COM_OpenKeyForCLSID(clsidOld, KEY_READ, &hkey))
2179 res = REGDB_E_CLASSNOTREG;
2184 /* we can just query for the default value of AutoConvertTo key like that,
2185 without opening the AutoConvertTo key and querying for NULL (default) */
2186 if (RegQueryValueW(hkey, wszAutoConvertTo, buf, &len))
2188 res = REGDB_E_KEYMISSING;
2191 res = CLSIDFromString(buf, pClsidNew);
2193 if (hkey) RegCloseKey(hkey);
2197 /******************************************************************************
2198 * CoTreatAsClass [OLE32.@]
2200 * Sets the TreatAs value of a class.
2203 * clsidOld [I] Class to set TreatAs value on.
2204 * clsidNew [I] The class the clsidOld should be treated as.
2208 * Failure: HRESULT code.
2213 HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
2215 static const WCHAR wszAutoTreatAs[] = {'A','u','t','o','T','r','e','a','t','A','s',0};
2216 static const WCHAR wszTreatAs[] = {'T','r','e','a','t','A','s',0};
2218 WCHAR szClsidNew[CHARS_IN_GUID];
2220 WCHAR auto_treat_as[CHARS_IN_GUID];
2221 LONG auto_treat_as_size = sizeof(auto_treat_as);
2224 if (ERROR_SUCCESS != COM_OpenKeyForCLSID(clsidOld, KEY_READ | KEY_WRITE, &hkey))
2226 res = REGDB_E_CLASSNOTREG;
2229 if (!memcmp( clsidOld, clsidNew, sizeof(*clsidOld) ))
2231 if (!RegQueryValueW(hkey, wszAutoTreatAs, auto_treat_as, &auto_treat_as_size) &&
2232 !CLSIDFromString(auto_treat_as, &id))
2234 if (RegSetValueW(hkey, wszTreatAs, REG_SZ, auto_treat_as, sizeof(auto_treat_as)))
2236 res = REGDB_E_WRITEREGDB;
2242 RegDeleteKeyW(hkey, wszTreatAs);
2246 else if (!StringFromGUID2(clsidNew, szClsidNew, ARRAYSIZE(szClsidNew)) &&
2247 !RegSetValueW(hkey, wszTreatAs, REG_SZ, szClsidNew, sizeof(szClsidNew)))
2249 res = REGDB_E_WRITEREGDB;
2254 if (hkey) RegCloseKey(hkey);
2258 /******************************************************************************
2259 * CoGetTreatAsClass [OLE32.@]
2261 * Gets the TreatAs value of a class.
2264 * clsidOld [I] Class to get the TreatAs value of.
2265 * clsidNew [I] The class the clsidOld should be treated as.
2269 * Failure: HRESULT code.
2274 HRESULT WINAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID clsidNew)
2276 static const WCHAR wszTreatAs[] = {'T','r','e','a','t','A','s',0};
2278 WCHAR szClsidNew[CHARS_IN_GUID];
2280 LONG len = sizeof(szClsidNew);
2282 FIXME("(%s,%p)\n", debugstr_guid(clsidOld), clsidNew);
2283 memcpy(clsidNew,clsidOld,sizeof(CLSID)); /* copy over old value */
2285 if (COM_OpenKeyForCLSID(clsidOld, KEY_READ, &hkey))
2287 res = REGDB_E_CLASSNOTREG;
2290 if (RegQueryValueW(hkey, wszTreatAs, szClsidNew, &len))
2295 res = CLSIDFromString(szClsidNew,clsidNew);
2297 ERR("Failed CLSIDFromStringA(%s), hres 0x%08lx\n", debugstr_w(szClsidNew), res);
2299 if (hkey) RegCloseKey(hkey);
2303 /******************************************************************************
2304 * CoGetCurrentProcess [OLE32.@]
2305 * CoGetCurrentProcess [COMPOBJ.34]
2307 * Gets the current process ID.
2310 * The current process ID.
2313 * Is DWORD really the correct return type for this function?
2315 DWORD WINAPI CoGetCurrentProcess(void)
2317 return GetCurrentProcessId();
2320 /******************************************************************************
2321 * CoRegisterMessageFilter [OLE32.@]
2323 * Registers a message filter.
2326 * lpMessageFilter [I] Pointer to interface.
2327 * lplpMessageFilter [O] Indirect pointer to prior instance if non-NULL.
2331 * Failure: HRESULT code.
2333 HRESULT WINAPI CoRegisterMessageFilter(
2334 LPMESSAGEFILTER lpMessageFilter,
2335 LPMESSAGEFILTER *lplpMessageFilter)
2338 if (lplpMessageFilter) {
2339 *lplpMessageFilter = NULL;
2344 /***********************************************************************
2345 * CoIsOle1Class [OLE32.@]
2347 * Determines whether the specified class an OLE v1 class.
2350 * clsid [I] Class to test.
2353 * TRUE if the class is an OLE v1 class, or FALSE otherwise.
2355 BOOL WINAPI CoIsOle1Class(REFCLSID clsid)
2357 FIXME("%s\n", debugstr_guid(clsid));
2361 /***********************************************************************
2362 * IsEqualGUID [OLE32.@]
2364 * Compares two Unique Identifiers.
2367 * rguid1 [I] The first GUID to compare.
2368 * rguid2 [I] The other GUID to compare.
2374 BOOL WINAPI IsEqualGUID(
2378 return !memcmp(rguid1,rguid2,sizeof(GUID));
2381 /***********************************************************************
2382 * CoInitializeSecurity [OLE32.@]
2384 HRESULT WINAPI CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc,
2385 SOLE_AUTHENTICATION_SERVICE* asAuthSvc,
2386 void* pReserved1, DWORD dwAuthnLevel,
2387 DWORD dwImpLevel, void* pReserved2,
2388 DWORD dwCapabilities, void* pReserved3)
2390 FIXME("(%p,%ld,%p,%p,%ld,%ld,%p,%ld,%p) - stub!\n", pSecDesc, cAuthSvc,
2391 asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pReserved2,
2392 dwCapabilities, pReserved3);
2396 /***********************************************************************
2397 * CoSuspendClassObjects [OLE32.@]
2399 * Suspends all registered class objects to prevent further requests coming in
2400 * for those objects.
2404 * Failure: HRESULT code.
2406 HRESULT WINAPI CoSuspendClassObjects(void)
2412 /***********************************************************************
2413 * CoAddRefServerProcess [OLE32.@]
2415 * Helper function for incrementing the reference count of a local-server
2419 * New reference count.
2421 ULONG WINAPI CoAddRefServerProcess(void)
2427 /***********************************************************************
2428 * CoReleaseServerProcess [OLE32.@]
2430 * Helper function for decrementing the reference count of a local-server
2434 * New reference count.
2436 ULONG WINAPI CoReleaseServerProcess(void)
2442 /***********************************************************************
2443 * CoIsHandlerConnected [OLE32.@]
2445 * Determines whether a proxy is connected to a remote stub.
2448 * pUnk [I] Pointer to object that may or may not be connected.
2451 * TRUE if pUnk is not a proxy or if pUnk is connected to a remote stub, or
2454 BOOL WINAPI CoIsHandlerConnected(IUnknown *pUnk)
2456 FIXME("%p\n", pUnk);
2461 /***********************************************************************
2462 * CoQueryProxyBlanket [OLE32.@]
2464 * Retrieves the security settings being used by a proxy.
2467 * pProxy [I] Pointer to the proxy object.
2468 * pAuthnSvc [O] The type of authentication service.
2469 * pAuthzSvc [O] The type of authorization service.
2470 * ppServerPrincName [O] Optional. The server prinicple name.
2471 * pAuthnLevel [O] The authentication level.
2472 * pImpLevel [O] The impersonation level.
2473 * ppAuthInfo [O] Information specific to the authorization/authentication service.
2474 * pCapabilities [O] Flags affecting the security behaviour.
2478 * Failure: HRESULT code.
2481 * CoCopyProxy, CoSetProxyBlanket.
2483 HRESULT WINAPI CoQueryProxyBlanket(IUnknown *pProxy, DWORD *pAuthnSvc,
2484 DWORD *pAuthzSvc, OLECHAR **ppServerPrincName, DWORD *pAuthnLevel,
2485 DWORD *pImpLevel, void **ppAuthInfo, DWORD *pCapabilities)
2487 IClientSecurity *pCliSec;
2490 TRACE("%p\n", pProxy);
2492 hr = IUnknown_QueryInterface(pProxy, &IID_IClientSecurity, (void **)&pCliSec);
2495 hr = IClientSecurity_QueryBlanket(pCliSec, pProxy, pAuthnSvc,
2496 pAuthzSvc, ppServerPrincName,
2497 pAuthnLevel, pImpLevel, ppAuthInfo,
2499 IClientSecurity_Release(pCliSec);
2502 if (FAILED(hr)) ERR("-- failed with 0x%08lx\n", hr);
2506 /***********************************************************************
2507 * CoSetProxyBlanket [OLE32.@]
2509 * Sets the security settings for a proxy.
2512 * pProxy [I] Pointer to the proxy object.
2513 * AuthnSvc [I] The type of authentication service.
2514 * AuthzSvc [I] The type of authorization service.
2515 * pServerPrincName [I] The server prinicple name.
2516 * AuthnLevel [I] The authentication level.
2517 * ImpLevel [I] The impersonation level.
2518 * pAuthInfo [I] Information specific to the authorization/authentication service.
2519 * Capabilities [I] Flags affecting the security behaviour.
2523 * Failure: HRESULT code.
2526 * CoQueryProxyBlanket, CoCopyProxy.
2528 HRESULT WINAPI CoSetProxyBlanket(IUnknown *pProxy, DWORD AuthnSvc,
2529 DWORD AuthzSvc, OLECHAR *pServerPrincName, DWORD AuthnLevel,
2530 DWORD ImpLevel, void *pAuthInfo, DWORD Capabilities)
2532 IClientSecurity *pCliSec;
2535 TRACE("%p\n", pProxy);
2537 hr = IUnknown_QueryInterface(pProxy, &IID_IClientSecurity, (void **)&pCliSec);
2540 hr = IClientSecurity_SetBlanket(pCliSec, pProxy, AuthnSvc,
2541 AuthzSvc, pServerPrincName,
2542 AuthnLevel, ImpLevel, pAuthInfo,
2544 IClientSecurity_Release(pCliSec);
2547 if (FAILED(hr)) ERR("-- failed with 0x%08lx\n", hr);
2551 /***********************************************************************
2552 * CoCopyProxy [OLE32.@]
2557 * pProxy [I] Pointer to the proxy object.
2558 * ppCopy [O] Copy of the proxy.
2562 * Failure: HRESULT code.
2565 * CoQueryProxyBlanket, CoSetProxyBlanket.
2567 HRESULT WINAPI CoCopyProxy(IUnknown *pProxy, IUnknown **ppCopy)
2569 IClientSecurity *pCliSec;
2572 TRACE("%p\n", pProxy);
2574 hr = IUnknown_QueryInterface(pProxy, &IID_IClientSecurity, (void **)&pCliSec);
2577 hr = IClientSecurity_CopyProxy(pCliSec, pProxy, ppCopy);
2578 IClientSecurity_Release(pCliSec);
2581 if (FAILED(hr)) ERR("-- failed with 0x%08lx\n", hr);
2586 /***********************************************************************
2587 * CoWaitForMultipleHandles [OLE32.@]
2589 * Waits for one or more handles to become signaled.
2592 * dwFlags [I] Flags. See notes.
2593 * dwTimeout [I] Timeout in milliseconds.
2594 * cHandles [I] Number of handles pointed to by pHandles.
2595 * pHandles [I] Handles to wait for.
2596 * lpdwindex [O] Index of handle that was signaled.
2600 * Failure: RPC_S_CALLPENDING on timeout.
2604 * The dwFlags parameter can be zero or more of the following:
2605 *| COWAIT_WAITALL - Wait for all of the handles to become signaled.
2606 *| COWAIT_ALERTABLE - Allows a queued APC to run during the wait.
2609 * MsgWaitForMultipleObjects, WaitForMultipleObjects.
2611 HRESULT WINAPI CoWaitForMultipleHandles(DWORD dwFlags, DWORD dwTimeout,
2612 ULONG cHandles, const HANDLE* pHandles, LPDWORD lpdwindex)
2615 DWORD wait_flags = (dwFlags & COWAIT_WAITALL) ? MWMO_WAITALL : 0 |
2616 (dwFlags & COWAIT_ALERTABLE ) ? MWMO_ALERTABLE : 0;
2617 DWORD start_time = GetTickCount();
2619 TRACE("(0x%08lx, 0x%08lx, %ld, %p, %p)\n", dwFlags, dwTimeout, cHandles,
2620 pHandles, lpdwindex);
2624 DWORD now = GetTickCount();
2627 if ((dwTimeout != INFINITE) && (start_time + dwTimeout >= now))
2629 hr = RPC_S_CALLPENDING;
2633 TRACE("waiting for rpc completion or window message\n");
2635 res = MsgWaitForMultipleObjectsEx(cHandles, pHandles,
2636 (dwTimeout == INFINITE) ? INFINITE : start_time + dwTimeout - now,
2637 QS_ALLINPUT, wait_flags);
2639 if (res == WAIT_OBJECT_0 + cHandles) /* messages available */
2642 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
2644 /* FIXME: filter the messages here */
2645 TRACE("received message whilst waiting for RPC: 0x%04x\n", msg.message);
2646 TranslateMessage(&msg);
2647 DispatchMessageW(&msg);
2650 else if ((res >= WAIT_OBJECT_0) && (res < WAIT_OBJECT_0 + cHandles))
2652 /* handle signaled, store index */
2653 *lpdwindex = (res - WAIT_OBJECT_0);
2656 else if (res == WAIT_TIMEOUT)
2658 hr = RPC_S_CALLPENDING;
2663 ERR("Unexpected wait termination: %ld, %ld\n", res, GetLastError());
2668 TRACE("-- 0x%08lx\n", hr);
2672 /***********************************************************************
2675 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
2677 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
2680 case DLL_PROCESS_ATTACH:
2681 OLE32_hInstance = hinstDLL;
2682 COMPOBJ_InitProcess();
2683 if (TRACE_ON(ole)) CoRegisterMallocSpy((LPVOID)-1);
2686 case DLL_PROCESS_DETACH:
2687 if (TRACE_ON(ole)) CoRevokeMallocSpy();
2688 COMPOBJ_UninitProcess();
2689 OLE32_hInstance = 0;
2692 case DLL_THREAD_DETACH:
2699 /* NOTE: DllRegisterServer and DllUnregisterServer are in regsvr.c */