4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
28 #include "wine/obj_base.h"
29 #include "wine/obj_clientserver.h"
30 #include "wine/obj_misc.h"
31 #include "wine/obj_marshal.h"
32 #include "wine/obj_storage.h"
33 #include "wine/winbase16.h"
34 #include "compobj_private.h"
38 #include "debugtools.h"
40 DEFAULT_DEBUG_CHANNEL(ole);
42 /****************************************************************************
43 * COM External Lock structures and methods declaration
45 * This api provides a linked list to managed external references to
48 * The public interface consists of three calls:
49 * COM_ExternalLockAddRef
50 * COM_ExternalLockRelease
51 * COM_ExternalLockFreeList
54 #define EL_END_OF_LIST 0
55 #define EL_NOT_FOUND 0
58 * Declaration of the static structure that manage the
59 * external lock to COM objects.
61 typedef struct COM_ExternalLock COM_ExternalLock;
62 typedef struct COM_ExternalLockList COM_ExternalLockList;
64 struct COM_ExternalLock
66 IUnknown *pUnk; /* IUnknown referenced */
67 ULONG uRefCount; /* external lock counter to IUnknown object*/
68 COM_ExternalLock *next; /* Pointer to next element in list */
71 struct COM_ExternalLockList
73 COM_ExternalLock *head; /* head of list */
77 * Declaration and initialization of the static structure that manages
78 * the external lock to COM objects.
80 static COM_ExternalLockList elList = { EL_END_OF_LIST };
83 * Public Interface to the external lock list
85 static void COM_ExternalLockFreeList();
86 static void COM_ExternalLockAddRef(IUnknown *pUnk);
87 static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
88 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
91 * Private methods used to managed the linked list
93 static BOOL COM_ExternalLockInsert(
96 static void COM_ExternalLockDelete(
97 COM_ExternalLock *element);
99 static COM_ExternalLock* COM_ExternalLockFind(
102 static COM_ExternalLock* COM_ExternalLockLocate(
103 COM_ExternalLock *element,
106 /****************************************************************************
107 * This section defines variables internal to the COM module.
109 * TODO: Most of these things will have to be made thread-safe.
111 HINSTANCE16 COMPOBJ_hInstance = 0;
112 HINSTANCE COMPOBJ_hInstance32 = 0;
113 static int COMPOBJ_Attach = 0;
115 LPMALLOC16 currentMalloc16=NULL;
116 LPMALLOC currentMalloc32=NULL;
119 WORD Table_ETask[62];
122 * This lock count counts the number of times CoInitialize is called. It is
123 * decreased every time CoUninitialize is called. When it hits 0, the COM
124 * libraries are freed
126 static LONG s_COMLockCount = 0;
129 * This linked list contains the list of registered class objects. These
130 * are mostly used to register the factories for out-of-proc servers of OLE
133 * TODO: Make this data structure aware of inter-process communication. This
134 * means that parts of this will be exported to the Wine Server.
136 typedef struct tagRegisteredClass
138 CLSID classIdentifier;
139 LPUNKNOWN classObject;
143 struct tagRegisteredClass* nextClass;
146 static CRITICAL_SECTION csRegisteredClassList;
147 static RegisteredClass* firstRegisteredClass = NULL;
149 /* this open DLL table belongs in a per process table, but my guess is that
150 * it shouldn't live in the kernel, so I'll put them out here in DLL
151 * space assuming that there is one OLE32 per process.
153 typedef struct tagOpenDll {
155 struct tagOpenDll *next;
158 static CRITICAL_SECTION csOpenDllList;
159 static OpenDll *openDllList = NULL; /* linked list of open dlls */
161 /*****************************************************************************
162 * This section contains prototypes to internal methods for this
165 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
169 static void COM_RevokeAllClasses();
172 /******************************************************************************
173 * Initialize/Uninitialize critical sections.
175 void COMPOBJ_InitProcess( void )
177 InitializeCriticalSection( &csRegisteredClassList );
178 InitializeCriticalSection( &csOpenDllList );
181 void COMPOBJ_UninitProcess( void )
183 DeleteCriticalSection( &csRegisteredClassList );
184 DeleteCriticalSection( &csOpenDllList );
187 /******************************************************************************
188 * CoBuildVersion [COMPOBJ.1]
189 * CoBuildVersion [OLE32.4]
192 * Current build version, hiword is majornumber, loword is minornumber
194 DWORD WINAPI CoBuildVersion(void)
196 TRACE("Returning version %d, build %d.\n", rmm, rup);
197 return (rmm<<16)+rup;
200 /******************************************************************************
201 * CoInitialize [COMPOBJ.2]
202 * Set the win16 IMalloc used for memory management
204 HRESULT WINAPI CoInitialize16(
205 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
207 currentMalloc16 = (LPMALLOC16)lpReserved;
211 /******************************************************************************
212 * CoInitialize [OLE32.26]
214 * Initializes the COM libraries.
218 HRESULT WINAPI CoInitialize(
219 LPVOID lpReserved /* [in] pointer to win32 malloc interface
220 (obsolete, should be NULL) */
224 * Just delegate to the newer method.
226 return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
229 /******************************************************************************
230 * CoInitializeEx [OLE32.163]
232 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
233 * used for memory management is obsolete.
236 * S_OK if successful,
237 * S_FALSE if this function was called already.
238 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
242 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
245 * See the windows documentation for more details.
247 HRESULT WINAPI CoInitializeEx(
248 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
249 (obsolete, should be NULL) */
250 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
255 TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
257 if (lpReserved!=NULL)
259 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
263 * Check for unsupported features.
265 if (dwCoInit!=COINIT_APARTMENTTHREADED)
267 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
268 /* Hope for the best and continue anyway */
272 * Check the lock count. If this is the first time going through the initialize
273 * process, we have to initialize the libraries.
275 * And crank-up that lock count.
277 if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
280 * Initialize the various COM libraries and data structures.
282 TRACE("() - Initializing the COM libraries\n");
285 RunningObjectTableImpl_Initialize();
295 /***********************************************************************
296 * CoUninitialize [COMPOBJ.3]
297 * Don't know what it does.
298 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
299 * believe is the correct spelling
301 void WINAPI CoUninitialize16(void)
304 CoFreeAllLibraries();
307 /***********************************************************************
308 * CoUninitialize [OLE32.47]
310 * This method will release the COM libraries.
312 * See the windows documentation for more details.
314 void WINAPI CoUninitialize(void)
320 * Decrease the reference count.
321 * If we are back to 0 locks on the COM library, make sure we free
322 * all the associated data structures.
324 lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
328 * Release the various COM libraries and data structures.
330 TRACE("() - Releasing the COM libraries\n");
332 RunningObjectTableImpl_UnInitialize();
334 * Release the references to the registered class objects.
336 COM_RevokeAllClasses();
339 * This will free the loaded COM Dlls.
341 CoFreeAllLibraries();
344 * This will free list of external references to COM objects.
346 COM_ExternalLockFreeList();
349 else if (lCOMRefCnt<1) {
350 ERR( "CoUninitialize() - not CoInitialized.\n" );
351 InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
355 /***********************************************************************
356 * CoGetMalloc [COMPOBJ.4]
358 * The current win16 IMalloc
360 HRESULT WINAPI CoGetMalloc16(
361 DWORD dwMemContext, /* [in] unknown */
362 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
365 currentMalloc16 = IMalloc16_Constructor();
366 *lpMalloc = currentMalloc16;
370 /******************************************************************************
371 * CoGetMalloc [OLE32.20]
374 * The current win32 IMalloc
376 HRESULT WINAPI CoGetMalloc(
377 DWORD dwMemContext, /* [in] unknown */
378 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
381 currentMalloc32 = IMalloc_Constructor();
382 *lpMalloc = currentMalloc32;
386 /***********************************************************************
387 * CoCreateStandardMalloc [COMPOBJ.71]
389 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
390 LPMALLOC16 *lpMalloc)
392 /* FIXME: docu says we shouldn't return the same allocator as in
394 *lpMalloc = IMalloc16_Constructor();
398 /******************************************************************************
399 * CoDisconnectObject [COMPOBJ.15]
400 * CoDisconnectObject [OLE32.8]
402 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
404 TRACE("(%p, %lx)\n",lpUnk,reserved);
408 /***********************************************************************
409 * IsEqualGUID [COMPOBJ.18]
411 * Compares two Unique Identifiers.
416 BOOL16 WINAPI IsEqualGUID16(
417 GUID* g1, /* [in] unique id 1 */
418 GUID* g2 /* [in] unique id 2 */
420 return !memcmp( g1, g2, sizeof(GUID) );
423 /******************************************************************************
424 * CLSIDFromString [COMPOBJ.20]
425 * Converts a unique identifier from its string representation into
428 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
433 HRESULT WINAPI CLSIDFromString16(
434 LPCOLESTR16 idstr, /* [in] string representation of guid */
435 CLSID *id /* [out] GUID converted from string */
437 BYTE *s = (BYTE *) idstr;
443 s = "{00000000-0000-0000-0000-000000000000}";
444 else { /* validate the CLSID string */
447 return CO_E_CLASSSTRING;
449 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
450 return CO_E_CLASSSTRING;
454 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
455 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
456 ((s[i] >= 'a') && (s[i] <= 'f')) ||
457 ((s[i] >= 'A') && (s[i] <= 'F')))
459 return CO_E_CLASSSTRING;
463 TRACE("%s -> %p\n", s, id);
465 /* quick lookup table */
466 memset(table, 0, 256);
468 for (i = 0; i < 10; i++) {
471 for (i = 0; i < 6; i++) {
472 table['A' + i] = i+10;
473 table['a' + i] = i+10;
476 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
480 s++; /* skip leading brace */
481 for (i = 0; i < 4; i++) {
482 p[3 - i] = table[*s]<<4 | table[*(s+1)];
488 for (i = 0; i < 2; i++) {
489 p[1-i] = table[*s]<<4 | table[*(s+1)];
495 for (i = 0; i < 2; i++) {
496 p[1-i] = table[*s]<<4 | table[*(s+1)];
502 /* these are just sequential bytes */
503 for (i = 0; i < 2; i++) {
504 *p++ = table[*s]<<4 | table[*(s+1)];
509 for (i = 0; i < 6; i++) {
510 *p++ = table[*s]<<4 | table[*(s+1)];
517 /******************************************************************************
518 * CoCreateGuid[OLE32.6]
521 HRESULT WINAPI CoCreateGuid(
522 GUID *pguid /* [out] points to the GUID to initialize */
524 return UuidCreate(pguid);
527 /******************************************************************************
528 * CLSIDFromString [OLE32.3]
529 * IIDFromString [OLE32.74]
530 * Converts a unique identifier from its string representation into
534 * If idstr is not a valid CLSID string then it gets treated as a ProgID
539 HRESULT WINAPI CLSIDFromString(
540 LPCOLESTR idstr, /* [in] string representation of GUID */
541 CLSID *id /* [out] GUID represented by above string */
543 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
544 HRESULT ret = CLSIDFromString16(xid,id);
546 HeapFree(GetProcessHeap(),0,xid);
547 if(ret != S_OK) { /* It appears a ProgID is also valid */
548 ret = CLSIDFromProgID(idstr, id);
553 /******************************************************************************
554 * WINE_StringFromCLSID [Internal]
555 * Converts a GUID into the respective string representation.
560 * the string representation and HRESULT
562 static HRESULT WINE_StringFromCLSID(
563 const CLSID *id, /* [in] GUID to be converted */
564 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
566 static const char *hex = "0123456789ABCDEF";
571 { ERR("called with id=Null\n");
576 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
577 id->Data1, id->Data2, id->Data3,
578 id->Data4[0], id->Data4[1]);
582 for (i = 2; i < 8; i++) {
583 *s++ = hex[id->Data4[i]>>4];
584 *s++ = hex[id->Data4[i] & 0xf];
590 TRACE("%p->%s\n", id, idstr);
595 /******************************************************************************
596 * StringFromCLSID [COMPOBJ.19]
597 * Converts a GUID into the respective string representation.
598 * The target string is allocated using the OLE IMalloc.
600 * the string representation and HRESULT
602 HRESULT WINAPI StringFromCLSID16(
603 REFCLSID id, /* [in] the GUID to be converted */
604 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
607 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
608 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
613 ret = CoGetMalloc16(0,&mllc);
616 args[0] = (DWORD)mllc;
619 /* No need for a Callback entry, we have WOWCallback16Ex which does
620 * everything we need.
622 if (!K32WOWCallback16Ex(
623 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
624 (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
631 WARN("CallTo16 IMalloc16 failed\n");
634 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
637 /******************************************************************************
638 * StringFromCLSID [OLE32.151]
639 * StringFromIID [OLE32.153]
640 * Converts a GUID into the respective string representation.
641 * The target string is allocated using the OLE IMalloc.
643 * the string representation and HRESULT
645 HRESULT WINAPI StringFromCLSID(
646 REFCLSID id, /* [in] the GUID to be converted */
647 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
653 if ((ret=CoGetMalloc(0,&mllc)))
656 ret=WINE_StringFromCLSID(id,buf);
658 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
659 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
660 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
665 /******************************************************************************
666 * StringFromGUID2 [COMPOBJ.76]
667 * StringFromGUID2 [OLE32.152]
669 * Converts a global unique identifier into a string of an API-
670 * specified fixed format. (The usual {.....} stuff.)
673 * The (UNICODE) string representation of the GUID in 'str'
674 * The length of the resulting string, 0 if there was any problem.
677 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
681 if (WINE_StringFromCLSID(id,xguid))
683 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
686 /******************************************************************************
687 * ProgIDFromCLSID [OLE32.133]
688 * Converts a class id into the respective Program ID. (By using a registry lookup)
689 * RETURNS S_OK on success
690 * riid associated with the progid
693 HRESULT WINAPI ProgIDFromCLSID(
694 REFCLSID clsid, /* [in] class id as found in registry */
695 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
698 char strCLSID[50], *buf, *buf2;
704 WINE_StringFromCLSID(clsid, strCLSID);
706 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
707 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
708 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
709 ret = REGDB_E_CLASSNOTREG;
711 HeapFree(GetProcessHeap(), 0, buf);
715 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
717 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
718 ret = REGDB_E_CLASSNOTREG;
722 if (CoGetMalloc(0,&mllc))
726 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
727 *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
728 MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
731 HeapFree(GetProcessHeap(), 0, buf2);
738 /******************************************************************************
739 * CLSIDFromProgID [COMPOBJ.61]
740 * Converts a program id into the respective GUID. (By using a registry lookup)
742 * riid associated with the progid
744 HRESULT WINAPI CLSIDFromProgID16(
745 LPCOLESTR16 progid, /* [in] program id as found in registry */
746 LPCLSID riid /* [out] associated CLSID */
753 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
754 sprintf(buf,"%s\\CLSID",progid);
755 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
756 HeapFree(GetProcessHeap(),0,buf);
757 return CO_E_CLASSSTRING;
759 HeapFree(GetProcessHeap(),0,buf);
760 buf2len = sizeof(buf2);
761 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
763 return CO_E_CLASSSTRING;
766 return CLSIDFromString16(buf2,riid);
769 /******************************************************************************
770 * CLSIDFromProgID [OLE32.2]
771 * Converts a program id into the respective GUID. (By using a registry lookup)
773 * riid associated with the progid
775 HRESULT WINAPI CLSIDFromProgID(
776 LPCOLESTR progid, /* [in] program id as found in registry */
777 LPCLSID riid /* [out] associated CLSID */
779 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
780 HRESULT ret = CLSIDFromProgID16(pid,riid);
782 HeapFree(GetProcessHeap(),0,pid);
788 /*****************************************************************************
789 * CoGetPSClsid [OLE32.22]
791 * This function returns the CLSID of the DLL that implements the proxy and stub
792 * for the specified interface.
794 * It determines this by searching the
795 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
796 * and any interface id registered by CoRegisterPSClsid within the current process.
798 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
800 HRESULT WINAPI CoGetPSClsid(
801 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
802 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
808 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
810 /* Get the input iid as a string */
811 WINE_StringFromCLSID(riid, buf2);
812 /* Allocate memory for the registry key we will construct.
813 (length of iid string plus constant length of static text */
814 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
817 return (E_OUTOFMEMORY);
820 /* Construct the registry key we want */
821 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
824 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
826 HeapFree(GetProcessHeap(),0,buf);
827 return (E_INVALIDARG);
829 HeapFree(GetProcessHeap(),0,buf);
831 /* ... Once we have the key, query the registry to get the
832 value of CLSID as a string, and convert it into a
833 proper CLSID structure to be passed back to the app */
834 buf2len = sizeof(buf2);
835 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
842 /* We have the CLSid we want back from the registry as a string, so
843 lets convert it into a CLSID structure */
844 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
849 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
855 /***********************************************************************
856 * WriteClassStm (OLE32.159)
858 * This function write a CLSID on stream
860 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
862 TRACE("(%p,%p)\n",pStm,rclsid);
867 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
870 /***********************************************************************
871 * ReadClassStm (OLE32.135)
873 * This function read a CLSID from a stream
875 HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
880 TRACE("(%p,%p)\n",pStm,pclsid);
885 res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
890 if (nbByte != sizeof(CLSID))
896 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
897 /***********************************************************************
898 * LookupETask (COMPOBJ.94)
900 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
901 FIXME("(%p,%p),stub!\n",hTask,p);
902 if ((*hTask = GetCurrentTask()) == hETask) {
903 memcpy(p, Table_ETask, sizeof(Table_ETask));
908 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
909 /***********************************************************************
910 * SetETask (COMPOBJ.95)
912 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
913 FIXME("(%04x,%p),stub!\n",hTask,p);
918 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
919 /***********************************************************************
920 * CALLOBJECTINWOW (COMPOBJ.201)
922 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
923 FIXME("(%p,%p),stub!\n",p1,p2);
927 /******************************************************************************
928 * CoRegisterClassObject [COMPOBJ.5]
930 * Don't know where it registers it ...
932 HRESULT WINAPI CoRegisterClassObject16(
935 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
936 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
941 WINE_StringFromCLSID(rclsid,buf);
943 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
944 buf,pUnk,dwClsContext,flags,lpdwRegister
950 /******************************************************************************
951 * CoRevokeClassObject [COMPOBJ.6]
954 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
956 FIXME("(0x%08lx),stub!\n", dwRegister);
960 /******************************************************************************
961 * CoFileTimeToDosDateTime [COMPOBJ.30]
963 BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
965 return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
968 /******************************************************************************
969 * CoDosDateTimeToFileTime [COMPOBJ.31]
971 BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
973 return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
977 * COM_GetRegisteredClassObject
979 * This internal method is used to scan the registered class list to
980 * find a class object.
983 * rclsid Class ID of the class to find.
984 * dwClsContext Class context to match.
985 * ppv [out] returns a pointer to the class object. Complying
986 * to normal COM usage, this method will increase the
987 * reference count on this object.
989 static HRESULT COM_GetRegisteredClassObject(
994 HRESULT hr = S_FALSE;
995 RegisteredClass* curClass;
997 EnterCriticalSection( &csRegisteredClassList );
1005 * Iterate through the whole list and try to match the class ID.
1007 curClass = firstRegisteredClass;
1009 while (curClass != 0)
1012 * Check if we have a match on the class ID.
1014 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
1017 * Since we don't do out-of process or DCOM just right away, let's ignore the
1022 * We have a match, return the pointer to the class object.
1024 *ppUnk = curClass->classObject;
1026 IUnknown_AddRef(curClass->classObject);
1033 * Step to the next class in the list.
1035 curClass = curClass->nextClass;
1039 LeaveCriticalSection( &csRegisteredClassList );
1041 * If we get to here, we haven't found our class.
1046 /******************************************************************************
1047 * CoRegisterClassObject [OLE32.36]
1049 * This method will register the class object for a given class ID.
1051 * See the Windows documentation for more details.
1053 HRESULT WINAPI CoRegisterClassObject(
1056 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
1057 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1058 LPDWORD lpdwRegister
1061 RegisteredClass* newClass;
1062 LPUNKNOWN foundObject;
1066 WINE_StringFromCLSID(rclsid,buf);
1068 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1069 buf,pUnk,dwClsContext,flags,lpdwRegister);
1072 * Perform a sanity check on the parameters
1074 if ( (lpdwRegister==0) || (pUnk==0) )
1076 return E_INVALIDARG;
1080 * Initialize the cookie (out parameter)
1085 * First, check if the class is already registered.
1086 * If it is, this should cause an error.
1088 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1093 * The COM_GetRegisteredClassObject increased the reference count on the
1094 * object so it has to be released.
1096 IUnknown_Release(foundObject);
1098 return CO_E_OBJISREG;
1102 * If it is not registered, we must create a new entry for this class and
1103 * append it to the registered class list.
1104 * We use the address of the chain node as the cookie since we are sure it's
1107 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1108 if ( newClass == NULL )
1109 return E_OUTOFMEMORY;
1111 EnterCriticalSection( &csRegisteredClassList );
1113 * Initialize the node.
1115 newClass->classIdentifier = *rclsid;
1116 newClass->runContext = dwClsContext;
1117 newClass->connectFlags = flags;
1118 newClass->dwCookie = (DWORD)newClass;
1119 newClass->nextClass = firstRegisteredClass;
1122 * Since we're making a copy of the object pointer, we have to increase its
1125 newClass->classObject = pUnk;
1126 IUnknown_AddRef(newClass->classObject);
1128 firstRegisteredClass = newClass;
1130 LeaveCriticalSection( &csRegisteredClassList );
1133 * Assign the out parameter (cookie)
1135 *lpdwRegister = newClass->dwCookie;
1138 * We're successful Yippee!
1143 /***********************************************************************
1144 * CoRevokeClassObject [OLE32.40]
1146 * This method will remove a class object from the class registry
1148 * See the Windows documentation for more details.
1150 HRESULT WINAPI CoRevokeClassObject(
1153 HRESULT hr = E_INVALIDARG;
1154 RegisteredClass** prevClassLink;
1155 RegisteredClass* curClass;
1157 TRACE("(%08lx)\n",dwRegister);
1159 EnterCriticalSection( &csRegisteredClassList );
1162 * Iterate through the whole list and try to match the cookie.
1164 curClass = firstRegisteredClass;
1165 prevClassLink = &firstRegisteredClass;
1167 while (curClass != 0)
1170 * Check if we have a match on the cookie.
1172 if (curClass->dwCookie == dwRegister)
1175 * Remove the class from the chain.
1177 *prevClassLink = curClass->nextClass;
1180 * Release the reference to the class object.
1182 IUnknown_Release(curClass->classObject);
1185 * Free the memory used by the chain node.
1187 HeapFree(GetProcessHeap(), 0, curClass);
1194 * Step to the next class in the list.
1196 prevClassLink = &(curClass->nextClass);
1197 curClass = curClass->nextClass;
1201 LeaveCriticalSection( &csRegisteredClassList );
1203 * If we get to here, we haven't found our class.
1208 /***********************************************************************
1209 * CoGetClassObject [COMPOBJ.7]
1210 * CoGetClassObject [OLE32.16]
1212 HRESULT WINAPI CoGetClassObject(
1213 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1214 REFIID iid, LPVOID *ppv
1216 LPUNKNOWN regClassObject;
1217 HRESULT hres = E_UNEXPECTED;
1219 WCHAR dllName[MAX_PATH+1];
1220 DWORD dllNameLen = sizeof(dllName);
1222 typedef HRESULT CALLBACK (*DllGetClassObjectFunc)(REFCLSID clsid,
1223 REFIID iid, LPVOID *ppv);
1224 DllGetClassObjectFunc DllGetClassObject;
1226 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1228 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1229 debugstr_guid(rclsid),
1234 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
1235 FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
1239 * First, try and see if we can't match the class ID with one of the
1240 * registered classes.
1242 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1245 * Get the required interface from the retrieved pointer.
1247 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1250 * Since QI got another reference on the pointer, we want to release the
1251 * one we already have. If QI was unsuccessful, this will release the object. This
1252 * is good since we are not returning it in the "out" parameter.
1254 IUnknown_Release(regClassObject);
1259 /* out of process and remote servers not supported yet */
1260 if ( ((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1261 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
1263 FIXME("%s %s not supported!\n",
1264 (dwClsContext&CLSCTX_LOCAL_SERVER)?"CLSCTX_LOCAL_SERVER":"",
1265 (dwClsContext&CLSCTX_REMOTE_SERVER)?"CLSCTX_REMOTE_SERVER":""
1267 return E_ACCESSDENIED;
1270 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1274 sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
1275 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
1277 if (hres != ERROR_SUCCESS) {
1278 return REGDB_E_CLASSNOTREG;
1281 memset(dllName,0,sizeof(dllName));
1282 hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
1284 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1286 TRACE("found InprocServer32 dll %s\n", debugstr_w(dllName));
1288 /* open dll, call DllGetClassObject */
1289 hLibrary = CoLoadLibrary(dllName, TRUE);
1290 if (hLibrary == 0) {
1291 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(dllName));
1292 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1294 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1295 if (!DllGetClassObject) {
1296 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1297 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllName));
1298 return E_ACCESSDENIED;
1302 * Ask the DLL for its class object. (there was a note here about class
1303 * factories but this is good.
1305 return DllGetClassObject(rclsid, iid, ppv);
1310 /***********************************************************************
1311 * CoResumeClassObjects (OLE32.173)
1313 * Resumes classobjects registered with REGCLS suspended
1315 HRESULT WINAPI CoResumeClassObjects(void)
1321 /***********************************************************************
1322 * GetClassFile (OLE32.67)
1324 * This function supplies the CLSID associated with the given filename.
1326 HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
1330 int nbElm=0,length=0,i=0;
1332 LPOLESTR *pathDec=0,absFile=0,progId=0;
1333 WCHAR extention[100]={0};
1337 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1338 if((StgIsStorageFile(filePathName))==S_OK){
1340 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1343 res=ReadClassStg(pstg,pclsid);
1345 IStorage_Release(pstg);
1349 /* if the file is not a storage object then attemps to match various bits in the file against a
1350 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1353 for(i=0;i<nFileTypes;i++)
1355 for(i=0;j<nPatternsForType;j++){
1360 pat=ReadPatternFromRegistry(i,j);
1361 hFile=CreateFileW(filePathName,,,,,,hFile);
1362 SetFilePosition(hFile,pat.offset);
1363 ReadFile(hFile,buf,pat.size,NULL,NULL);
1364 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1366 *pclsid=ReadCLSIDFromRegistry(i);
1372 /* if the obove strategies fail then search for the extension key in the registry */
1374 /* get the last element (absolute file) in the path name */
1375 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1376 absFile=pathDec[nbElm-1];
1378 /* failed if the path represente a directory and not an absolute file name*/
1379 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1380 return MK_E_INVALIDEXTENSION;
1382 /* get the extension of the file */
1383 length=lstrlenW(absFile);
1384 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1386 /* get the progId associated to the extension */
1387 progId=CoTaskMemAlloc(sizeProgId);
1389 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1391 if (res==ERROR_MORE_DATA){
1393 progId = CoTaskMemRealloc(progId,sizeProgId);
1394 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1396 if (res==ERROR_SUCCESS)
1397 /* return the clsid associated to the progId */
1398 res= CLSIDFromProgID(progId,pclsid);
1400 for(i=0; pathDec[i]!=NULL;i++)
1401 CoTaskMemFree(pathDec[i]);
1402 CoTaskMemFree(pathDec);
1404 CoTaskMemFree(progId);
1406 if (res==ERROR_SUCCESS)
1409 return MK_E_INVALIDEXTENSION;
1411 /******************************************************************************
1412 * CoRegisterMessageFilter [COMPOBJ.27]
1414 HRESULT WINAPI CoRegisterMessageFilter16(
1415 LPMESSAGEFILTER lpMessageFilter,
1416 LPMESSAGEFILTER *lplpMessageFilter
1418 FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
1422 /***********************************************************************
1423 * CoCreateInstance [COMPOBJ.13]
1424 * CoCreateInstance [OLE32.7]
1426 HRESULT WINAPI CoCreateInstance(
1428 LPUNKNOWN pUnkOuter,
1434 LPCLASSFACTORY lpclf = 0;
1443 * Initialize the "out" parameter
1448 * Get a class factory to construct the object we want.
1450 hres = CoGetClassObject(rclsid,
1457 FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
1458 debugstr_guid(rclsid),hres);
1463 * Create the object and don't forget to release the factory
1465 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1466 IClassFactory_Release(lpclf);
1468 FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
1469 debugstr_guid(iid), debugstr_guid(rclsid),hres);
1474 /***********************************************************************
1475 * CoCreateInstanceEx [OLE32.165]
1477 HRESULT WINAPI CoCreateInstanceEx(
1479 LPUNKNOWN pUnkOuter,
1481 COSERVERINFO* pServerInfo,
1485 IUnknown* pUnk = NULL;
1488 int successCount = 0;
1493 if ( (cmq==0) || (pResults==NULL))
1494 return E_INVALIDARG;
1496 if (pServerInfo!=NULL)
1497 FIXME("() non-NULL pServerInfo not supported!\n");
1500 * Initialize all the "out" parameters.
1502 for (index = 0; index < cmq; index++)
1504 pResults[index].pItf = NULL;
1505 pResults[index].hr = E_NOINTERFACE;
1509 * Get the object and get its IUnknown pointer.
1511 hr = CoCreateInstance(rclsid,
1521 * Then, query for all the interfaces requested.
1523 for (index = 0; index < cmq; index++)
1525 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1526 pResults[index].pIID,
1527 (VOID**)&(pResults[index].pItf));
1529 if (pResults[index].hr == S_OK)
1534 * Release our temporary unknown pointer.
1536 IUnknown_Release(pUnk);
1538 if (successCount == 0)
1539 return E_NOINTERFACE;
1541 if (successCount!=cmq)
1542 return CO_S_NOTALLINTERFACES;
1547 /***********************************************************************
1548 * CoFreeLibrary [OLE32.13]
1550 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1552 OpenDll *ptr, *prev;
1555 EnterCriticalSection( &csOpenDllList );
1557 /* lookup library in linked list */
1559 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1560 if (ptr->hLibrary == hLibrary) {
1567 /* shouldn't happen if user passed in a valid hLibrary */
1570 /* assert: ptr points to the library entry to free */
1572 /* free library and remove node from list */
1573 FreeLibrary(hLibrary);
1574 if (ptr == openDllList) {
1575 tmp = openDllList->next;
1576 HeapFree(GetProcessHeap(), 0, openDllList);
1580 HeapFree(GetProcessHeap(), 0, ptr);
1584 LeaveCriticalSection( &csOpenDllList );
1588 /***********************************************************************
1589 * CoFreeAllLibraries [OLE32.12]
1591 void WINAPI CoFreeAllLibraries(void)
1595 EnterCriticalSection( &csOpenDllList );
1597 for (ptr = openDllList; ptr != NULL; ) {
1599 CoFreeLibrary(ptr->hLibrary);
1603 LeaveCriticalSection( &csOpenDllList );
1608 /***********************************************************************
1609 * CoFreeUnusedLibraries [COMPOBJ.17]
1610 * CoFreeUnusedLibraries [OLE32.14]
1612 void WINAPI CoFreeUnusedLibraries(void)
1615 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1616 DllCanUnloadNowFunc DllCanUnloadNow;
1618 EnterCriticalSection( &csOpenDllList );
1620 for (ptr = openDllList; ptr != NULL; ) {
1621 DllCanUnloadNow = (DllCanUnloadNowFunc)
1622 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1624 if ( (DllCanUnloadNow != NULL) &&
1625 (DllCanUnloadNow() == S_OK) ) {
1627 CoFreeLibrary(ptr->hLibrary);
1634 LeaveCriticalSection( &csOpenDllList );
1637 /***********************************************************************
1638 * CoFileTimeNow [COMPOBJ.82]
1639 * CoFileTimeNow [OLE32.10]
1642 * the current system time in lpFileTime
1644 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1646 GetSystemTimeAsFileTime( lpFileTime );
1650 /***********************************************************************
1651 * CoTaskMemAlloc (OLE32.43)
1653 * pointer to newly allocated block
1655 LPVOID WINAPI CoTaskMemAlloc(
1656 ULONG size /* [in] size of memoryblock to be allocated */
1659 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1664 return IMalloc_Alloc(lpmalloc,size);
1666 /***********************************************************************
1667 * CoTaskMemFree (OLE32.44)
1669 VOID WINAPI CoTaskMemFree(
1670 LPVOID ptr /* [in] pointer to be freed */
1673 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1678 IMalloc_Free(lpmalloc, ptr);
1681 /***********************************************************************
1682 * CoTaskMemRealloc (OLE32.45)
1684 * pointer to newly allocated block
1686 LPVOID WINAPI CoTaskMemRealloc(
1688 ULONG size) /* [in] size of memoryblock to be allocated */
1691 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1696 return IMalloc_Realloc(lpmalloc, pvOld, size);
1699 /***********************************************************************
1700 * CoLoadLibrary (OLE32.30)
1702 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1708 TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
1710 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1715 EnterCriticalSection( &csOpenDllList );
1717 if (openDllList == NULL) {
1718 /* empty list -- add first node */
1719 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1720 openDllList->hLibrary=hLibrary;
1721 openDllList->next = NULL;
1723 /* search for this dll */
1725 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1726 if (ptr->hLibrary == hLibrary) {
1732 /* dll not found, add it */
1734 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1735 openDllList->hLibrary = hLibrary;
1736 openDllList->next = tmp;
1740 LeaveCriticalSection( &csOpenDllList );
1745 /***********************************************************************
1746 * CoInitializeWOW (OLE32.27)
1748 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1749 FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
1753 /******************************************************************************
1754 * CoLockObjectExternal [COMPOBJ.63]
1756 HRESULT WINAPI CoLockObjectExternal16(
1757 LPUNKNOWN pUnk, /* [in] object to be locked */
1758 BOOL16 fLock, /* [in] do lock */
1759 BOOL16 fLastUnlockReleases /* [in] ? */
1761 FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
1765 /******************************************************************************
1766 * CoLockObjectExternal [OLE32.31]
1768 HRESULT WINAPI CoLockObjectExternal(
1769 LPUNKNOWN pUnk, /* [in] object to be locked */
1770 BOOL fLock, /* [in] do lock */
1771 BOOL fLastUnlockReleases) /* [in] unlock all */
1777 * Increment the external lock coutner, COM_ExternalLockAddRef also
1778 * increment the object's internal lock counter.
1780 COM_ExternalLockAddRef( pUnk);
1785 * Decrement the external lock coutner, COM_ExternalLockRelease also
1786 * decrement the object's internal lock counter.
1788 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1794 /***********************************************************************
1795 * CoGetState [COMPOBJ.115]
1797 HRESULT WINAPI CoGetState16(LPDWORD state)
1799 FIXME("(%p),stub!\n", state);
1803 /***********************************************************************
1804 * CoSetState [OLE32.42]
1806 HRESULT WINAPI CoSetState(LPDWORD state)
1808 FIXME("(%p),stub!\n", state);
1809 if (state) *state = 0;
1812 /***********************************************************************
1813 * CoCreateFreeThreadedMarshaler [OLE32.5]
1815 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1817 FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
1823 /***********************************************************************
1824 * DllGetClassObject [OLE32.63]
1826 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1828 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1830 return CLASS_E_CLASSNOTAVAILABLE;
1835 * COM_RevokeAllClasses
1837 * This method is called when the COM libraries are uninitialized to
1838 * release all the references to the class objects registered with
1841 static void COM_RevokeAllClasses()
1843 EnterCriticalSection( &csRegisteredClassList );
1845 while (firstRegisteredClass!=0)
1847 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1850 LeaveCriticalSection( &csRegisteredClassList );
1853 /****************************************************************************
1854 * COM External Lock methods implementation
1857 /****************************************************************************
1858 * Public - Method that increments the count for a IUnknown* in the linked
1859 * list. The item is inserted if not already in the list.
1861 static void COM_ExternalLockAddRef(
1864 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1867 * Add an external lock to the object. If it was already externally
1868 * locked, just increase the reference count. If it was not.
1869 * add the item to the list.
1871 if ( externalLock == EL_NOT_FOUND )
1872 COM_ExternalLockInsert(pUnk);
1874 externalLock->uRefCount++;
1877 * Add an internal lock to the object
1879 IUnknown_AddRef(pUnk);
1882 /****************************************************************************
1883 * Public - Method that decrements the count for a IUnknown* in the linked
1884 * list. The item is removed from the list if its count end up at zero or if
1887 static void COM_ExternalLockRelease(
1891 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1893 if ( externalLock != EL_NOT_FOUND )
1897 externalLock->uRefCount--; /* release external locks */
1898 IUnknown_Release(pUnk); /* release local locks as well */
1900 if ( bRelAll == FALSE )
1901 break; /* perform single release */
1903 } while ( externalLock->uRefCount > 0 );
1905 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1906 COM_ExternalLockDelete(externalLock);
1909 /****************************************************************************
1910 * Public - Method that frees the content of the list.
1912 static void COM_ExternalLockFreeList()
1914 COM_ExternalLock *head;
1916 head = elList.head; /* grab it by the head */
1917 while ( head != EL_END_OF_LIST )
1919 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1921 head = elList.head; /* get the new head... */
1925 /****************************************************************************
1926 * Public - Method that dump the content of the list.
1928 void COM_ExternalLockDump()
1930 COM_ExternalLock *current = elList.head;
1932 DPRINTF("\nExternal lock list contains:\n");
1934 while ( current != EL_END_OF_LIST )
1936 DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
1938 /* Skip to the next item */
1939 current = current->next;
1944 /****************************************************************************
1945 * Internal - Find a IUnknown* in the linked list
1947 static COM_ExternalLock* COM_ExternalLockFind(
1950 return COM_ExternalLockLocate(elList.head, pUnk);
1953 /****************************************************************************
1954 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1956 static COM_ExternalLock* COM_ExternalLockLocate(
1957 COM_ExternalLock *element,
1960 if ( element == EL_END_OF_LIST )
1961 return EL_NOT_FOUND;
1963 else if ( element->pUnk == pUnk ) /* We found it */
1966 else /* Not the right guy, keep on looking */
1967 return COM_ExternalLockLocate( element->next, pUnk);
1970 /****************************************************************************
1971 * Internal - Insert a new IUnknown* to the linked list
1973 static BOOL COM_ExternalLockInsert(
1976 COM_ExternalLock *newLock = NULL;
1977 COM_ExternalLock *previousHead = NULL;
1980 * Allocate space for the new storage object
1982 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
1986 if ( elList.head == EL_END_OF_LIST )
1988 elList.head = newLock; /* The list is empty */
1993 * insert does it at the head
1995 previousHead = elList.head;
1996 elList.head = newLock;
2000 * Set new list item data member
2002 newLock->pUnk = pUnk;
2003 newLock->uRefCount = 1;
2004 newLock->next = previousHead;
2012 /****************************************************************************
2013 * Internal - Method that removes an item from the linked list.
2015 static void COM_ExternalLockDelete(
2016 COM_ExternalLock *itemList)
2018 COM_ExternalLock *current = elList.head;
2020 if ( current == itemList )
2023 * this section handles the deletion of the first node
2025 elList.head = itemList->next;
2026 HeapFree( GetProcessHeap(), 0, itemList);
2032 if ( current->next == itemList ) /* We found the item to free */
2034 current->next = itemList->next; /* readjust the list pointers */
2036 HeapFree( GetProcessHeap(), 0, itemList);
2040 /* Skip to the next item */
2041 current = current->next;
2043 } while ( current != EL_END_OF_LIST );
2047 /***********************************************************************
2048 * DllEntryPoint [COMPOBJ.116]
2050 * Initialization code for the COMPOBJ DLL
2054 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
2056 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
2060 case DLL_PROCESS_ATTACH:
2061 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
2064 case DLL_PROCESS_DETACH:
2065 if(!--COMPOBJ_Attach)
2066 COMPOBJ_hInstance = 0;
2072 /******************************************************************************
2073 * OleGetAutoConvert [OLE32.104]
2075 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2083 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2084 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2086 res = REGDB_E_CLASSNOTREG;
2090 /* we can just query for the default value of AutoConvertTo key like that,
2091 without opening the AutoConvertTo key and querying for NULL (default) */
2092 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
2094 res = REGDB_E_KEYMISSING;
2097 MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
2098 CLSIDFromString(wbuf,pClsidNew);
2100 if (hkey) RegCloseKey(hkey);
2105 /******************************************************************************
2106 * OleSetAutoConvert [OLE32.126]
2108 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2110 HKEY hkey = 0, hkeyConvert = 0;
2111 char buf[200], szClsidNew[200];
2114 TRACE("(%p,%p);\n", clsidOld, clsidNew);
2115 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2116 WINE_StringFromCLSID(clsidNew, szClsidNew);
2117 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2119 res = REGDB_E_CLASSNOTREG;
2122 if (RegCreateKeyA(hkey, "AutoConvertTo", &hkeyConvert))
2124 res = REGDB_E_WRITEREGDB;
2127 if (RegSetValueExA(hkeyConvert, NULL, 0,
2128 REG_SZ, (LPBYTE)szClsidNew, strlen(szClsidNew)+1))
2130 res = REGDB_E_WRITEREGDB;
2135 if (hkeyConvert) RegCloseKey(hkeyConvert);
2136 if (hkey) RegCloseKey(hkey);
2141 /***********************************************************************
2142 * IsEqualGUID [OLE32.76]
2144 * Compares two Unique Identifiers.
2150 BOOL WINAPI IsEqualGUID(
2151 REFGUID rguid1, /* [in] unique id 1 */
2152 REFGUID rguid2 /* [in] unique id 2 */
2155 return !memcmp(rguid1,rguid2,sizeof(GUID));