4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
27 #include "wine/unicode.h"
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"
37 #include "debugtools.h"
39 DEFAULT_DEBUG_CHANNEL(ole);
41 /****************************************************************************
42 * COM External Lock structures and methods declaration
44 * This api provides a linked list to managed external references to
47 * The public interface consists of three calls:
48 * COM_ExternalLockAddRef
49 * COM_ExternalLockRelease
50 * COM_ExternalLockFreeList
53 #define EL_END_OF_LIST 0
54 #define EL_NOT_FOUND 0
57 * Declaration of the static structure that manage the
58 * external lock to COM objects.
60 typedef struct COM_ExternalLock COM_ExternalLock;
61 typedef struct COM_ExternalLockList COM_ExternalLockList;
63 struct COM_ExternalLock
65 IUnknown *pUnk; /* IUnknown referenced */
66 ULONG uRefCount; /* external lock counter to IUnknown object*/
67 COM_ExternalLock *next; /* Pointer to next element in list */
70 struct COM_ExternalLockList
72 COM_ExternalLock *head; /* head of list */
76 * Declaration and initialization of the static structure that manages
77 * the external lock to COM objects.
79 static COM_ExternalLockList elList = { EL_END_OF_LIST };
82 * Public Interface to the external lock list
84 static void COM_ExternalLockFreeList();
85 static void COM_ExternalLockAddRef(IUnknown *pUnk);
86 static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
87 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
90 * Private methods used to managed the linked list
92 static BOOL COM_ExternalLockInsert(
95 static void COM_ExternalLockDelete(
96 COM_ExternalLock *element);
98 static COM_ExternalLock* COM_ExternalLockFind(
101 static COM_ExternalLock* COM_ExternalLockLocate(
102 COM_ExternalLock *element,
105 /****************************************************************************
106 * This section defines variables internal to the COM module.
108 * TODO: Most of these things will have to be made thread-safe.
110 HINSTANCE16 COMPOBJ_hInstance = 0;
111 HINSTANCE COMPOBJ_hInstance32 = 0;
112 static int COMPOBJ_Attach = 0;
114 LPMALLOC16 currentMalloc16=NULL;
115 LPMALLOC currentMalloc32=NULL;
118 WORD Table_ETask[62];
121 * This lock count counts the number of times CoInitialize is called. It is
122 * decreased every time CoUninitialize is called. When it hits 0, the COM
123 * libraries are freed
125 static LONG s_COMLockCount = 0;
128 * This linked list contains the list of registered class objects. These
129 * are mostly used to register the factories for out-of-proc servers of OLE
132 * TODO: Make this data structure aware of inter-process communication. This
133 * means that parts of this will be exported to the Wine Server.
135 typedef struct tagRegisteredClass
137 CLSID classIdentifier;
138 LPUNKNOWN classObject;
142 struct tagRegisteredClass* nextClass;
145 static CRITICAL_SECTION csRegisteredClassList;
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 CRITICAL_SECTION csOpenDllList;
158 static OpenDll *openDllList = NULL; /* linked list of open dlls */
160 /*****************************************************************************
161 * This section contains prototypes to internal methods for this
164 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
168 static void COM_RevokeAllClasses();
171 /******************************************************************************
172 * Initialize/Uninitialize critical sections.
174 void COMPOBJ_InitProcess( void )
176 InitializeCriticalSection( &csRegisteredClassList );
177 InitializeCriticalSection( &csOpenDllList );
180 void COMPOBJ_UninitProcess( void )
182 DeleteCriticalSection( &csRegisteredClassList );
183 DeleteCriticalSection( &csOpenDllList );
186 /******************************************************************************
187 * CoBuildVersion [COMPOBJ.1]
188 * CoBuildVersion [OLE32.4]
191 * Current build version, hiword is majornumber, loword is minornumber
193 DWORD WINAPI CoBuildVersion(void)
195 TRACE("Returning version %d, build %d.\n", rmm, rup);
196 return (rmm<<16)+rup;
199 /******************************************************************************
200 * CoInitialize [COMPOBJ.2]
201 * Set the win16 IMalloc used for memory management
203 HRESULT WINAPI CoInitialize16(
204 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
206 currentMalloc16 = (LPMALLOC16)lpReserved;
210 /******************************************************************************
211 * CoInitialize [OLE32.26]
213 * Initializes the COM libraries.
217 HRESULT WINAPI CoInitialize(
218 LPVOID lpReserved /* [in] pointer to win32 malloc interface
219 (obsolete, should be NULL) */
223 * Just delegate to the newer method.
225 return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
228 /******************************************************************************
229 * CoInitializeEx [OLE32.163]
231 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
232 * used for memory management is obsolete.
235 * S_OK if successful,
236 * S_FALSE if this function was called already.
237 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
241 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
244 * See the windows documentation for more details.
246 HRESULT WINAPI CoInitializeEx(
247 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
248 (obsolete, should be NULL) */
249 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
254 TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
256 if (lpReserved!=NULL)
258 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
262 * Check for unsupported features.
264 if (dwCoInit!=COINIT_APARTMENTTHREADED)
266 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
267 /* Hope for the best and continue anyway */
271 * Check the lock count. If this is the first time going through the initialize
272 * process, we have to initialize the libraries.
274 * And crank-up that lock count.
276 if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
279 * Initialize the various COM libraries and data structures.
281 TRACE("() - Initializing the COM libraries\n");
284 RunningObjectTableImpl_Initialize();
294 /***********************************************************************
295 * CoUninitialize [COMPOBJ.3]
296 * Don't know what it does.
297 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
298 * believe is the correct spelling
300 void WINAPI CoUninitialize16(void)
303 CoFreeAllLibraries();
306 /***********************************************************************
307 * CoUninitialize [OLE32.47]
309 * This method will release the COM libraries.
311 * See the windows documentation for more details.
313 void WINAPI CoUninitialize(void)
319 * Decrease the reference count.
320 * If we are back to 0 locks on the COM library, make sure we free
321 * all the associated data structures.
323 lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
327 * Release the various COM libraries and data structures.
329 TRACE("() - Releasing the COM libraries\n");
331 RunningObjectTableImpl_UnInitialize();
333 * Release the references to the registered class objects.
335 COM_RevokeAllClasses();
338 * This will free the loaded COM Dlls.
340 CoFreeAllLibraries();
343 * This will free list of external references to COM objects.
345 COM_ExternalLockFreeList();
348 else if (lCOMRefCnt<1) {
349 ERR( "CoUninitialize() - not CoInitialized.\n" );
350 InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
354 /***********************************************************************
355 * CoGetMalloc [COMPOBJ.4]
357 * The current win16 IMalloc
359 HRESULT WINAPI CoGetMalloc16(
360 DWORD dwMemContext, /* [in] unknown */
361 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
364 currentMalloc16 = IMalloc16_Constructor();
365 *lpMalloc = currentMalloc16;
369 /******************************************************************************
370 * CoGetMalloc [OLE32.20]
373 * The current win32 IMalloc
375 HRESULT WINAPI CoGetMalloc(
376 DWORD dwMemContext, /* [in] unknown */
377 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
380 currentMalloc32 = IMalloc_Constructor();
381 *lpMalloc = currentMalloc32;
385 /***********************************************************************
386 * CoCreateStandardMalloc [COMPOBJ.71]
388 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
389 LPMALLOC16 *lpMalloc)
391 /* FIXME: docu says we shouldn't return the same allocator as in
393 *lpMalloc = IMalloc16_Constructor();
397 /******************************************************************************
398 * CoDisconnectObject [COMPOBJ.15]
399 * CoDisconnectObject [OLE32.8]
401 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
403 TRACE("(%p, %lx)\n",lpUnk,reserved);
407 /***********************************************************************
408 * IsEqualGUID [COMPOBJ.18]
410 * Compares two Unique Identifiers.
415 BOOL16 WINAPI IsEqualGUID16(
416 GUID* g1, /* [in] unique id 1 */
417 GUID* g2 /* [in] unique id 2 */
419 return !memcmp( g1, g2, sizeof(GUID) );
422 /******************************************************************************
423 * CLSIDFromString [COMPOBJ.20]
424 * Converts a unique identifier from its string representation into
427 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
432 HRESULT WINAPI CLSIDFromString16(
433 LPCOLESTR16 idstr, /* [in] string representation of guid */
434 CLSID *id /* [out] GUID converted from string */
436 BYTE *s = (BYTE *) idstr;
442 s = "{00000000-0000-0000-0000-000000000000}";
443 else { /* validate the CLSID string */
446 return CO_E_CLASSSTRING;
448 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
449 return CO_E_CLASSSTRING;
453 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
454 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
455 ((s[i] >= 'a') && (s[i] <= 'f')) ||
456 ((s[i] >= 'A') && (s[i] <= 'F')))
458 return CO_E_CLASSSTRING;
462 TRACE("%s -> %p\n", s, id);
464 /* quick lookup table */
465 memset(table, 0, 256);
467 for (i = 0; i < 10; i++) {
470 for (i = 0; i < 6; i++) {
471 table['A' + i] = i+10;
472 table['a' + i] = i+10;
475 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
479 s++; /* skip leading brace */
480 for (i = 0; i < 4; i++) {
481 p[3 - i] = table[*s]<<4 | table[*(s+1)];
487 for (i = 0; i < 2; i++) {
488 p[1-i] = table[*s]<<4 | table[*(s+1)];
494 for (i = 0; i < 2; i++) {
495 p[1-i] = table[*s]<<4 | table[*(s+1)];
501 /* these are just sequential bytes */
502 for (i = 0; i < 2; i++) {
503 *p++ = table[*s]<<4 | table[*(s+1)];
508 for (i = 0; i < 6; i++) {
509 *p++ = table[*s]<<4 | table[*(s+1)];
516 /******************************************************************************
517 * CoCreateGuid[OLE32.6]
520 HRESULT WINAPI CoCreateGuid(
521 GUID *pguid /* [out] points to the GUID to initialize */
523 return UuidCreate(pguid);
526 /******************************************************************************
527 * CLSIDFromString [OLE32.3]
528 * IIDFromString [OLE32.74]
529 * Converts a unique identifier from its string representation into
533 * If idstr is not a valid CLSID string then it gets treated as a ProgID
538 HRESULT WINAPI CLSIDFromString(
539 LPCOLESTR idstr, /* [in] string representation of GUID */
540 CLSID *id ) /* [out] GUID represented by above string */
545 if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL ))
546 return CO_E_CLASSSTRING;
547 ret = CLSIDFromString16(xid,id);
548 if(ret != S_OK) { /* It appears a ProgID is also valid */
549 ret = CLSIDFromProgID(idstr, id);
554 /******************************************************************************
555 * WINE_StringFromCLSID [Internal]
556 * Converts a GUID into the respective string representation.
561 * the string representation and HRESULT
563 static HRESULT WINE_StringFromCLSID(
564 const CLSID *id, /* [in] GUID to be converted */
565 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
567 static const char *hex = "0123456789ABCDEF";
572 { ERR("called with id=Null\n");
577 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
578 id->Data1, id->Data2, id->Data3,
579 id->Data4[0], id->Data4[1]);
583 for (i = 2; i < 8; i++) {
584 *s++ = hex[id->Data4[i]>>4];
585 *s++ = hex[id->Data4[i] & 0xf];
591 TRACE("%p->%s\n", id, idstr);
596 /******************************************************************************
597 * StringFromCLSID [COMPOBJ.19]
598 * Converts a GUID into the respective string representation.
599 * The target string is allocated using the OLE IMalloc.
601 * the string representation and HRESULT
603 HRESULT WINAPI StringFromCLSID16(
604 REFCLSID id, /* [in] the GUID to be converted */
605 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
608 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
609 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
614 ret = CoGetMalloc16(0,&mllc);
617 args[0] = (DWORD)mllc;
620 /* No need for a Callback entry, we have WOWCallback16Ex which does
621 * everything we need.
623 if (!K32WOWCallback16Ex(
624 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
625 (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
632 WARN("CallTo16 IMalloc16 failed\n");
635 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
638 /******************************************************************************
639 * StringFromCLSID [OLE32.151]
640 * StringFromIID [OLE32.153]
641 * Converts a GUID into the respective string representation.
642 * The target string is allocated using the OLE IMalloc.
644 * the string representation and HRESULT
646 HRESULT WINAPI StringFromCLSID(
647 REFCLSID id, /* [in] the GUID to be converted */
648 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
654 if ((ret=CoGetMalloc(0,&mllc)))
657 ret=WINE_StringFromCLSID(id,buf);
659 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
660 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
661 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
666 /******************************************************************************
667 * StringFromGUID2 [COMPOBJ.76]
668 * StringFromGUID2 [OLE32.152]
670 * Converts a global unique identifier into a string of an API-
671 * specified fixed format. (The usual {.....} stuff.)
674 * The (UNICODE) string representation of the GUID in 'str'
675 * The length of the resulting string, 0 if there was any problem.
678 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
682 if (WINE_StringFromCLSID(id,xguid))
684 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
687 /******************************************************************************
688 * ProgIDFromCLSID [OLE32.133]
689 * Converts a class id into the respective Program ID. (By using a registry lookup)
690 * RETURNS S_OK on success
691 * riid associated with the progid
694 HRESULT WINAPI ProgIDFromCLSID(
695 REFCLSID clsid, /* [in] class id as found in registry */
696 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
699 char strCLSID[50], *buf, *buf2;
705 WINE_StringFromCLSID(clsid, strCLSID);
707 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
708 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
709 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
710 ret = REGDB_E_CLASSNOTREG;
712 HeapFree(GetProcessHeap(), 0, buf);
716 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
718 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
719 ret = REGDB_E_CLASSNOTREG;
723 if (CoGetMalloc(0,&mllc))
727 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
728 *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
729 MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
732 HeapFree(GetProcessHeap(), 0, buf2);
739 /******************************************************************************
740 * CLSIDFromProgID [COMPOBJ.61]
741 * Converts a program id into the respective GUID. (By using a registry lookup)
743 * riid associated with the progid
745 HRESULT WINAPI CLSIDFromProgID16(
746 LPCOLESTR16 progid, /* [in] program id as found in registry */
747 LPCLSID riid /* [out] associated CLSID */
754 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
755 sprintf(buf,"%s\\CLSID",progid);
756 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
757 HeapFree(GetProcessHeap(),0,buf);
758 return CO_E_CLASSSTRING;
760 HeapFree(GetProcessHeap(),0,buf);
761 buf2len = sizeof(buf2);
762 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
764 return CO_E_CLASSSTRING;
767 return CLSIDFromString16(buf2,riid);
770 /******************************************************************************
771 * CLSIDFromProgID [OLE32.2]
772 * Converts a program id into the respective GUID. (By using a registry lookup)
774 * riid associated with the progid
776 HRESULT WINAPI CLSIDFromProgID(
777 LPCOLESTR progid, /* [in] program id as found in registry */
778 LPCLSID riid ) /* [out] associated CLSID */
780 static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
782 DWORD buf2len = sizeof(buf2);
785 WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
786 strcpyW( buf, progid );
787 strcatW( buf, clsidW );
788 if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
790 HeapFree(GetProcessHeap(),0,buf);
791 return CO_E_CLASSSTRING;
793 HeapFree(GetProcessHeap(),0,buf);
795 if (RegQueryValueA(xhkey,NULL,buf2,&buf2len))
798 return CO_E_CLASSSTRING;
801 return CLSIDFromString16(buf2,riid);
806 /*****************************************************************************
807 * CoGetPSClsid [OLE32.22]
809 * This function returns the CLSID of the DLL that implements the proxy and stub
810 * for the specified interface.
812 * It determines this by searching the
813 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
814 * and any interface id registered by CoRegisterPSClsid within the current process.
816 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
818 HRESULT WINAPI CoGetPSClsid(
819 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
820 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
826 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
828 /* Get the input iid as a string */
829 WINE_StringFromCLSID(riid, buf2);
830 /* Allocate memory for the registry key we will construct.
831 (length of iid string plus constant length of static text */
832 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
835 return (E_OUTOFMEMORY);
838 /* Construct the registry key we want */
839 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
842 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
844 HeapFree(GetProcessHeap(),0,buf);
845 return (E_INVALIDARG);
847 HeapFree(GetProcessHeap(),0,buf);
849 /* ... Once we have the key, query the registry to get the
850 value of CLSID as a string, and convert it into a
851 proper CLSID structure to be passed back to the app */
852 buf2len = sizeof(buf2);
853 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
860 /* We have the CLSid we want back from the registry as a string, so
861 lets convert it into a CLSID structure */
862 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
867 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
873 /***********************************************************************
874 * WriteClassStm (OLE32.159)
876 * This function write a CLSID on stream
878 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
880 TRACE("(%p,%p)\n",pStm,rclsid);
885 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
888 /***********************************************************************
889 * ReadClassStm (OLE32.135)
891 * This function read a CLSID from a stream
893 HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
898 TRACE("(%p,%p)\n",pStm,pclsid);
903 res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
908 if (nbByte != sizeof(CLSID))
914 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
915 /***********************************************************************
916 * LookupETask (COMPOBJ.94)
918 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
919 FIXME("(%p,%p),stub!\n",hTask,p);
920 if ((*hTask = GetCurrentTask()) == hETask) {
921 memcpy(p, Table_ETask, sizeof(Table_ETask));
926 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
927 /***********************************************************************
928 * SetETask (COMPOBJ.95)
930 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
931 FIXME("(%04x,%p),stub!\n",hTask,p);
936 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
937 /***********************************************************************
938 * CALLOBJECTINWOW (COMPOBJ.201)
940 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
941 FIXME("(%p,%p),stub!\n",p1,p2);
945 /******************************************************************************
946 * CoRegisterClassObject [COMPOBJ.5]
948 * Don't know where it registers it ...
950 HRESULT WINAPI CoRegisterClassObject16(
953 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
954 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
959 WINE_StringFromCLSID(rclsid,buf);
961 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
962 buf,pUnk,dwClsContext,flags,lpdwRegister
968 /******************************************************************************
969 * CoRevokeClassObject [COMPOBJ.6]
972 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
974 FIXME("(0x%08lx),stub!\n", dwRegister);
978 /******************************************************************************
979 * CoFileTimeToDosDateTime [COMPOBJ.30]
981 BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
983 return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
986 /******************************************************************************
987 * CoDosDateTimeToFileTime [COMPOBJ.31]
989 BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
991 return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
995 * COM_GetRegisteredClassObject
997 * This internal method is used to scan the registered class list to
998 * find a class object.
1001 * rclsid Class ID of the class to find.
1002 * dwClsContext Class context to match.
1003 * ppv [out] returns a pointer to the class object. Complying
1004 * to normal COM usage, this method will increase the
1005 * reference count on this object.
1007 static HRESULT COM_GetRegisteredClassObject(
1012 HRESULT hr = S_FALSE;
1013 RegisteredClass* curClass;
1015 EnterCriticalSection( &csRegisteredClassList );
1023 * Iterate through the whole list and try to match the class ID.
1025 curClass = firstRegisteredClass;
1027 while (curClass != 0)
1030 * Check if we have a match on the class ID.
1032 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
1035 * Since we don't do out-of process or DCOM just right away, let's ignore the
1040 * We have a match, return the pointer to the class object.
1042 *ppUnk = curClass->classObject;
1044 IUnknown_AddRef(curClass->classObject);
1051 * Step to the next class in the list.
1053 curClass = curClass->nextClass;
1057 LeaveCriticalSection( &csRegisteredClassList );
1059 * If we get to here, we haven't found our class.
1064 /******************************************************************************
1065 * CoRegisterClassObject [OLE32.36]
1067 * This method will register the class object for a given class ID.
1069 * See the Windows documentation for more details.
1071 HRESULT WINAPI CoRegisterClassObject(
1074 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
1075 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1076 LPDWORD lpdwRegister
1079 RegisteredClass* newClass;
1080 LPUNKNOWN foundObject;
1084 WINE_StringFromCLSID(rclsid,buf);
1086 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1087 buf,pUnk,dwClsContext,flags,lpdwRegister);
1090 * Perform a sanity check on the parameters
1092 if ( (lpdwRegister==0) || (pUnk==0) )
1094 return E_INVALIDARG;
1098 * Initialize the cookie (out parameter)
1103 * First, check if the class is already registered.
1104 * If it is, this should cause an error.
1106 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1111 * The COM_GetRegisteredClassObject increased the reference count on the
1112 * object so it has to be released.
1114 IUnknown_Release(foundObject);
1116 return CO_E_OBJISREG;
1120 * If it is not registered, we must create a new entry for this class and
1121 * append it to the registered class list.
1122 * We use the address of the chain node as the cookie since we are sure it's
1125 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1126 if ( newClass == NULL )
1127 return E_OUTOFMEMORY;
1129 EnterCriticalSection( &csRegisteredClassList );
1131 * Initialize the node.
1133 newClass->classIdentifier = *rclsid;
1134 newClass->runContext = dwClsContext;
1135 newClass->connectFlags = flags;
1136 newClass->dwCookie = (DWORD)newClass;
1137 newClass->nextClass = firstRegisteredClass;
1140 * Since we're making a copy of the object pointer, we have to increase its
1143 newClass->classObject = pUnk;
1144 IUnknown_AddRef(newClass->classObject);
1146 firstRegisteredClass = newClass;
1148 LeaveCriticalSection( &csRegisteredClassList );
1151 * Assign the out parameter (cookie)
1153 *lpdwRegister = newClass->dwCookie;
1156 * We're successful Yippee!
1161 /***********************************************************************
1162 * CoRevokeClassObject [OLE32.40]
1164 * This method will remove a class object from the class registry
1166 * See the Windows documentation for more details.
1168 HRESULT WINAPI CoRevokeClassObject(
1171 HRESULT hr = E_INVALIDARG;
1172 RegisteredClass** prevClassLink;
1173 RegisteredClass* curClass;
1175 TRACE("(%08lx)\n",dwRegister);
1177 EnterCriticalSection( &csRegisteredClassList );
1180 * Iterate through the whole list and try to match the cookie.
1182 curClass = firstRegisteredClass;
1183 prevClassLink = &firstRegisteredClass;
1185 while (curClass != 0)
1188 * Check if we have a match on the cookie.
1190 if (curClass->dwCookie == dwRegister)
1193 * Remove the class from the chain.
1195 *prevClassLink = curClass->nextClass;
1198 * Release the reference to the class object.
1200 IUnknown_Release(curClass->classObject);
1203 * Free the memory used by the chain node.
1205 HeapFree(GetProcessHeap(), 0, curClass);
1212 * Step to the next class in the list.
1214 prevClassLink = &(curClass->nextClass);
1215 curClass = curClass->nextClass;
1219 LeaveCriticalSection( &csRegisteredClassList );
1221 * If we get to here, we haven't found our class.
1226 /***********************************************************************
1227 * CoGetClassObject [COMPOBJ.7]
1228 * CoGetClassObject [OLE32.16]
1230 HRESULT WINAPI CoGetClassObject(
1231 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1232 REFIID iid, LPVOID *ppv
1234 LPUNKNOWN regClassObject;
1235 HRESULT hres = E_UNEXPECTED;
1237 WCHAR dllName[MAX_PATH+1];
1238 DWORD dllNameLen = sizeof(dllName);
1240 typedef HRESULT CALLBACK (*DllGetClassObjectFunc)(REFCLSID clsid,
1241 REFIID iid, LPVOID *ppv);
1242 DllGetClassObjectFunc DllGetClassObject;
1244 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1246 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1247 debugstr_guid(rclsid),
1252 FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
1253 FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
1257 * First, try and see if we can't match the class ID with one of the
1258 * registered classes.
1260 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1263 * Get the required interface from the retrieved pointer.
1265 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1268 * Since QI got another reference on the pointer, we want to release the
1269 * one we already have. If QI was unsuccessful, this will release the object. This
1270 * is good since we are not returning it in the "out" parameter.
1272 IUnknown_Release(regClassObject);
1277 /* out of process and remote servers not supported yet */
1278 if ( ((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1279 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
1281 FIXME("%s %s not supported!\n",
1282 (dwClsContext&CLSCTX_LOCAL_SERVER)?"CLSCTX_LOCAL_SERVER":"",
1283 (dwClsContext&CLSCTX_REMOTE_SERVER)?"CLSCTX_REMOTE_SERVER":""
1285 return E_ACCESSDENIED;
1288 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1292 sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
1293 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
1295 if (hres != ERROR_SUCCESS) {
1296 return REGDB_E_CLASSNOTREG;
1299 memset(dllName,0,sizeof(dllName));
1300 hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
1302 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1304 TRACE("found InprocServer32 dll %s\n", debugstr_w(dllName));
1306 /* open dll, call DllGetClassObject */
1307 hLibrary = CoLoadLibrary(dllName, TRUE);
1308 if (hLibrary == 0) {
1309 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(dllName));
1310 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1312 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1313 if (!DllGetClassObject) {
1314 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1315 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllName));
1316 return E_ACCESSDENIED;
1320 * Ask the DLL for its class object. (there was a note here about class
1321 * factories but this is good.
1323 return DllGetClassObject(rclsid, iid, ppv);
1328 /***********************************************************************
1329 * CoResumeClassObjects (OLE32.173)
1331 * Resumes classobjects registered with REGCLS suspended
1333 HRESULT WINAPI CoResumeClassObjects(void)
1339 /***********************************************************************
1340 * GetClassFile (OLE32.67)
1342 * This function supplies the CLSID associated with the given filename.
1344 HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
1348 int nbElm=0,length=0,i=0;
1350 LPOLESTR *pathDec=0,absFile=0,progId=0;
1351 WCHAR extention[100]={0};
1355 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1356 if((StgIsStorageFile(filePathName))==S_OK){
1358 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1361 res=ReadClassStg(pstg,pclsid);
1363 IStorage_Release(pstg);
1367 /* if the file is not a storage object then attemps to match various bits in the file against a
1368 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1371 for(i=0;i<nFileTypes;i++)
1373 for(i=0;j<nPatternsForType;j++){
1378 pat=ReadPatternFromRegistry(i,j);
1379 hFile=CreateFileW(filePathName,,,,,,hFile);
1380 SetFilePosition(hFile,pat.offset);
1381 ReadFile(hFile,buf,pat.size,NULL,NULL);
1382 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1384 *pclsid=ReadCLSIDFromRegistry(i);
1390 /* if the obove strategies fail then search for the extension key in the registry */
1392 /* get the last element (absolute file) in the path name */
1393 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1394 absFile=pathDec[nbElm-1];
1396 /* failed if the path represente a directory and not an absolute file name*/
1397 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1398 return MK_E_INVALIDEXTENSION;
1400 /* get the extension of the file */
1401 length=lstrlenW(absFile);
1402 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1404 /* get the progId associated to the extension */
1405 progId=CoTaskMemAlloc(sizeProgId);
1407 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1409 if (res==ERROR_MORE_DATA){
1411 progId = CoTaskMemRealloc(progId,sizeProgId);
1412 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1414 if (res==ERROR_SUCCESS)
1415 /* return the clsid associated to the progId */
1416 res= CLSIDFromProgID(progId,pclsid);
1418 for(i=0; pathDec[i]!=NULL;i++)
1419 CoTaskMemFree(pathDec[i]);
1420 CoTaskMemFree(pathDec);
1422 CoTaskMemFree(progId);
1424 if (res==ERROR_SUCCESS)
1427 return MK_E_INVALIDEXTENSION;
1429 /******************************************************************************
1430 * CoRegisterMessageFilter [COMPOBJ.27]
1432 HRESULT WINAPI CoRegisterMessageFilter16(
1433 LPMESSAGEFILTER lpMessageFilter,
1434 LPMESSAGEFILTER *lplpMessageFilter
1436 FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
1440 /***********************************************************************
1441 * CoCreateInstance [COMPOBJ.13]
1442 * CoCreateInstance [OLE32.7]
1444 HRESULT WINAPI CoCreateInstance(
1446 LPUNKNOWN pUnkOuter,
1452 LPCLASSFACTORY lpclf = 0;
1461 * Initialize the "out" parameter
1466 * Get a class factory to construct the object we want.
1468 hres = CoGetClassObject(rclsid,
1475 FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
1476 debugstr_guid(rclsid),hres);
1481 * Create the object and don't forget to release the factory
1483 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1484 IClassFactory_Release(lpclf);
1486 FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
1487 debugstr_guid(iid), debugstr_guid(rclsid),hres);
1492 /***********************************************************************
1493 * CoCreateInstanceEx [OLE32.165]
1495 HRESULT WINAPI CoCreateInstanceEx(
1497 LPUNKNOWN pUnkOuter,
1499 COSERVERINFO* pServerInfo,
1503 IUnknown* pUnk = NULL;
1506 int successCount = 0;
1511 if ( (cmq==0) || (pResults==NULL))
1512 return E_INVALIDARG;
1514 if (pServerInfo!=NULL)
1515 FIXME("() non-NULL pServerInfo not supported!\n");
1518 * Initialize all the "out" parameters.
1520 for (index = 0; index < cmq; index++)
1522 pResults[index].pItf = NULL;
1523 pResults[index].hr = E_NOINTERFACE;
1527 * Get the object and get its IUnknown pointer.
1529 hr = CoCreateInstance(rclsid,
1539 * Then, query for all the interfaces requested.
1541 for (index = 0; index < cmq; index++)
1543 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1544 pResults[index].pIID,
1545 (VOID**)&(pResults[index].pItf));
1547 if (pResults[index].hr == S_OK)
1552 * Release our temporary unknown pointer.
1554 IUnknown_Release(pUnk);
1556 if (successCount == 0)
1557 return E_NOINTERFACE;
1559 if (successCount!=cmq)
1560 return CO_S_NOTALLINTERFACES;
1565 /***********************************************************************
1566 * CoFreeLibrary [OLE32.13]
1568 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1570 OpenDll *ptr, *prev;
1573 EnterCriticalSection( &csOpenDllList );
1575 /* lookup library in linked list */
1577 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1578 if (ptr->hLibrary == hLibrary) {
1585 /* shouldn't happen if user passed in a valid hLibrary */
1588 /* assert: ptr points to the library entry to free */
1590 /* free library and remove node from list */
1591 FreeLibrary(hLibrary);
1592 if (ptr == openDllList) {
1593 tmp = openDllList->next;
1594 HeapFree(GetProcessHeap(), 0, openDllList);
1598 HeapFree(GetProcessHeap(), 0, ptr);
1602 LeaveCriticalSection( &csOpenDllList );
1606 /***********************************************************************
1607 * CoFreeAllLibraries [OLE32.12]
1609 void WINAPI CoFreeAllLibraries(void)
1613 EnterCriticalSection( &csOpenDllList );
1615 for (ptr = openDllList; ptr != NULL; ) {
1617 CoFreeLibrary(ptr->hLibrary);
1621 LeaveCriticalSection( &csOpenDllList );
1626 /***********************************************************************
1627 * CoFreeUnusedLibraries [COMPOBJ.17]
1628 * CoFreeUnusedLibraries [OLE32.14]
1630 void WINAPI CoFreeUnusedLibraries(void)
1633 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1634 DllCanUnloadNowFunc DllCanUnloadNow;
1636 EnterCriticalSection( &csOpenDllList );
1638 for (ptr = openDllList; ptr != NULL; ) {
1639 DllCanUnloadNow = (DllCanUnloadNowFunc)
1640 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1642 if ( (DllCanUnloadNow != NULL) &&
1643 (DllCanUnloadNow() == S_OK) ) {
1645 CoFreeLibrary(ptr->hLibrary);
1652 LeaveCriticalSection( &csOpenDllList );
1655 /***********************************************************************
1656 * CoFileTimeNow [COMPOBJ.82]
1657 * CoFileTimeNow [OLE32.10]
1660 * the current system time in lpFileTime
1662 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1664 GetSystemTimeAsFileTime( lpFileTime );
1668 /***********************************************************************
1669 * CoTaskMemAlloc (OLE32.43)
1671 * pointer to newly allocated block
1673 LPVOID WINAPI CoTaskMemAlloc(
1674 ULONG size /* [in] size of memoryblock to be allocated */
1677 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1682 return IMalloc_Alloc(lpmalloc,size);
1684 /***********************************************************************
1685 * CoTaskMemFree (OLE32.44)
1687 VOID WINAPI CoTaskMemFree(
1688 LPVOID ptr /* [in] pointer to be freed */
1691 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1696 IMalloc_Free(lpmalloc, ptr);
1699 /***********************************************************************
1700 * CoTaskMemRealloc (OLE32.45)
1702 * pointer to newly allocated block
1704 LPVOID WINAPI CoTaskMemRealloc(
1706 ULONG size) /* [in] size of memoryblock to be allocated */
1709 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1714 return IMalloc_Realloc(lpmalloc, pvOld, size);
1717 /***********************************************************************
1718 * CoLoadLibrary (OLE32.30)
1720 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1726 TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
1728 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1733 EnterCriticalSection( &csOpenDllList );
1735 if (openDllList == NULL) {
1736 /* empty list -- add first node */
1737 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1738 openDllList->hLibrary=hLibrary;
1739 openDllList->next = NULL;
1741 /* search for this dll */
1743 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1744 if (ptr->hLibrary == hLibrary) {
1750 /* dll not found, add it */
1752 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1753 openDllList->hLibrary = hLibrary;
1754 openDllList->next = tmp;
1758 LeaveCriticalSection( &csOpenDllList );
1763 /***********************************************************************
1764 * CoInitializeWOW (OLE32.27)
1766 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1767 FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
1771 /******************************************************************************
1772 * CoLockObjectExternal [COMPOBJ.63]
1774 HRESULT WINAPI CoLockObjectExternal16(
1775 LPUNKNOWN pUnk, /* [in] object to be locked */
1776 BOOL16 fLock, /* [in] do lock */
1777 BOOL16 fLastUnlockReleases /* [in] ? */
1779 FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
1783 /******************************************************************************
1784 * CoLockObjectExternal [OLE32.31]
1786 HRESULT WINAPI CoLockObjectExternal(
1787 LPUNKNOWN pUnk, /* [in] object to be locked */
1788 BOOL fLock, /* [in] do lock */
1789 BOOL fLastUnlockReleases) /* [in] unlock all */
1795 * Increment the external lock coutner, COM_ExternalLockAddRef also
1796 * increment the object's internal lock counter.
1798 COM_ExternalLockAddRef( pUnk);
1803 * Decrement the external lock coutner, COM_ExternalLockRelease also
1804 * decrement the object's internal lock counter.
1806 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1812 /***********************************************************************
1813 * CoGetState [COMPOBJ.115]
1815 HRESULT WINAPI CoGetState16(LPDWORD state)
1817 FIXME("(%p),stub!\n", state);
1821 /***********************************************************************
1822 * CoSetState [OLE32.42]
1824 HRESULT WINAPI CoSetState(LPDWORD state)
1826 FIXME("(%p),stub!\n", state);
1827 if (state) *state = 0;
1830 /***********************************************************************
1831 * CoCreateFreeThreadedMarshaler [OLE32.5]
1833 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1835 FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
1841 /***********************************************************************
1842 * DllGetClassObject [OLE32.63]
1844 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1846 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1848 return CLASS_E_CLASSNOTAVAILABLE;
1853 * COM_RevokeAllClasses
1855 * This method is called when the COM libraries are uninitialized to
1856 * release all the references to the class objects registered with
1859 static void COM_RevokeAllClasses()
1861 EnterCriticalSection( &csRegisteredClassList );
1863 while (firstRegisteredClass!=0)
1865 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1868 LeaveCriticalSection( &csRegisteredClassList );
1871 /****************************************************************************
1872 * COM External Lock methods implementation
1875 /****************************************************************************
1876 * Public - Method that increments the count for a IUnknown* in the linked
1877 * list. The item is inserted if not already in the list.
1879 static void COM_ExternalLockAddRef(
1882 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1885 * Add an external lock to the object. If it was already externally
1886 * locked, just increase the reference count. If it was not.
1887 * add the item to the list.
1889 if ( externalLock == EL_NOT_FOUND )
1890 COM_ExternalLockInsert(pUnk);
1892 externalLock->uRefCount++;
1895 * Add an internal lock to the object
1897 IUnknown_AddRef(pUnk);
1900 /****************************************************************************
1901 * Public - Method that decrements the count for a IUnknown* in the linked
1902 * list. The item is removed from the list if its count end up at zero or if
1905 static void COM_ExternalLockRelease(
1909 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1911 if ( externalLock != EL_NOT_FOUND )
1915 externalLock->uRefCount--; /* release external locks */
1916 IUnknown_Release(pUnk); /* release local locks as well */
1918 if ( bRelAll == FALSE )
1919 break; /* perform single release */
1921 } while ( externalLock->uRefCount > 0 );
1923 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1924 COM_ExternalLockDelete(externalLock);
1927 /****************************************************************************
1928 * Public - Method that frees the content of the list.
1930 static void COM_ExternalLockFreeList()
1932 COM_ExternalLock *head;
1934 head = elList.head; /* grab it by the head */
1935 while ( head != EL_END_OF_LIST )
1937 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1939 head = elList.head; /* get the new head... */
1943 /****************************************************************************
1944 * Public - Method that dump the content of the list.
1946 void COM_ExternalLockDump()
1948 COM_ExternalLock *current = elList.head;
1950 DPRINTF("\nExternal lock list contains:\n");
1952 while ( current != EL_END_OF_LIST )
1954 DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
1956 /* Skip to the next item */
1957 current = current->next;
1962 /****************************************************************************
1963 * Internal - Find a IUnknown* in the linked list
1965 static COM_ExternalLock* COM_ExternalLockFind(
1968 return COM_ExternalLockLocate(elList.head, pUnk);
1971 /****************************************************************************
1972 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1974 static COM_ExternalLock* COM_ExternalLockLocate(
1975 COM_ExternalLock *element,
1978 if ( element == EL_END_OF_LIST )
1979 return EL_NOT_FOUND;
1981 else if ( element->pUnk == pUnk ) /* We found it */
1984 else /* Not the right guy, keep on looking */
1985 return COM_ExternalLockLocate( element->next, pUnk);
1988 /****************************************************************************
1989 * Internal - Insert a new IUnknown* to the linked list
1991 static BOOL COM_ExternalLockInsert(
1994 COM_ExternalLock *newLock = NULL;
1995 COM_ExternalLock *previousHead = NULL;
1998 * Allocate space for the new storage object
2000 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
2004 if ( elList.head == EL_END_OF_LIST )
2006 elList.head = newLock; /* The list is empty */
2011 * insert does it at the head
2013 previousHead = elList.head;
2014 elList.head = newLock;
2018 * Set new list item data member
2020 newLock->pUnk = pUnk;
2021 newLock->uRefCount = 1;
2022 newLock->next = previousHead;
2030 /****************************************************************************
2031 * Internal - Method that removes an item from the linked list.
2033 static void COM_ExternalLockDelete(
2034 COM_ExternalLock *itemList)
2036 COM_ExternalLock *current = elList.head;
2038 if ( current == itemList )
2041 * this section handles the deletion of the first node
2043 elList.head = itemList->next;
2044 HeapFree( GetProcessHeap(), 0, itemList);
2050 if ( current->next == itemList ) /* We found the item to free */
2052 current->next = itemList->next; /* readjust the list pointers */
2054 HeapFree( GetProcessHeap(), 0, itemList);
2058 /* Skip to the next item */
2059 current = current->next;
2061 } while ( current != EL_END_OF_LIST );
2065 /***********************************************************************
2066 * DllEntryPoint [COMPOBJ.116]
2068 * Initialization code for the COMPOBJ DLL
2072 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
2074 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
2078 case DLL_PROCESS_ATTACH:
2079 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
2082 case DLL_PROCESS_DETACH:
2083 if(!--COMPOBJ_Attach)
2084 COMPOBJ_hInstance = 0;
2090 /******************************************************************************
2091 * OleGetAutoConvert [OLE32.104]
2093 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2101 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2102 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2104 res = REGDB_E_CLASSNOTREG;
2108 /* we can just query for the default value of AutoConvertTo key like that,
2109 without opening the AutoConvertTo key and querying for NULL (default) */
2110 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
2112 res = REGDB_E_KEYMISSING;
2115 MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
2116 CLSIDFromString(wbuf,pClsidNew);
2118 if (hkey) RegCloseKey(hkey);
2123 /******************************************************************************
2124 * OleSetAutoConvert [OLE32.126]
2126 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2129 char buf[200], szClsidNew[200];
2132 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2133 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2134 WINE_StringFromCLSID(clsidNew, szClsidNew);
2135 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2137 res = REGDB_E_CLASSNOTREG;
2140 if (RegSetValueA(hkey, "AutoConvertTo", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
2142 res = REGDB_E_WRITEREGDB;
2147 if (hkey) RegCloseKey(hkey);
2151 /******************************************************************************
2152 * CoTreatAsClass [OLE32.46]
2154 HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
2157 char buf[200], szClsidNew[200];
2160 FIXME("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2161 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2162 WINE_StringFromCLSID(clsidNew, szClsidNew);
2163 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2165 res = REGDB_E_CLASSNOTREG;
2168 if (RegSetValueA(hkey, "AutoTreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
2170 res = REGDB_E_WRITEREGDB;
2175 if (hkey) RegCloseKey(hkey);
2180 /***********************************************************************
2181 * IsEqualGUID [OLE32.76]
2183 * Compares two Unique Identifiers.
2189 BOOL WINAPI IsEqualGUID(
2190 REFGUID rguid1, /* [in] unique id 1 */
2191 REFGUID rguid2 /* [in] unique id 2 */
2194 return !memcmp(rguid1,rguid2,sizeof(GUID));