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 ULONG 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 RegisteredClass* firstRegisteredClass = NULL;
148 /* this open DLL table belongs in a per process table, but my guess is that
149 * it shouldn't live in the kernel, so I'll put them out here in DLL
150 * space assuming that there is one OLE32 per process.
152 typedef struct tagOpenDll {
154 struct tagOpenDll *next;
157 static OpenDll *openDllList = NULL; /* linked list of open dlls */
159 /*****************************************************************************
160 * This section contains prototypes to internal methods for this
163 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
167 static void COM_RevokeAllClasses();
170 /******************************************************************************
171 * CoBuildVersion [COMPOBJ.1]
172 * CoBuildVersion [OLE32.4]
175 * Current build version, hiword is majornumber, loword is minornumber
177 DWORD WINAPI CoBuildVersion(void)
179 TRACE("Returning version %d, build %d.\n", rmm, rup);
180 return (rmm<<16)+rup;
183 /******************************************************************************
184 * CoInitialize [COMPOBJ.2]
185 * Set the win16 IMalloc used for memory management
187 HRESULT WINAPI CoInitialize16(
188 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
190 currentMalloc16 = (LPMALLOC16)lpReserved;
194 /******************************************************************************
195 * CoInitialize [OLE32.26]
197 * Initializes the COM libraries.
201 HRESULT WINAPI CoInitialize(
202 LPVOID lpReserved /* [in] pointer to win32 malloc interface
203 (obsolete, should be NULL) */
207 * Just delegate to the newer method.
209 return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
212 /******************************************************************************
213 * CoInitializeEx [OLE32.163]
215 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
216 * used for memory management is obsolete.
219 * S_OK if successful,
220 * S_FALSE if this function was called already.
221 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
225 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
228 * See the windows documentation for more details.
230 HRESULT WINAPI CoInitializeEx(
231 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
232 (obsolete, should be NULL) */
233 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
238 TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
240 if (lpReserved!=NULL)
242 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
246 * Check for unsupported features.
248 if (dwCoInit!=COINIT_APARTMENTTHREADED)
250 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
251 /* Hope for the best and continue anyway */
255 * Check the lock count. If this is the first time going through the initialize
256 * process, we have to initialize the libraries.
258 if (s_COMLockCount==0)
261 * Initialize the various COM libraries and data structures.
263 TRACE("() - Initializing the COM libraries\n");
265 RunningObjectTableImpl_Initialize();
273 * Crank-up that lock count.
280 /***********************************************************************
281 * CoUninitialize [COMPOBJ.3]
282 * Don't know what it does.
283 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
284 * believe is the correct spelling
286 void WINAPI CoUninitialize16(void)
289 CoFreeAllLibraries();
292 /***********************************************************************
293 * CoUninitialize [OLE32.47]
295 * This method will release the COM libraries.
297 * See the windows documentation for more details.
299 void WINAPI CoUninitialize(void)
304 * Decrease the reference count.
309 * If we are back to 0 locks on the COM library, make sure we free
310 * all the associated data structures.
312 if (s_COMLockCount==0)
315 * Release the various COM libraries and data structures.
317 TRACE("() - Releasing the COM libraries\n");
319 RunningObjectTableImpl_UnInitialize();
321 * Release the references to the registered class objects.
323 COM_RevokeAllClasses();
326 * This will free the loaded COM Dlls.
328 CoFreeAllLibraries();
331 * This will free list of external references to COM objects.
333 COM_ExternalLockFreeList();
337 /***********************************************************************
338 * CoGetMalloc [COMPOBJ.4]
340 * The current win16 IMalloc
342 HRESULT WINAPI CoGetMalloc16(
343 DWORD dwMemContext, /* [in] unknown */
344 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
347 currentMalloc16 = IMalloc16_Constructor();
348 *lpMalloc = currentMalloc16;
352 /******************************************************************************
353 * CoGetMalloc [OLE32.20]
356 * The current win32 IMalloc
358 HRESULT WINAPI CoGetMalloc(
359 DWORD dwMemContext, /* [in] unknown */
360 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
363 currentMalloc32 = IMalloc_Constructor();
364 *lpMalloc = currentMalloc32;
368 /***********************************************************************
369 * CoCreateStandardMalloc [COMPOBJ.71]
371 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
372 LPMALLOC16 *lpMalloc)
374 /* FIXME: docu says we shouldn't return the same allocator as in
376 *lpMalloc = IMalloc16_Constructor();
380 /******************************************************************************
381 * CoDisconnectObject [COMPOBJ.15]
382 * CoDisconnectObject [OLE32.8]
384 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
386 TRACE("(%p, %lx)\n",lpUnk,reserved);
390 /***********************************************************************
391 * IsEqualGUID [COMPOBJ.18]
393 * Compares two Unique Identifiers.
398 BOOL16 WINAPI IsEqualGUID16(
399 GUID* g1, /* [in] unique id 1 */
400 GUID* g2 /* [in] unique id 2 */
402 return !memcmp( g1, g2, sizeof(GUID) );
405 /******************************************************************************
406 * CLSIDFromString [COMPOBJ.20]
407 * Converts a unique identifier from its string representation into
410 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
415 HRESULT WINAPI CLSIDFromString16(
416 LPCOLESTR16 idstr, /* [in] string representation of guid */
417 CLSID *id /* [out] GUID converted from string */
419 BYTE *s = (BYTE *) idstr;
425 s = "{00000000-0000-0000-0000-000000000000}";
426 else { /* validate the CLSID string */
429 return CO_E_CLASSSTRING;
431 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
432 return CO_E_CLASSSTRING;
436 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
437 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
438 ((s[i] >= 'a') && (s[i] <= 'f')) ||
439 ((s[i] >= 'A') && (s[i] <= 'F')))
441 return CO_E_CLASSSTRING;
445 TRACE("%s -> %p\n", s, id);
447 /* quick lookup table */
448 memset(table, 0, 256);
450 for (i = 0; i < 10; i++) {
453 for (i = 0; i < 6; i++) {
454 table['A' + i] = i+10;
455 table['a' + i] = i+10;
458 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
462 s++; /* skip leading brace */
463 for (i = 0; i < 4; i++) {
464 p[3 - i] = table[*s]<<4 | table[*(s+1)];
470 for (i = 0; i < 2; i++) {
471 p[1-i] = table[*s]<<4 | table[*(s+1)];
477 for (i = 0; i < 2; i++) {
478 p[1-i] = table[*s]<<4 | table[*(s+1)];
484 /* these are just sequential bytes */
485 for (i = 0; i < 2; i++) {
486 *p++ = table[*s]<<4 | table[*(s+1)];
491 for (i = 0; i < 6; i++) {
492 *p++ = table[*s]<<4 | table[*(s+1)];
499 /******************************************************************************
500 * CoCreateGuid[OLE32.6]
503 HRESULT WINAPI CoCreateGuid(
504 GUID *pguid /* [out] points to the GUID to initialize */
506 return UuidCreate(pguid);
509 /******************************************************************************
510 * CLSIDFromString [OLE32.3]
511 * IIDFromString [OLE32.74]
512 * Converts a unique identifier from its string representation into
516 * If idstr is not a valid CLSID string then it gets treated as a ProgID
521 HRESULT WINAPI CLSIDFromString(
522 LPCOLESTR idstr, /* [in] string representation of GUID */
523 CLSID *id /* [out] GUID represented by above string */
525 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
526 HRESULT ret = CLSIDFromString16(xid,id);
528 HeapFree(GetProcessHeap(),0,xid);
529 if(ret != S_OK) { /* It appears a ProgID is also valid */
530 ret = CLSIDFromProgID(idstr, id);
535 /******************************************************************************
536 * WINE_StringFromCLSID [Internal]
537 * Converts a GUID into the respective string representation.
542 * the string representation and HRESULT
544 static HRESULT WINE_StringFromCLSID(
545 const CLSID *id, /* [in] GUID to be converted */
546 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
548 static const char *hex = "0123456789ABCDEF";
553 { ERR("called with id=Null\n");
558 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
559 id->Data1, id->Data2, id->Data3,
560 id->Data4[0], id->Data4[1]);
564 for (i = 2; i < 8; i++) {
565 *s++ = hex[id->Data4[i]>>4];
566 *s++ = hex[id->Data4[i] & 0xf];
572 TRACE("%p->%s\n", id, idstr);
577 /******************************************************************************
578 * StringFromCLSID [COMPOBJ.19]
579 * Converts a GUID into the respective string representation.
580 * The target string is allocated using the OLE IMalloc.
582 * the string representation and HRESULT
584 HRESULT WINAPI StringFromCLSID16(
585 REFCLSID id, /* [in] the GUID to be converted */
586 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
589 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
590 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
595 ret = CoGetMalloc16(0,&mllc);
598 args[0] = (DWORD)mllc;
601 /* No need for a Callback entry, we have WOWCallback16Ex which does
602 * everything we need.
604 if (!K32WOWCallback16Ex(
605 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
606 (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
613 WARN("CallTo16 IMalloc16 failed\n");
616 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
619 /******************************************************************************
620 * StringFromCLSID [OLE32.151]
621 * StringFromIID [OLE32.153]
622 * Converts a GUID into the respective string representation.
623 * The target string is allocated using the OLE IMalloc.
625 * the string representation and HRESULT
627 HRESULT WINAPI StringFromCLSID(
628 REFCLSID id, /* [in] the GUID to be converted */
629 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
635 if ((ret=CoGetMalloc(0,&mllc)))
638 ret=WINE_StringFromCLSID(id,buf);
640 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
641 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
642 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
647 /******************************************************************************
648 * StringFromGUID2 [COMPOBJ.76]
649 * StringFromGUID2 [OLE32.152]
651 * Converts a global unique identifier into a string of an API-
652 * specified fixed format. (The usual {.....} stuff.)
655 * The (UNICODE) string representation of the GUID in 'str'
656 * The length of the resulting string, 0 if there was any problem.
659 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
663 if (WINE_StringFromCLSID(id,xguid))
665 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
668 /******************************************************************************
669 * ProgIDFromCLSID [OLE32.133]
670 * Converts a class id into the respective Program ID. (By using a registry lookup)
671 * RETURNS S_OK on success
672 * riid associated with the progid
675 HRESULT WINAPI ProgIDFromCLSID(
676 REFCLSID clsid, /* [in] class id as found in registry */
677 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
680 char strCLSID[50], *buf, *buf2;
686 WINE_StringFromCLSID(clsid, strCLSID);
688 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
689 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
690 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
691 ret = REGDB_E_CLASSNOTREG;
693 HeapFree(GetProcessHeap(), 0, buf);
697 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
699 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
700 ret = REGDB_E_CLASSNOTREG;
704 if (CoGetMalloc(0,&mllc))
708 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
709 *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
710 MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
713 HeapFree(GetProcessHeap(), 0, buf2);
720 /******************************************************************************
721 * CLSIDFromProgID [COMPOBJ.61]
722 * Converts a program id into the respective GUID. (By using a registry lookup)
724 * riid associated with the progid
726 HRESULT WINAPI CLSIDFromProgID16(
727 LPCOLESTR16 progid, /* [in] program id as found in registry */
728 LPCLSID riid /* [out] associated CLSID */
735 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
736 sprintf(buf,"%s\\CLSID",progid);
737 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
738 HeapFree(GetProcessHeap(),0,buf);
739 return CO_E_CLASSSTRING;
741 HeapFree(GetProcessHeap(),0,buf);
742 buf2len = sizeof(buf2);
743 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
745 return CO_E_CLASSSTRING;
748 return CLSIDFromString16(buf2,riid);
751 /******************************************************************************
752 * CLSIDFromProgID [OLE32.2]
753 * Converts a program id into the respective GUID. (By using a registry lookup)
755 * riid associated with the progid
757 HRESULT WINAPI CLSIDFromProgID(
758 LPCOLESTR progid, /* [in] program id as found in registry */
759 LPCLSID riid /* [out] associated CLSID */
761 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
762 HRESULT ret = CLSIDFromProgID16(pid,riid);
764 HeapFree(GetProcessHeap(),0,pid);
770 /*****************************************************************************
771 * CoGetPSClsid [OLE32.22]
773 * This function returns the CLSID of the DLL that implements the proxy and stub
774 * for the specified interface.
776 * It determines this by searching the
777 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
778 * and any interface id registered by CoRegisterPSClsid within the current process.
780 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
782 HRESULT WINAPI CoGetPSClsid(
783 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
784 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
790 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
792 /* Get the input iid as a string */
793 WINE_StringFromCLSID(riid, buf2);
794 /* Allocate memory for the registry key we will construct.
795 (length of iid string plus constant length of static text */
796 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
799 return (E_OUTOFMEMORY);
802 /* Construct the registry key we want */
803 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
806 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
808 HeapFree(GetProcessHeap(),0,buf);
809 return (E_INVALIDARG);
811 HeapFree(GetProcessHeap(),0,buf);
813 /* ... Once we have the key, query the registry to get the
814 value of CLSID as a string, and convert it into a
815 proper CLSID structure to be passed back to the app */
816 buf2len = sizeof(buf2);
817 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
824 /* We have the CLSid we want back from the registry as a string, so
825 lets convert it into a CLSID structure */
826 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
831 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
837 /***********************************************************************
838 * WriteClassStm (OLE32.159)
840 * This function write a CLSID on stream
842 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
844 TRACE("(%p,%p)\n",pStm,rclsid);
849 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
852 /***********************************************************************
853 * ReadClassStm (OLE32.135)
855 * This function read a CLSID from a stream
857 HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
862 TRACE("(%p,%p)\n",pStm,pclsid);
867 res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
872 if (nbByte != sizeof(CLSID))
878 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
879 /***********************************************************************
880 * LookupETask (COMPOBJ.94)
882 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
883 FIXME("(%p,%p),stub!\n",hTask,p);
884 if ((*hTask = GetCurrentTask()) == hETask) {
885 memcpy(p, Table_ETask, sizeof(Table_ETask));
890 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
891 /***********************************************************************
892 * SetETask (COMPOBJ.95)
894 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
895 FIXME("(%04x,%p),stub!\n",hTask,p);
900 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
901 /***********************************************************************
902 * CALLOBJECTINWOW (COMPOBJ.201)
904 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
905 FIXME("(%p,%p),stub!\n",p1,p2);
909 /******************************************************************************
910 * CoRegisterClassObject [COMPOBJ.5]
912 * Don't know where it registers it ...
914 HRESULT WINAPI CoRegisterClassObject16(
917 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
918 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
923 WINE_StringFromCLSID(rclsid,buf);
925 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
926 buf,pUnk,dwClsContext,flags,lpdwRegister
932 /******************************************************************************
933 * CoRevokeClassObject [COMPOBJ.6]
936 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
938 FIXME("(0x%08lx),stub!\n", dwRegister);
942 /******************************************************************************
943 * CoFileTimeToDosDateTime [COMPOBJ.30]
945 BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
947 return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
950 /******************************************************************************
951 * CoDosDateTimeToFileTime [COMPOBJ.31]
953 BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
955 return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
959 * COM_GetRegisteredClassObject
961 * This internal method is used to scan the registered class list to
962 * find a class object.
965 * rclsid Class ID of the class to find.
966 * dwClsContext Class context to match.
967 * ppv [out] returns a pointer to the class object. Complying
968 * to normal COM usage, this method will increase the
969 * reference count on this object.
971 static HRESULT COM_GetRegisteredClassObject(
976 RegisteredClass* curClass;
984 * Iterate through the whole list and try to match the class ID.
986 curClass = firstRegisteredClass;
988 while (curClass != 0)
991 * Check if we have a match on the class ID.
993 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
996 * Since we don't do out-of process or DCOM just right away, let's ignore the
1001 * We have a match, return the pointer to the class object.
1003 *ppUnk = curClass->classObject;
1005 IUnknown_AddRef(curClass->classObject);
1011 * Step to the next class in the list.
1013 curClass = curClass->nextClass;
1017 * If we get to here, we haven't found our class.
1022 /******************************************************************************
1023 * CoRegisterClassObject [OLE32.36]
1025 * This method will register the class object for a given class ID.
1027 * See the Windows documentation for more details.
1029 HRESULT WINAPI CoRegisterClassObject(
1032 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
1033 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1034 LPDWORD lpdwRegister
1037 RegisteredClass* newClass;
1038 LPUNKNOWN foundObject;
1042 WINE_StringFromCLSID(rclsid,buf);
1044 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1045 buf,pUnk,dwClsContext,flags,lpdwRegister);
1048 * Perform a sanity check on the parameters
1050 if ( (lpdwRegister==0) || (pUnk==0) )
1052 return E_INVALIDARG;
1056 * Initialize the cookie (out parameter)
1061 * First, check if the class is already registered.
1062 * If it is, this should cause an error.
1064 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1069 * The COM_GetRegisteredClassObject increased the reference count on the
1070 * object so it has to be released.
1072 IUnknown_Release(foundObject);
1074 return CO_E_OBJISREG;
1078 * If it is not registered, we must create a new entry for this class and
1079 * append it to the registered class list.
1080 * We use the address of the chain node as the cookie since we are sure it's
1083 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1086 * Initialize the node.
1088 newClass->classIdentifier = *rclsid;
1089 newClass->runContext = dwClsContext;
1090 newClass->connectFlags = flags;
1091 newClass->dwCookie = (DWORD)newClass;
1092 newClass->nextClass = firstRegisteredClass;
1095 * Since we're making a copy of the object pointer, we have to increase its
1098 newClass->classObject = pUnk;
1099 IUnknown_AddRef(newClass->classObject);
1101 firstRegisteredClass = newClass;
1104 * Assign the out parameter (cookie)
1106 *lpdwRegister = newClass->dwCookie;
1109 * We're successful Yippee!
1114 /***********************************************************************
1115 * CoRevokeClassObject [OLE32.40]
1117 * This method will remove a class object from the class registry
1119 * See the Windows documentation for more details.
1121 HRESULT WINAPI CoRevokeClassObject(
1124 RegisteredClass** prevClassLink;
1125 RegisteredClass* curClass;
1127 TRACE("(%08lx)\n",dwRegister);
1130 * Iterate through the whole list and try to match the cookie.
1132 curClass = firstRegisteredClass;
1133 prevClassLink = &firstRegisteredClass;
1135 while (curClass != 0)
1138 * Check if we have a match on the cookie.
1140 if (curClass->dwCookie == dwRegister)
1143 * Remove the class from the chain.
1145 *prevClassLink = curClass->nextClass;
1148 * Release the reference to the class object.
1150 IUnknown_Release(curClass->classObject);
1153 * Free the memory used by the chain node.
1155 HeapFree(GetProcessHeap(), 0, curClass);
1161 * Step to the next class in the list.
1163 prevClassLink = &(curClass->nextClass);
1164 curClass = curClass->nextClass;
1168 * If we get to here, we haven't found our class.
1170 return E_INVALIDARG;
1173 /***********************************************************************
1174 * CoGetClassObject [COMPOBJ.7]
1175 * CoGetClassObject [OLE32.16]
1177 HRESULT WINAPI CoGetClassObject(
1178 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1179 REFIID iid, LPVOID *ppv
1181 LPUNKNOWN regClassObject;
1182 HRESULT hres = E_UNEXPECTED;
1184 WCHAR dllName[MAX_PATH+1];
1185 DWORD dllNameLen = sizeof(dllName);
1187 typedef HRESULT CALLBACK (*DllGetClassObjectFunc)(REFCLSID clsid,
1188 REFIID iid, LPVOID *ppv);
1189 DllGetClassObjectFunc DllGetClassObject;
1191 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1193 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1194 debugstr_guid(rclsid),
1199 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
1200 FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
1204 * First, try and see if we can't match the class ID with one of the
1205 * registered classes.
1207 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1210 * Get the required interface from the retrieved pointer.
1212 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1215 * Since QI got another reference on the pointer, we want to release the
1216 * one we already have. If QI was unsuccessful, this will release the object. This
1217 * is good since we are not returning it in the "out" parameter.
1219 IUnknown_Release(regClassObject);
1224 /* out of process and remote servers not supported yet */
1225 if ( ((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1226 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
1228 FIXME("%s %s not supported!\n",
1229 (dwClsContext&CLSCTX_LOCAL_SERVER)?"CLSCTX_LOCAL_SERVER":"",
1230 (dwClsContext&CLSCTX_REMOTE_SERVER)?"CLSCTX_REMOTE_SERVER":""
1232 return E_ACCESSDENIED;
1235 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1239 sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
1240 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
1242 if (hres != ERROR_SUCCESS) {
1243 return REGDB_E_CLASSNOTREG;
1246 memset(dllName,0,sizeof(dllName));
1247 hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
1249 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1251 TRACE("found InprocServer32 dll %s\n", debugstr_w(dllName));
1253 /* open dll, call DllGetClassObject */
1254 hLibrary = CoLoadLibrary(dllName, TRUE);
1255 if (hLibrary == 0) {
1256 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(dllName));
1257 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1259 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1260 if (!DllGetClassObject) {
1261 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1262 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllName));
1263 return E_ACCESSDENIED;
1267 * Ask the DLL for its class object. (there was a note here about class
1268 * factories but this is good.
1270 return DllGetClassObject(rclsid, iid, ppv);
1275 /***********************************************************************
1276 * CoResumeClassObjects (OLE32.173)
1278 * Resumes classobjects registered with REGCLS suspended
1280 HRESULT WINAPI CoResumeClassObjects(void)
1286 /***********************************************************************
1287 * GetClassFile (OLE32.67)
1289 * This function supplies the CLSID associated with the given filename.
1291 HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
1295 int nbElm=0,length=0,i=0;
1297 LPOLESTR *pathDec=0,absFile=0,progId=0;
1298 WCHAR extention[100]={0};
1302 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1303 if((StgIsStorageFile(filePathName))==S_OK){
1305 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1308 res=ReadClassStg(pstg,pclsid);
1310 IStorage_Release(pstg);
1314 /* if the file is not a storage object then attemps to match various bits in the file against a
1315 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1318 for(i=0;i<nFileTypes;i++)
1320 for(i=0;j<nPatternsForType;j++){
1325 pat=ReadPatternFromRegistry(i,j);
1326 hFile=CreateFileW(filePathName,,,,,,hFile);
1327 SetFilePosition(hFile,pat.offset);
1328 ReadFile(hFile,buf,pat.size,NULL,NULL);
1329 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1331 *pclsid=ReadCLSIDFromRegistry(i);
1337 /* if the obove strategies fail then search for the extension key in the registry */
1339 /* get the last element (absolute file) in the path name */
1340 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1341 absFile=pathDec[nbElm-1];
1343 /* failed if the path represente a directory and not an absolute file name*/
1344 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1345 return MK_E_INVALIDEXTENSION;
1347 /* get the extension of the file */
1348 length=lstrlenW(absFile);
1349 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1351 /* get the progId associated to the extension */
1352 progId=CoTaskMemAlloc(sizeProgId);
1354 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1356 if (res==ERROR_MORE_DATA){
1358 progId = CoTaskMemRealloc(progId,sizeProgId);
1359 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1361 if (res==ERROR_SUCCESS)
1362 /* return the clsid associated to the progId */
1363 res= CLSIDFromProgID(progId,pclsid);
1365 for(i=0; pathDec[i]!=NULL;i++)
1366 CoTaskMemFree(pathDec[i]);
1367 CoTaskMemFree(pathDec);
1369 CoTaskMemFree(progId);
1371 if (res==ERROR_SUCCESS)
1374 return MK_E_INVALIDEXTENSION;
1376 /******************************************************************************
1377 * CoRegisterMessageFilter [COMPOBJ.27]
1379 HRESULT WINAPI CoRegisterMessageFilter16(
1380 LPMESSAGEFILTER lpMessageFilter,
1381 LPMESSAGEFILTER *lplpMessageFilter
1383 FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
1387 /***********************************************************************
1388 * CoCreateInstance [COMPOBJ.13]
1389 * CoCreateInstance [OLE32.7]
1391 HRESULT WINAPI CoCreateInstance(
1393 LPUNKNOWN pUnkOuter,
1399 LPCLASSFACTORY lpclf = 0;
1408 * Initialize the "out" parameter
1413 * Get a class factory to construct the object we want.
1415 hres = CoGetClassObject(rclsid,
1422 FIXME("no instance created for %s, hres is 0x%08lx\n",debugstr_guid(iid),hres);
1427 * Create the object and don't forget to release the factory
1429 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1430 IClassFactory_Release(lpclf);
1435 /***********************************************************************
1436 * CoCreateInstanceEx [OLE32.165]
1438 HRESULT WINAPI CoCreateInstanceEx(
1440 LPUNKNOWN pUnkOuter,
1442 COSERVERINFO* pServerInfo,
1446 IUnknown* pUnk = NULL;
1449 int successCount = 0;
1454 if ( (cmq==0) || (pResults==NULL))
1455 return E_INVALIDARG;
1457 if (pServerInfo!=NULL)
1458 FIXME("() non-NULL pServerInfo not supported!\n");
1461 * Initialize all the "out" parameters.
1463 for (index = 0; index < cmq; index++)
1465 pResults[index].pItf = NULL;
1466 pResults[index].hr = E_NOINTERFACE;
1470 * Get the object and get its IUnknown pointer.
1472 hr = CoCreateInstance(rclsid,
1482 * Then, query for all the interfaces requested.
1484 for (index = 0; index < cmq; index++)
1486 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1487 pResults[index].pIID,
1488 (VOID**)&(pResults[index].pItf));
1490 if (pResults[index].hr == S_OK)
1495 * Release our temporary unknown pointer.
1497 IUnknown_Release(pUnk);
1499 if (successCount == 0)
1500 return E_NOINTERFACE;
1502 if (successCount!=cmq)
1503 return CO_S_NOTALLINTERFACES;
1508 /***********************************************************************
1509 * CoFreeLibrary [OLE32.13]
1511 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1513 OpenDll *ptr, *prev;
1516 /* lookup library in linked list */
1518 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1519 if (ptr->hLibrary == hLibrary) {
1526 /* shouldn't happen if user passed in a valid hLibrary */
1529 /* assert: ptr points to the library entry to free */
1531 /* free library and remove node from list */
1532 FreeLibrary(hLibrary);
1533 if (ptr == openDllList) {
1534 tmp = openDllList->next;
1535 HeapFree(GetProcessHeap(), 0, openDllList);
1539 HeapFree(GetProcessHeap(), 0, ptr);
1546 /***********************************************************************
1547 * CoFreeAllLibraries [OLE32.12]
1549 void WINAPI CoFreeAllLibraries(void)
1553 for (ptr = openDllList; ptr != NULL; ) {
1555 CoFreeLibrary(ptr->hLibrary);
1562 /***********************************************************************
1563 * CoFreeUnusedLibraries [COMPOBJ.17]
1564 * CoFreeUnusedLibraries [OLE32.14]
1566 void WINAPI CoFreeUnusedLibraries(void)
1569 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1570 DllCanUnloadNowFunc DllCanUnloadNow;
1572 for (ptr = openDllList; ptr != NULL; ) {
1573 DllCanUnloadNow = (DllCanUnloadNowFunc)
1574 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1576 if ( (DllCanUnloadNow != NULL) &&
1577 (DllCanUnloadNow() == S_OK) ) {
1579 CoFreeLibrary(ptr->hLibrary);
1587 /***********************************************************************
1588 * CoFileTimeNow [COMPOBJ.82]
1589 * CoFileTimeNow [OLE32.10]
1592 * the current system time in lpFileTime
1594 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1596 GetSystemTimeAsFileTime( lpFileTime );
1600 /***********************************************************************
1601 * CoTaskMemAlloc (OLE32.43)
1603 * pointer to newly allocated block
1605 LPVOID WINAPI CoTaskMemAlloc(
1606 ULONG size /* [in] size of memoryblock to be allocated */
1609 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1614 return IMalloc_Alloc(lpmalloc,size);
1616 /***********************************************************************
1617 * CoTaskMemFree (OLE32.44)
1619 VOID WINAPI CoTaskMemFree(
1620 LPVOID ptr /* [in] pointer to be freed */
1623 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1628 IMalloc_Free(lpmalloc, ptr);
1631 /***********************************************************************
1632 * CoTaskMemRealloc (OLE32.45)
1634 * pointer to newly allocated block
1636 LPVOID WINAPI CoTaskMemRealloc(
1638 ULONG size) /* [in] size of memoryblock to be allocated */
1641 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1646 return IMalloc_Realloc(lpmalloc, pvOld, size);
1649 /***********************************************************************
1650 * CoLoadLibrary (OLE32.30)
1652 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1658 TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
1660 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1665 if (openDllList == NULL) {
1666 /* empty list -- add first node */
1667 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1668 openDllList->hLibrary=hLibrary;
1669 openDllList->next = NULL;
1671 /* search for this dll */
1673 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1674 if (ptr->hLibrary == hLibrary) {
1680 /* dll not found, add it */
1682 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1683 openDllList->hLibrary = hLibrary;
1684 openDllList->next = tmp;
1691 /***********************************************************************
1692 * CoInitializeWOW (OLE32.27)
1694 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1695 FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
1699 /******************************************************************************
1700 * CoLockObjectExternal [COMPOBJ.63]
1702 HRESULT WINAPI CoLockObjectExternal16(
1703 LPUNKNOWN pUnk, /* [in] object to be locked */
1704 BOOL16 fLock, /* [in] do lock */
1705 BOOL16 fLastUnlockReleases /* [in] ? */
1707 FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
1711 /******************************************************************************
1712 * CoLockObjectExternal [OLE32.31]
1714 HRESULT WINAPI CoLockObjectExternal(
1715 LPUNKNOWN pUnk, /* [in] object to be locked */
1716 BOOL fLock, /* [in] do lock */
1717 BOOL fLastUnlockReleases) /* [in] unlock all */
1723 * Increment the external lock coutner, COM_ExternalLockAddRef also
1724 * increment the object's internal lock counter.
1726 COM_ExternalLockAddRef( pUnk);
1731 * Decrement the external lock coutner, COM_ExternalLockRelease also
1732 * decrement the object's internal lock counter.
1734 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1740 /***********************************************************************
1741 * CoGetState [COMPOBJ.115]
1743 HRESULT WINAPI CoGetState16(LPDWORD state)
1745 FIXME("(%p),stub!\n", state);
1749 /***********************************************************************
1750 * CoSetState [OLE32.42]
1752 HRESULT WINAPI CoSetState(LPDWORD state)
1754 FIXME("(%p),stub!\n", state);
1755 if (state) *state = 0;
1758 /***********************************************************************
1759 * CoCreateFreeThreadedMarshaler [OLE32.5]
1761 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1763 FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
1769 /***********************************************************************
1770 * DllGetClassObject [OLE32.63]
1772 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1774 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1776 return CLASS_E_CLASSNOTAVAILABLE;
1781 * COM_RevokeAllClasses
1783 * This method is called when the COM libraries are uninitialized to
1784 * release all the references to the class objects registered with
1787 static void COM_RevokeAllClasses()
1789 while (firstRegisteredClass!=0)
1791 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1795 /****************************************************************************
1796 * COM External Lock methods implementation
1799 /****************************************************************************
1800 * Public - Method that increments the count for a IUnknown* in the linked
1801 * list. The item is inserted if not already in the list.
1803 static void COM_ExternalLockAddRef(
1806 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1809 * Add an external lock to the object. If it was already externally
1810 * locked, just increase the reference count. If it was not.
1811 * add the item to the list.
1813 if ( externalLock == EL_NOT_FOUND )
1814 COM_ExternalLockInsert(pUnk);
1816 externalLock->uRefCount++;
1819 * Add an internal lock to the object
1821 IUnknown_AddRef(pUnk);
1824 /****************************************************************************
1825 * Public - Method that decrements the count for a IUnknown* in the linked
1826 * list. The item is removed from the list if its count end up at zero or if
1829 static void COM_ExternalLockRelease(
1833 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1835 if ( externalLock != EL_NOT_FOUND )
1839 externalLock->uRefCount--; /* release external locks */
1840 IUnknown_Release(pUnk); /* release local locks as well */
1842 if ( bRelAll == FALSE )
1843 break; /* perform single release */
1845 } while ( externalLock->uRefCount > 0 );
1847 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1848 COM_ExternalLockDelete(externalLock);
1851 /****************************************************************************
1852 * Public - Method that frees the content of the list.
1854 static void COM_ExternalLockFreeList()
1856 COM_ExternalLock *head;
1858 head = elList.head; /* grab it by the head */
1859 while ( head != EL_END_OF_LIST )
1861 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1863 head = elList.head; /* get the new head... */
1867 /****************************************************************************
1868 * Public - Method that dump the content of the list.
1870 void COM_ExternalLockDump()
1872 COM_ExternalLock *current = elList.head;
1874 DPRINTF("\nExternal lock list contains:\n");
1876 while ( current != EL_END_OF_LIST )
1878 DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
1880 /* Skip to the next item */
1881 current = current->next;
1886 /****************************************************************************
1887 * Internal - Find a IUnknown* in the linked list
1889 static COM_ExternalLock* COM_ExternalLockFind(
1892 return COM_ExternalLockLocate(elList.head, pUnk);
1895 /****************************************************************************
1896 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1898 static COM_ExternalLock* COM_ExternalLockLocate(
1899 COM_ExternalLock *element,
1902 if ( element == EL_END_OF_LIST )
1903 return EL_NOT_FOUND;
1905 else if ( element->pUnk == pUnk ) /* We found it */
1908 else /* Not the right guy, keep on looking */
1909 return COM_ExternalLockLocate( element->next, pUnk);
1912 /****************************************************************************
1913 * Internal - Insert a new IUnknown* to the linked list
1915 static BOOL COM_ExternalLockInsert(
1918 COM_ExternalLock *newLock = NULL;
1919 COM_ExternalLock *previousHead = NULL;
1922 * Allocate space for the new storage object
1924 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
1928 if ( elList.head == EL_END_OF_LIST )
1930 elList.head = newLock; /* The list is empty */
1935 * insert does it at the head
1937 previousHead = elList.head;
1938 elList.head = newLock;
1942 * Set new list item data member
1944 newLock->pUnk = pUnk;
1945 newLock->uRefCount = 1;
1946 newLock->next = previousHead;
1954 /****************************************************************************
1955 * Internal - Method that removes an item from the linked list.
1957 static void COM_ExternalLockDelete(
1958 COM_ExternalLock *itemList)
1960 COM_ExternalLock *current = elList.head;
1962 if ( current == itemList )
1965 * this section handles the deletion of the first node
1967 elList.head = itemList->next;
1968 HeapFree( GetProcessHeap(), 0, itemList);
1974 if ( current->next == itemList ) /* We found the item to free */
1976 current->next = itemList->next; /* readjust the list pointers */
1978 HeapFree( GetProcessHeap(), 0, itemList);
1982 /* Skip to the next item */
1983 current = current->next;
1985 } while ( current != EL_END_OF_LIST );
1989 /***********************************************************************
1990 * DllEntryPoint [COMPOBJ.116]
1992 * Initialization code for the COMPOBJ DLL
1996 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
1998 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
2002 case DLL_PROCESS_ATTACH:
2003 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
2006 case DLL_PROCESS_DETACH:
2007 if(!--COMPOBJ_Attach)
2008 COMPOBJ_hInstance = 0;
2014 /******************************************************************************
2015 * OleGetAutoConvert [OLE32.104]
2017 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2025 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2026 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2028 res = REGDB_E_CLASSNOTREG;
2032 /* we can just query for the default value of AutoConvertTo key like that,
2033 without opening the AutoConvertTo key and querying for NULL (default) */
2034 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
2036 res = REGDB_E_KEYMISSING;
2039 MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
2040 CLSIDFromString(wbuf,pClsidNew);
2042 if (hkey) RegCloseKey(hkey);
2047 /******************************************************************************
2048 * OleSetAutoConvert [OLE32.126]
2050 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2052 HKEY hkey = 0, hkeyConvert = 0;
2053 char buf[200], szClsidNew[200];
2056 TRACE("(%p,%p);\n", clsidOld, clsidNew);
2057 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2058 WINE_StringFromCLSID(clsidNew, szClsidNew);
2059 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2061 res = REGDB_E_CLASSNOTREG;
2064 if (RegCreateKeyA(hkey, "AutoConvertTo", &hkeyConvert))
2066 res = REGDB_E_WRITEREGDB;
2069 if (RegSetValueExA(hkeyConvert, NULL, 0,
2070 REG_SZ, (LPBYTE)szClsidNew, strlen(szClsidNew)+1))
2072 res = REGDB_E_WRITEREGDB;
2077 if (hkeyConvert) RegCloseKey(hkeyConvert);
2078 if (hkey) RegCloseKey(hkey);
2083 /***********************************************************************
2084 * IsEqualGUID [OLE32.76]
2086 * Compares two Unique Identifiers.
2092 BOOL WINAPI IsEqualGUID(
2093 REFGUID rguid1, /* [in] unique id 1 */
2094 REFGUID rguid2 /* [in] unique id 2 */
2097 return !memcmp(rguid1,rguid2,sizeof(GUID));