4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
19 #include "wine/winbase16.h"
21 #include "wine/winestring.h"
24 #include "debugtools.h"
30 #include "wine/obj_base.h"
31 #include "wine/obj_misc.h"
32 #include "wine/obj_storage.h"
33 #include "wine/obj_clientserver.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 ULONG 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 RegisteredClass* firstRegisteredClass = NULL;
147 /* this open DLL table belongs in a per process table, but my guess is that
148 * it shouldn't live in the kernel, so I'll put them out here in DLL
149 * space assuming that there is one OLE32 per process.
151 typedef struct tagOpenDll {
153 struct tagOpenDll *next;
156 static OpenDll *openDllList = NULL; /* linked list of open dlls */
158 /*****************************************************************************
159 * This section contains prototypes to internal methods for this
162 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
166 static void COM_RevokeAllClasses();
169 /******************************************************************************
170 * CoBuildVersion [COMPOBJ.1]
173 * Current build version, hiword is majornumber, loword is minornumber
175 DWORD WINAPI CoBuildVersion(void)
177 TRACE("Returning version %d, build %d.\n", rmm, rup);
178 return (rmm<<16)+rup;
181 /******************************************************************************
182 * CoInitialize16 [COMPOBJ.2]
183 * Set the win16 IMalloc used for memory management
185 HRESULT WINAPI CoInitialize16(
186 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
188 currentMalloc16 = (LPMALLOC16)lpReserved;
192 /******************************************************************************
193 * CoInitialize [OLE32.26]
195 * Initializes the COM libraries.
199 HRESULT WINAPI CoInitialize(
200 LPVOID lpReserved /* [in] pointer to win32 malloc interface
201 (obsolete, should be NULL) */
205 * Just delegate to the newer method.
207 return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
210 /******************************************************************************
211 * CoInitializeEx [OLE32.163]
213 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
214 * used for memory management is obsolete.
217 * S_OK if successful,
218 * S_FALSE if this function was called already.
219 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
223 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
226 * See the windows documentation for more details.
228 HRESULT WINAPI CoInitializeEx(
229 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
230 (obsolete, should be NULL) */
231 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
236 TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
238 if (lpReserved!=NULL)
240 ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
244 * Check for unsupported features.
246 if (dwCoInit!=COINIT_APARTMENTTHREADED)
248 FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
249 /* Hope for the best and continue anyway */
253 * Check the lock count. If this is the first time going through the initialize
254 * process, we have to initialize the libraries.
256 if (s_COMLockCount==0)
259 * Initialize the various COM libraries and data structures.
261 TRACE("() - Initializing the COM libraries\n");
263 RunningObjectTableImpl_Initialize();
271 * Crank-up that lock count.
278 /***********************************************************************
279 * CoUninitialize16 [COMPOBJ.3]
280 * Don't know what it does.
281 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
282 * believe is the correct spelling
284 void WINAPI CoUninitialize16(void)
287 CoFreeAllLibraries();
290 /***********************************************************************
291 * CoUninitialize [OLE32.47]
293 * This method will release the COM libraries.
295 * See the windows documentation for more details.
297 void WINAPI CoUninitialize(void)
302 * Decrease the reference count.
307 * If we are back to 0 locks on the COM library, make sure we free
308 * all the associated data structures.
310 if (s_COMLockCount==0)
313 * Release the various COM libraries and data structures.
315 TRACE("() - Releasing the COM libraries\n");
317 RunningObjectTableImpl_UnInitialize();
319 * Release the references to the registered class objects.
321 COM_RevokeAllClasses();
324 * This will free the loaded COM Dlls.
326 CoFreeAllLibraries();
329 * This will free list of external references to COM objects.
331 COM_ExternalLockFreeList();
335 /***********************************************************************
336 * CoGetMalloc16 [COMPOBJ.4]
338 * The current win16 IMalloc
340 HRESULT WINAPI CoGetMalloc16(
341 DWORD dwMemContext, /* [in] unknown */
342 LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
345 currentMalloc16 = IMalloc16_Constructor();
346 *lpMalloc = currentMalloc16;
350 /******************************************************************************
351 * CoGetMalloc [OLE32.20]
354 * The current win32 IMalloc
356 HRESULT WINAPI CoGetMalloc(
357 DWORD dwMemContext, /* [in] unknown */
358 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
361 currentMalloc32 = IMalloc_Constructor();
362 *lpMalloc = currentMalloc32;
366 /***********************************************************************
367 * CoCreateStandardMalloc16 [COMPOBJ.71]
369 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
370 LPMALLOC16 *lpMalloc)
372 /* FIXME: docu says we shouldn't return the same allocator as in
374 *lpMalloc = IMalloc16_Constructor();
378 /******************************************************************************
379 * CoDisconnectObject [COMPOBJ.15]
381 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
383 TRACE("(%p, %lx)\n",lpUnk,reserved);
387 /***********************************************************************
388 * IsEqualGUID16 [COMPOBJ.18]
390 * Compares two Unique Identifiers.
395 BOOL16 WINAPI IsEqualGUID16(
396 GUID* g1, /* [in] unique id 1 */
397 GUID* g2 /* [in] unique id 2 */
399 return !memcmp( g1, g2, sizeof(GUID) );
402 /******************************************************************************
403 * CLSIDFromString16 [COMPOBJ.20]
404 * Converts a unique identifier from its string representation into
407 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
412 HRESULT WINAPI CLSIDFromString16(
413 LPCOLESTR16 idstr, /* [in] string representation of guid */
414 CLSID *id /* [out] GUID converted from string */
416 BYTE *s = (BYTE *) idstr;
422 s = "{00000000-0000-0000-0000-000000000000}";
423 else { /* validate the CLSID string */
426 return CO_E_CLASSSTRING;
428 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
429 return CO_E_CLASSSTRING;
433 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
434 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
435 ((s[i] >= 'a') && (s[i] <= 'f')) ||
436 ((s[i] >= 'A') && (s[i] <= 'F')))
438 return CO_E_CLASSSTRING;
442 TRACE("%s -> %p\n", s, id);
444 /* quick lookup table */
445 memset(table, 0, 256);
447 for (i = 0; i < 10; i++) {
450 for (i = 0; i < 6; i++) {
451 table['A' + i] = i+10;
452 table['a' + i] = i+10;
455 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
459 s++; /* skip leading brace */
460 for (i = 0; i < 4; i++) {
461 p[3 - i] = table[*s]<<4 | table[*(s+1)];
467 for (i = 0; i < 2; i++) {
468 p[1-i] = table[*s]<<4 | table[*(s+1)];
474 for (i = 0; i < 2; i++) {
475 p[1-i] = table[*s]<<4 | table[*(s+1)];
481 /* these are just sequential bytes */
482 for (i = 0; i < 2; i++) {
483 *p++ = table[*s]<<4 | table[*(s+1)];
488 for (i = 0; i < 6; i++) {
489 *p++ = table[*s]<<4 | table[*(s+1)];
496 /******************************************************************************
497 * CoCreateGuid[OLE32.6]
500 HRESULT WINAPI CoCreateGuid(
501 GUID *pguid /* [out] points to the GUID to initialize */
503 return UuidCreate(pguid);
506 /******************************************************************************
507 * CLSIDFromString [OLE32.3]
508 * Converts a unique identifier from its string representation into
512 * If idstr is not a valid CLSID string then it gets treated as a ProgID
517 HRESULT WINAPI CLSIDFromString(
518 LPCOLESTR idstr, /* [in] string representation of GUID */
519 CLSID *id /* [out] GUID represented by above string */
521 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
522 HRESULT ret = CLSIDFromString16(xid,id);
524 HeapFree(GetProcessHeap(),0,xid);
525 if(ret != S_OK) { /* It appears a ProgID is also valid */
526 ret = CLSIDFromProgID(idstr, id);
531 /******************************************************************************
532 * WINE_StringFromCLSID [Internal]
533 * Converts a GUID into the respective string representation.
538 * the string representation and HRESULT
540 static HRESULT WINE_StringFromCLSID(
541 const CLSID *id, /* [in] GUID to be converted */
542 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
544 static const char *hex = "0123456789ABCDEF";
549 { ERR("called with id=Null\n");
554 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
555 id->Data1, id->Data2, id->Data3,
556 id->Data4[0], id->Data4[1]);
560 for (i = 2; i < 8; i++) {
561 *s++ = hex[id->Data4[i]>>4];
562 *s++ = hex[id->Data4[i] & 0xf];
568 TRACE("%p->%s\n", id, idstr);
573 /******************************************************************************
574 * StringFromCLSID16 [COMPOBJ.19]
575 * Converts a GUID into the respective string representation.
576 * The target string is allocated using the OLE IMalloc.
578 * the string representation and HRESULT
580 HRESULT WINAPI StringFromCLSID16(
581 REFCLSID id, /* [in] the GUID to be converted */
582 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
589 ret = CoGetMalloc16(0,&mllc);
592 args[0] = (DWORD)mllc;
595 /* No need for a Callback entry, we have WOWCallback16Ex which does
596 * everything we need.
598 if (!WOWCallback16Ex(
599 (DWORD)((ICOM_VTABLE(IMalloc16)*)PTR_SEG_TO_LIN(
600 ICOM_VTBL(((LPMALLOC16)PTR_SEG_TO_LIN(mllc))))
607 WARN("CallTo16 IMalloc16 failed\n");
610 return WINE_StringFromCLSID(id,PTR_SEG_TO_LIN(*idstr));
613 /******************************************************************************
614 * StringFromCLSID [OLE32.151]
615 * Converts a GUID into the respective string representation.
616 * The target string is allocated using the OLE IMalloc.
618 * the string representation and HRESULT
620 HRESULT WINAPI StringFromCLSID(
621 REFCLSID id, /* [in] the GUID to be converted */
622 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
628 if ((ret=CoGetMalloc(0,&mllc)))
631 ret=WINE_StringFromCLSID(id,buf);
633 *idstr = IMalloc_Alloc(mllc,strlen(buf)*2+2);
634 lstrcpyAtoW(*idstr,buf);
639 /******************************************************************************
640 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
642 * Converts a global unique identifier into a string of an API-
643 * specified fixed format. (The usual {.....} stuff.)
646 * The (UNICODE) string representation of the GUID in 'str'
647 * The length of the resulting string, 0 if there was any problem.
650 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
654 if (WINE_StringFromCLSID(id,xguid))
656 if (strlen(xguid)>=cmax)
658 lstrcpyAtoW(str,xguid);
659 return strlen(xguid) + 1;
662 /******************************************************************************
663 * ProgIDFromCLSID [OLE32.133]
664 * Converts a class id into the respective Program ID. (By using a registry lookup)
665 * RETURNS S_OK on success
666 * riid associated with the progid
669 HRESULT WINAPI ProgIDFromCLSID(
670 REFCLSID clsid, /* [in] class id as found in registry */
671 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
674 char strCLSID[50], *buf, *buf2;
680 WINE_StringFromCLSID(clsid, strCLSID);
682 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
683 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
684 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
685 ret = REGDB_E_CLASSNOTREG;
687 HeapFree(GetProcessHeap(), 0, buf);
691 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
693 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
694 ret = REGDB_E_CLASSNOTREG;
698 if (CoGetMalloc(0,&mllc))
702 *lplpszProgID = IMalloc_Alloc(mllc, (buf2len+1)*2);
703 lstrcpyAtoW(*lplpszProgID, buf2);
706 HeapFree(GetProcessHeap(), 0, buf2);
713 /******************************************************************************
714 * CLSIDFromProgID16 [COMPOBJ.61]
715 * Converts a program id into the respective GUID. (By using a registry lookup)
717 * riid associated with the progid
719 HRESULT WINAPI CLSIDFromProgID16(
720 LPCOLESTR16 progid, /* [in] program id as found in registry */
721 LPCLSID riid /* [out] associated CLSID */
728 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
729 sprintf(buf,"%s\\CLSID",progid);
730 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
731 HeapFree(GetProcessHeap(),0,buf);
732 return CO_E_CLASSSTRING;
734 HeapFree(GetProcessHeap(),0,buf);
735 buf2len = sizeof(buf2);
736 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
738 return CO_E_CLASSSTRING;
741 return CLSIDFromString16(buf2,riid);
744 /******************************************************************************
745 * CLSIDFromProgID [OLE32.2]
746 * Converts a program id into the respective GUID. (By using a registry lookup)
748 * riid associated with the progid
750 HRESULT WINAPI CLSIDFromProgID(
751 LPCOLESTR progid, /* [in] program id as found in registry */
752 LPCLSID riid /* [out] associated CLSID */
754 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
755 HRESULT ret = CLSIDFromProgID16(pid,riid);
757 HeapFree(GetProcessHeap(),0,pid);
763 /*****************************************************************************
764 * CoGetPSClsid [OLE32.22]
766 * This function returns the CLSID of the DLL that implements the proxy and stub
767 * for the specified interface.
769 * It determines this by searching the
770 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
771 * and any interface id registered by CoRegisterPSClsid within the current process.
773 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
775 HRESULT WINAPI CoGetPSClsid(
776 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
777 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
783 TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
785 /* Get the input iid as a string */
786 WINE_StringFromCLSID(riid, buf2);
787 /* Allocate memory for the registry key we will construct.
788 (length of iid string plus constant length of static text */
789 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
792 return (E_OUTOFMEMORY);
795 /* Construct the registry key we want */
796 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
799 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
801 HeapFree(GetProcessHeap(),0,buf);
802 return (E_INVALIDARG);
804 HeapFree(GetProcessHeap(),0,buf);
806 /* ... Once we have the key, query the registry to get the
807 value of CLSID as a string, and convert it into a
808 proper CLSID structure to be passed back to the app */
809 buf2len = sizeof(buf2);
810 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
817 /* We have the CLSid we want back from the registry as a string, so
818 lets convert it into a CLSID structure */
819 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
824 TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
830 /***********************************************************************
833 * This function write a CLSID on stream
835 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
837 TRACE("(%p,%p)\n",pStm,rclsid);
842 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
845 /***********************************************************************
848 * This function read a CLSID from a stream
850 HRESULT WINAPI ReadClassStm(IStream *pStm,REFCLSID rclsid)
855 TRACE("(%p,%p)\n",pStm,rclsid);
860 res = IStream_Read(pStm,(void*)rclsid,sizeof(CLSID),&nbByte);
865 if (nbByte != sizeof(CLSID))
871 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
872 /***********************************************************************
873 * LookupETask (COMPOBJ.94)
875 HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
876 FIXME("(%p,%p),stub!\n",hTask,p);
877 if ((*hTask = GetCurrentTask()) == hETask) {
878 memcpy(p, Table_ETask, sizeof(Table_ETask));
883 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
884 /***********************************************************************
885 * SetETask (COMPOBJ.95)
887 HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
888 FIXME("(%04x,%p),stub!\n",hTask,p);
893 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
894 /***********************************************************************
895 * CallObjectInWOW (COMPOBJ.201)
897 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
898 FIXME("(%p,%p),stub!\n",p1,p2);
902 /******************************************************************************
903 * CoRegisterClassObject16 [COMPOBJ.5]
905 * Don't know where it registers it ...
907 HRESULT WINAPI CoRegisterClassObject16(
910 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
911 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
916 WINE_StringFromCLSID(rclsid,buf);
918 FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
919 buf,pUnk,dwClsContext,flags,lpdwRegister
925 /******************************************************************************
926 * CoRevokeClassObject16 [COMPOBJ.6]
929 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister /* token on class obj */)
931 FIXME("(0x%08lx),stub!\n", dwRegister);
937 * COM_GetRegisteredClassObject
939 * This internal method is used to scan the registered class list to
940 * find a class object.
943 * rclsid Class ID of the class to find.
944 * dwClsContext Class context to match.
945 * ppv [out] returns a pointer to the class object. Complying
946 * to normal COM usage, this method will increase the
947 * reference count on this object.
949 static HRESULT COM_GetRegisteredClassObject(
954 RegisteredClass* curClass;
962 * Iterate through the whole list and try to match the class ID.
964 curClass = firstRegisteredClass;
966 while (curClass != 0)
969 * Check if we have a match on the class ID.
971 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
974 * Since we don't do out-of process or DCOM just right away, let's ignore the
979 * We have a match, return the pointer to the class object.
981 *ppUnk = curClass->classObject;
983 IUnknown_AddRef(curClass->classObject);
989 * Step to the next class in the list.
991 curClass = curClass->nextClass;
995 * If we get to here, we haven't found our class.
1000 /******************************************************************************
1001 * CoRegisterClassObject [OLE32.36]
1003 * This method will register the class object for a given class ID.
1005 * See the Windows documentation for more details.
1007 HRESULT WINAPI CoRegisterClassObject(
1010 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
1011 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1012 LPDWORD lpdwRegister
1015 RegisteredClass* newClass;
1016 LPUNKNOWN foundObject;
1020 WINE_StringFromCLSID(rclsid,buf);
1022 TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1023 buf,pUnk,dwClsContext,flags,lpdwRegister);
1026 * Perform a sanity check on the parameters
1028 if ( (lpdwRegister==0) || (pUnk==0) )
1030 return E_INVALIDARG;
1034 * Initialize the cookie (out parameter)
1039 * First, check if the class is already registered.
1040 * If it is, this should cause an error.
1042 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1047 * The COM_GetRegisteredClassObject increased the reference count on the
1048 * object so it has to be released.
1050 IUnknown_Release(foundObject);
1052 return CO_E_OBJISREG;
1056 * If it is not registered, we must create a new entry for this class and
1057 * append it to the registered class list.
1058 * We use the address of the chain node as the cookie since we are sure it's
1061 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1064 * Initialize the node.
1066 newClass->classIdentifier = *rclsid;
1067 newClass->runContext = dwClsContext;
1068 newClass->connectFlags = flags;
1069 newClass->dwCookie = (DWORD)newClass;
1070 newClass->nextClass = firstRegisteredClass;
1073 * Since we're making a copy of the object pointer, we have to increase its
1076 newClass->classObject = pUnk;
1077 IUnknown_AddRef(newClass->classObject);
1079 firstRegisteredClass = newClass;
1082 * Assign the out parameter (cookie)
1084 *lpdwRegister = newClass->dwCookie;
1087 * We're successful Yippee!
1092 /***********************************************************************
1093 * CoRevokeClassObject [OLE32.40]
1095 * This method will remove a class object from the class registry
1097 * See the Windows documentation for more details.
1099 HRESULT WINAPI CoRevokeClassObject(
1102 RegisteredClass** prevClassLink;
1103 RegisteredClass* curClass;
1105 TRACE("(%08lx)\n",dwRegister);
1108 * Iterate through the whole list and try to match the cookie.
1110 curClass = firstRegisteredClass;
1111 prevClassLink = &firstRegisteredClass;
1113 while (curClass != 0)
1116 * Check if we have a match on the cookie.
1118 if (curClass->dwCookie == dwRegister)
1121 * Remove the class from the chain.
1123 *prevClassLink = curClass->nextClass;
1126 * Release the reference to the class object.
1128 IUnknown_Release(curClass->classObject);
1131 * Free the memory used by the chain node.
1133 HeapFree(GetProcessHeap(), 0, curClass);
1139 * Step to the next class in the list.
1141 prevClassLink = &(curClass->nextClass);
1142 curClass = curClass->nextClass;
1146 * If we get to here, we haven't found our class.
1148 return E_INVALIDARG;
1151 /***********************************************************************
1152 * CoGetClassObject [COMPOBJ.7]
1154 HRESULT WINAPI CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext,
1155 LPVOID pvReserved, REFIID iid, LPVOID *ppv)
1157 LPUNKNOWN regClassObject;
1158 HRESULT hres = E_UNEXPECTED;
1160 WCHAR dllName[MAX_PATH+1];
1161 DWORD dllNameLen = sizeof(dllName);
1163 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid,
1164 REFIID iid, LPVOID *ppv);
1165 DllGetClassObjectFunc DllGetClassObject;
1167 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1169 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1170 debugstr_guid(rclsid),
1175 * First, try and see if we can't match the class ID with one of the
1176 * registered classes.
1178 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1181 * Get the required interface from the retrieved pointer.
1183 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1186 * Since QI got another reference on the pointer, we want to release the
1187 * one we already have. If QI was unsuccessful, this will release the object. This
1188 * is good since we are not returning it in the "out" parameter.
1190 IUnknown_Release(regClassObject);
1195 /* out of process and remote servers not supported yet */
1196 if (((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1197 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)){
1198 FIXME("CLSCTX_LOCAL_SERVER and CLSCTX_REMOTE_SERVER not supported!\n");
1199 return E_ACCESSDENIED;
1202 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1204 WCHAR valname[]={ 'I','n','p','r','o','c',
1205 'S','e','r','v','e','r','3','2',0};
1207 /* lookup CLSID in registry key HKCR/CLSID */
1208 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0,
1209 KEY_READ, &CLSIDkey);
1211 if (hres != ERROR_SUCCESS)
1212 return REGDB_E_READREGDB;
1213 hres = RegOpenKeyExA(CLSIDkey,xclsid,0,KEY_QUERY_VALUE,&key);
1214 if (hres != ERROR_SUCCESS) {
1215 RegCloseKey(CLSIDkey);
1216 return REGDB_E_CLASSNOTREG;
1218 memset(dllName,0,sizeof(dllName));
1219 hres = RegQueryValueW(key, valname, dllName, &dllNameLen);
1221 ERR("RegQueryValue of %s failed with hres %lx\n",debugstr_w(dllName),hres);
1222 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1225 RegCloseKey(CLSIDkey);
1226 if (hres != ERROR_SUCCESS)
1227 return REGDB_E_READREGDB;
1228 TRACE("found InprocServer32 dll %s\n", debugstr_w(dllName));
1230 /* open dll, call DllGetClassObject */
1231 hLibrary = CoLoadLibrary(dllName, TRUE);
1232 if (hLibrary == 0) {
1233 FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(dllName));
1234 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1236 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1237 if (!DllGetClassObject) {
1238 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1239 FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(dllName));
1240 return E_ACCESSDENIED;
1244 * Ask the DLL for its class object. (there was a note here about class
1245 * factories but this is good.
1247 return DllGetClassObject(rclsid, iid, ppv);
1252 /***********************************************************************
1253 * CoResumeClassObjects
1255 * Resumes classobjects registered with REGCLS suspended
1257 HRESULT WINAPI CoResumeClassObjects(void)
1263 /***********************************************************************
1266 * This function supplies the CLSID associated with the given filename.
1268 HRESULT WINAPI GetClassFile(LPOLESTR filePathName,CLSID *pclsid)
1272 int nbElm=0,length=0,i=0;
1274 LPOLESTR *pathDec=0,absFile=0,progId=0;
1275 WCHAR extention[100]={0};
1279 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1280 if((StgIsStorageFile(filePathName))==S_OK){
1282 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1285 res=ReadClassStg(pstg,pclsid);
1287 IStorage_Release(pstg);
1291 /* if the file is not a storage object then attemps to match various bits in the file against a
1292 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1295 for(i=0;i<nFileTypes;i++)
1297 for(i=0;j<nPatternsForType;j++){
1302 pat=ReadPatternFromRegistry(i,j);
1303 hFile=CreateFileW(filePathName,,,,,,hFile);
1304 SetFilePosition(hFile,pat.offset);
1305 ReadFile(hFile,buf,pat.size,NULL,NULL);
1306 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1308 *pclsid=ReadCLSIDFromRegistry(i);
1314 /* if the obove strategies fail then search for the extension key in the registry */
1316 /* get the last element (absolute file) in the path name */
1317 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1318 absFile=pathDec[nbElm-1];
1320 /* failed if the path represente a directory and not an absolute file name*/
1321 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1322 return MK_E_INVALIDEXTENSION;
1324 /* get the extension of the file */
1325 length=lstrlenW(absFile);
1326 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1328 /* get the progId associated to the extension */
1329 progId=CoTaskMemAlloc(sizeProgId);
1331 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1333 if (res==ERROR_MORE_DATA){
1335 progId = CoTaskMemRealloc(progId,sizeProgId);
1336 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1338 if (res==ERROR_SUCCESS)
1339 /* return the clsid associated to the progId */
1340 res= CLSIDFromProgID(progId,pclsid);
1342 for(i=0; pathDec[i]!=NULL;i++)
1343 CoTaskMemFree(pathDec[i]);
1344 CoTaskMemFree(pathDec);
1346 CoTaskMemFree(progId);
1348 if (res==ERROR_SUCCESS)
1351 return MK_E_INVALIDEXTENSION;
1353 /******************************************************************************
1354 * CoRegisterMessageFilter16 [COMPOBJ.27]
1356 HRESULT WINAPI CoRegisterMessageFilter16(
1357 LPMESSAGEFILTER lpMessageFilter,
1358 LPMESSAGEFILTER *lplpMessageFilter
1360 FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
1364 /***********************************************************************
1365 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1367 HRESULT WINAPI CoCreateInstance(
1369 LPUNKNOWN pUnkOuter,
1375 LPCLASSFACTORY lpclf = 0;
1384 * Initialize the "out" parameter
1389 * Get a class factory to construct the object we want.
1391 hres = CoGetClassObject(rclsid,
1401 * Create the object and don't forget to release the factory
1403 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1404 IClassFactory_Release(lpclf);
1409 /***********************************************************************
1410 * CoCreateInstanceEx [OLE32.165]
1412 HRESULT WINAPI CoCreateInstanceEx(
1414 LPUNKNOWN pUnkOuter,
1416 COSERVERINFO* pServerInfo,
1420 IUnknown* pUnk = NULL;
1423 int successCount = 0;
1428 if ( (cmq==0) || (pResults==NULL))
1429 return E_INVALIDARG;
1431 if (pServerInfo!=NULL)
1432 FIXME("() non-NULL pServerInfo not supported!\n");
1435 * Initialize all the "out" parameters.
1437 for (index = 0; index < cmq; index++)
1439 pResults[index].pItf = NULL;
1440 pResults[index].hr = E_NOINTERFACE;
1444 * Get the object and get its IUnknown pointer.
1446 hr = CoCreateInstance(rclsid,
1456 * Then, query for all the interfaces requested.
1458 for (index = 0; index < cmq; index++)
1460 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1461 pResults[index].pIID,
1462 (VOID**)&(pResults[index].pItf));
1464 if (pResults[index].hr == S_OK)
1469 * Release our temporary unknown pointer.
1471 IUnknown_Release(pUnk);
1473 if (successCount == 0)
1474 return E_NOINTERFACE;
1476 if (successCount!=cmq)
1477 return CO_S_NOTALLINTERFACES;
1482 /***********************************************************************
1483 * CoFreeLibrary [COMPOBJ.13]
1485 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1487 OpenDll *ptr, *prev;
1490 /* lookup library in linked list */
1492 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1493 if (ptr->hLibrary == hLibrary) {
1500 /* shouldn't happen if user passed in a valid hLibrary */
1503 /* assert: ptr points to the library entry to free */
1505 /* free library and remove node from list */
1506 FreeLibrary(hLibrary);
1507 if (ptr == openDllList) {
1508 tmp = openDllList->next;
1509 HeapFree(GetProcessHeap(), 0, openDllList);
1513 HeapFree(GetProcessHeap(), 0, ptr);
1520 /***********************************************************************
1521 * CoFreeAllLibraries [COMPOBJ.12]
1523 void WINAPI CoFreeAllLibraries(void)
1527 for (ptr = openDllList; ptr != NULL; ) {
1529 CoFreeLibrary(ptr->hLibrary);
1536 /***********************************************************************
1537 * CoFreeUnusedLibraries [COMPOBJ.17]
1539 void WINAPI CoFreeUnusedLibraries(void)
1542 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1543 DllCanUnloadNowFunc DllCanUnloadNow;
1545 for (ptr = openDllList; ptr != NULL; ) {
1546 DllCanUnloadNow = (DllCanUnloadNowFunc)
1547 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1549 if ( (DllCanUnloadNow != NULL) &&
1550 (DllCanUnloadNow() == S_OK) ) {
1552 CoFreeLibrary(ptr->hLibrary);
1560 /***********************************************************************
1561 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1563 * the current system time in lpFileTime
1565 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1567 GetSystemTimeAsFileTime( lpFileTime );
1571 /***********************************************************************
1572 * CoTaskMemAlloc (OLE32.43)
1574 * pointer to newly allocated block
1576 LPVOID WINAPI CoTaskMemAlloc(
1577 ULONG size /* [in] size of memoryblock to be allocated */
1580 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1585 return IMalloc_Alloc(lpmalloc,size);
1587 /***********************************************************************
1588 * CoTaskMemFree (OLE32.44)
1590 VOID WINAPI CoTaskMemFree(
1591 LPVOID ptr /* [in] pointer to be freed */
1594 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1599 IMalloc_Free(lpmalloc, ptr);
1602 /***********************************************************************
1603 * CoTaskMemRealloc (OLE32.45)
1605 * pointer to newly allocated block
1607 LPVOID WINAPI CoTaskMemRealloc(
1609 ULONG size) /* [in] size of memoryblock to be allocated */
1612 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1617 return IMalloc_Realloc(lpmalloc, pvOld, size);
1620 /***********************************************************************
1621 * CoLoadLibrary (OLE32.30)
1623 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1629 TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
1631 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1636 if (openDllList == NULL) {
1637 /* empty list -- add first node */
1638 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1639 openDllList->hLibrary=hLibrary;
1640 openDllList->next = NULL;
1642 /* search for this dll */
1644 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1645 if (ptr->hLibrary == hLibrary) {
1651 /* dll not found, add it */
1653 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1654 openDllList->hLibrary = hLibrary;
1655 openDllList->next = tmp;
1662 /***********************************************************************
1663 * CoInitializeWOW (OLE32.27)
1665 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1666 FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
1670 /******************************************************************************
1671 * CoLockObjectExternal16 [COMPOBJ.63]
1673 HRESULT WINAPI CoLockObjectExternal16(
1674 LPUNKNOWN pUnk, /* [in] object to be locked */
1675 BOOL16 fLock, /* [in] do lock */
1676 BOOL16 fLastUnlockReleases /* [in] ? */
1678 FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
1682 /******************************************************************************
1683 * CoLockObjectExternal [OLE32.31]
1685 HRESULT WINAPI CoLockObjectExternal(
1686 LPUNKNOWN pUnk, /* [in] object to be locked */
1687 BOOL fLock, /* [in] do lock */
1688 BOOL fLastUnlockReleases) /* [in] unlock all */
1694 * Increment the external lock coutner, COM_ExternalLockAddRef also
1695 * increment the object's internal lock counter.
1697 COM_ExternalLockAddRef( pUnk);
1702 * Decrement the external lock coutner, COM_ExternalLockRelease also
1703 * decrement the object's internal lock counter.
1705 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1711 /***********************************************************************
1712 * CoGetState16 [COMPOBJ.115]
1714 HRESULT WINAPI CoGetState16(LPDWORD state)
1716 FIXME("(%p),stub!\n", state);
1720 /***********************************************************************
1721 * CoSetState [COM32.42]
1723 HRESULT WINAPI CoSetState(LPDWORD state)
1725 FIXME("(%p),stub!\n", state);
1726 if (state) *state = 0;
1729 /***********************************************************************
1730 * CoCreateFreeThreadedMarshaler [OLE32.5]
1732 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1734 FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
1740 /***********************************************************************
1741 * DllGetClassObject [OLE32.63]
1743 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1745 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
1747 return CLASS_E_CLASSNOTAVAILABLE;
1752 * COM_RevokeAllClasses
1754 * This method is called when the COM libraries are uninitialized to
1755 * release all the references to the class objects registered with
1758 static void COM_RevokeAllClasses()
1760 while (firstRegisteredClass!=0)
1762 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1766 /****************************************************************************
1767 * COM External Lock methods implementation
1770 /****************************************************************************
1771 * Public - Method that increments the count for a IUnknown* in the linked
1772 * list. The item is inserted if not already in the list.
1774 static void COM_ExternalLockAddRef(
1777 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1780 * Add an external lock to the object. If it was already externally
1781 * locked, just increase the reference count. If it was not.
1782 * add the item to the list.
1784 if ( externalLock == EL_NOT_FOUND )
1785 COM_ExternalLockInsert(pUnk);
1787 externalLock->uRefCount++;
1790 * Add an internal lock to the object
1792 IUnknown_AddRef(pUnk);
1795 /****************************************************************************
1796 * Public - Method that decrements the count for a IUnknown* in the linked
1797 * list. The item is removed from the list if its count end up at zero or if
1800 static void COM_ExternalLockRelease(
1804 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1806 if ( externalLock != EL_NOT_FOUND )
1810 externalLock->uRefCount--; /* release external locks */
1811 IUnknown_Release(pUnk); /* release local locks as well */
1813 if ( bRelAll == FALSE )
1814 break; /* perform single release */
1816 } while ( externalLock->uRefCount > 0 );
1818 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1819 COM_ExternalLockDelete(externalLock);
1822 /****************************************************************************
1823 * Public - Method that frees the content of the list.
1825 static void COM_ExternalLockFreeList()
1827 COM_ExternalLock *head;
1829 head = elList.head; /* grab it by the head */
1830 while ( head != EL_END_OF_LIST )
1832 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1834 head = elList.head; /* get the new head... */
1838 /****************************************************************************
1839 * Public - Method that dump the content of the list.
1841 void COM_ExternalLockDump()
1843 COM_ExternalLock *current = elList.head;
1845 DPRINTF("\nExternal lock list contains:\n");
1847 while ( current != EL_END_OF_LIST )
1849 DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
1851 /* Skip to the next item */
1852 current = current->next;
1857 /****************************************************************************
1858 * Internal - Find a IUnknown* in the linked list
1860 static COM_ExternalLock* COM_ExternalLockFind(
1863 return COM_ExternalLockLocate(elList.head, pUnk);
1866 /****************************************************************************
1867 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1869 static COM_ExternalLock* COM_ExternalLockLocate(
1870 COM_ExternalLock *element,
1873 if ( element == EL_END_OF_LIST )
1874 return EL_NOT_FOUND;
1876 else if ( element->pUnk == pUnk ) /* We found it */
1879 else /* Not the right guy, keep on looking */
1880 return COM_ExternalLockLocate( element->next, pUnk);
1883 /****************************************************************************
1884 * Internal - Insert a new IUnknown* to the linked list
1886 static BOOL COM_ExternalLockInsert(
1889 COM_ExternalLock *newLock = NULL;
1890 COM_ExternalLock *previousHead = NULL;
1893 * Allocate space for the new storage object
1895 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
1899 if ( elList.head == EL_END_OF_LIST )
1901 elList.head = newLock; /* The list is empty */
1906 * insert does it at the head
1908 previousHead = elList.head;
1909 elList.head = newLock;
1913 * Set new list item data member
1915 newLock->pUnk = pUnk;
1916 newLock->uRefCount = 1;
1917 newLock->next = previousHead;
1925 /****************************************************************************
1926 * Internal - Method that removes an item from the linked list.
1928 static void COM_ExternalLockDelete(
1929 COM_ExternalLock *itemList)
1931 COM_ExternalLock *current = elList.head;
1933 if ( current == itemList )
1936 * this section handles the deletion of the first node
1938 elList.head = itemList->next;
1939 HeapFree( GetProcessHeap(), 0, itemList);
1945 if ( current->next == itemList ) /* We found the item to free */
1947 current->next = itemList->next; /* readjust the list pointers */
1949 HeapFree( GetProcessHeap(), 0, itemList);
1953 /* Skip to the next item */
1954 current = current->next;
1956 } while ( current != EL_END_OF_LIST );
1960 /***********************************************************************
1961 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
1963 * Initialization code for the COMPOBJ DLL
1967 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
1969 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
1973 case DLL_PROCESS_ATTACH:
1975 if(COMPOBJ_hInstance)
1977 ERR("compobj.dll instantiated twice!\n");
1979 * We should return FALSE here, but that will break
1980 * most apps that use CreateProcess because we do
1981 * not yet support seperate address-spaces.
1986 COMPOBJ_hInstance = hInst;
1989 case DLL_PROCESS_DETACH:
1990 if(!--COMPOBJ_Attach)
1991 COMPOBJ_hInstance = 0;
1997 /******************************************************************************
1998 * OleGetAutoConvert [OLE32.104]
2000 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2007 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2008 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2009 return REGDB_E_CLASSNOTREG;
2011 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
2012 return REGDB_E_KEYMISSING;
2014 lstrcpyAtoW(wbuf,buf);
2015 CLSIDFromString(wbuf,pClsidNew);
2019 /***********************************************************************
2020 * IsEqualGUID [OLE32.76]
2022 * Compares two Unique Identifiers.
2028 BOOL WINAPI IsEqualGUID(
2029 REFGUID rguid1, /* [in] unique id 1 */
2030 REFGUID rguid2 /* [in] unique id 2 */
2033 return !memcmp(rguid1,rguid2,sizeof(GUID));