4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 Justin Bradford
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Sylvain St-Germain
15 #include <ole32/ole32.h>
17 #include <storage32.h>
21 /****************************************************************************
22 * COM External Lock structures and methods declaration
24 * This api provides a linked list to managed external references to
27 * The public interface consists of three calls:
28 * COM_ExternalLockAddRef
29 * COM_ExternalLockRelease
30 * COM_ExternalLockFreeList
33 #define EL_END_OF_LIST 0
34 #define EL_NOT_FOUND 0
37 * Declaration of the static structure that manage the
38 * external lock to COM objects.
40 typedef struct COM_ExternalLock COM_ExternalLock;
41 typedef struct COM_ExternalLockList COM_ExternalLockList;
43 struct COM_ExternalLock
45 IUnknown *pUnk; /* IUnknown referenced */
46 ULONG uRefCount; /* external lock counter to IUnknown object*/
47 COM_ExternalLock *next; /* Pointer to next element in list */
50 struct COM_ExternalLockList
52 COM_ExternalLock *head; /* head of list */
56 * Declaration and initialization of the static structure that manages
57 * the external lock to COM objects.
59 static COM_ExternalLockList elList = { EL_END_OF_LIST };
62 * Public Interface to the external lock list
64 static void COM_ExternalLockFreeList();
65 static void COM_ExternalLockAddRef(IUnknown *pUnk);
66 static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
67 void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
70 * Private methods used to managed the linked list
72 static BOOL COM_ExternalLockInsert(
75 static void COM_ExternalLockDelete(
76 COM_ExternalLock *element);
78 static COM_ExternalLock* COM_ExternalLockFind(
81 static COM_ExternalLock* COM_ExternalLockLocate(
82 COM_ExternalLock *element,
85 /****************************************************************************
86 * This section defines variables internal to the COM module.
88 * TODO: Most of these things will have to be made thread-safe.
90 HINSTANCE COMPOBJ_hInstance32 = 0;
91 static int COMPOBJ_Attach = 0;
93 LPMALLOC currentMalloc32=NULL;
98 * This lock count counts the number of times CoInitialize is called. It is
99 * decreased every time CoUninitialize is called. When it hits 0, the COM
100 * libraries are freed
102 static ULONG s_COMLockCount = 0;
105 * This linked list contains the list of registered class objects. These
106 * are mostly used to register the factories for out-of-proc servers of OLE
109 * TODO: Make this data structure aware of inter-process communication. This
110 * means that parts of this will be exported to the Wine Server.
112 typedef struct tagRegisteredClass
114 CLSID classIdentifier;
115 LPUNKNOWN classObject;
119 struct tagRegisteredClass* nextClass;
122 static RegisteredClass* firstRegisteredClass = NULL;
124 /* this open DLL table belongs in a per process table, but my guess is that
125 * it shouldn't live in the kernel, so I'll put them out here in DLL
126 * space assuming that there is one OLE32 per process.
128 typedef struct tagOpenDll {
130 struct tagOpenDll *next;
133 static OpenDll *openDllList = NULL; /* linked list of open dlls */
135 /*****************************************************************************
136 * This section contains prototypes to internal methods for this
139 static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
143 static void COM_RevokeAllClasses();
146 /******************************************************************************
147 * CoBuildVersion [COMPOBJ.1]
150 * Current build version, hiword is majornumber, loword is minornumber
152 DWORD WINAPI CoBuildVersion(void)
154 Print(MAX_TRACE, ("Returning version %d, build %d.\n", 1, 0));
158 /******************************************************************************
159 * CoInitialize16 [COMPOBJ.2]
160 * Set the win16 IMalloc used for memory management
162 HRESULT WINAPI CoInitialize16(
163 LPVOID lpReserved /* [in] pointer to win16 malloc interface */
169 /******************************************************************************
170 * CoInitialize [OLE32.26]
172 * Initializes the COM libraries.
176 HRESULT WINAPI CoInitialize(
177 LPVOID lpReserved /* [in] pointer to win32 malloc interface
178 (obsolete, should be NULL) */
183 * Just delegate to the newer method.
185 return CoInitializeEx(lpReserved, )COINIT_APARTMENTTHREADED);
191 /******************************************************************************
192 * CoInitializeEx [OLE32.163]
194 * Initializes the COM libraries. The behavior used to set the win32 IMalloc
195 * used for memory management is obsolete.
198 * S_OK if successful,
199 * S_FALSE if this function was called already.
200 * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
204 * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
207 * See the windows documentation for more details.
209 HRESULT WINAPI CoInitializeEx(
210 LPVOID lpReserved, /* [in] pointer to win32 malloc interface
211 (obsolete, should be NULL) */
212 DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
217 Print(MAX_TRACE, ("(%p, %x)\n", lpReserved, (int)dwCoInit));
219 if (lpReserved!=NULL)
221 Print(MIN_TRACE, ("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved));
225 * Check for unsupported features.
227 if (dwCoInit!=COINIT_APARTMENTTHREADED)
229 Print(MAX_TRACE, (":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit));
230 /* Hope for the best and continue anyway */
234 * Check the lock count. If this is the first time going through the initialize
235 * process, we have to initialize the libraries.
237 if (s_COMLockCount==0)
240 * Initialize the various COM libraries and data structures.
242 Print(MAX_TRACE, ("() - Initializing the COM libraries\n"));
244 RunningObjectTableImpl_Initialize();
252 * Crank-up that lock count.
259 /***********************************************************************
260 * CoUninitialize16 [COMPOBJ.3]
261 * Don't know what it does.
262 * 3-Nov-98 -- this was originally misspelled, I changed it to what I
263 * believe is the correct spelling
265 void WINAPI CoUninitialize16(void)
267 Print(MAX_TRACE, ("Called\n"));
268 CoFreeAllLibraries();
271 /***********************************************************************
272 * CoUninitialize [OLE32.47]
274 * This method will release the COM libraries.
276 * See the windows documentation for more details.
278 void WINAPI CoUninitialize(void)
280 Print(MAX_TRACE, ("Called\n"));
283 * Decrease the reference count.
288 * If we are back to 0 locks on the COM library, make sure we free
289 * all the associated data structures.
291 if (s_COMLockCount==0)
294 * Release the various COM libraries and data structures.
296 Print(MAX_TRACE, ("() - Releasing the COM libraries\n"));
298 RunningObjectTableImpl_UnInitialize();
300 * Release the references to the registered class objects.
302 COM_RevokeAllClasses();
305 * This will free the loaded COM Dlls.
307 CoFreeAllLibraries();
310 * This will free list of external references to COM objects.
312 COM_ExternalLockFreeList();
316 /***********************************************************************
317 * CoGetMalloc16 [COMPOBJ.4]
319 * The current win16 IMalloc
321 HRESULT WINAPI CoGetMalloc16(
322 DWORD dwMemContext, /* [in] unknown */
323 PVOID lpMalloc /* [out] current win16 malloc interface */
329 /******************************************************************************
330 * CoGetMalloc [OLE32.20]
333 * The current win32 IMalloc
335 HRESULT WINAPI CoGetMalloc(
336 DWORD dwMemContext, /* [in] unknown */
337 LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
341 currentMalloc32 = IMalloc_Constructor();
342 *lpMalloc = currentMalloc32;
350 /***********************************************************************
351 * CoCreateStandardMalloc16 [COMPOBJ.71]
353 HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
360 /******************************************************************************
361 * CoDisconnectObject [COMPOBJ.15]
363 HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
365 Print(MAX_TRACE, ("(%p, %lx)\n",lpUnk,reserved));
369 /***********************************************************************
370 * IsEqualGUID16 [COMPOBJ.18]
372 * Compares two Unique Identifiers.
377 BOOL WINAPI IsEqualGUID16(
378 GUID* g1, /* [in] unique id 1 */
379 GUID* g2 /* [in] unique id 2 */
381 return !memcmp( g1, g2, sizeof(GUID) );
384 /******************************************************************************
385 * CLSIDFromString16 [COMPOBJ.20]
386 * Converts a unique identifier from its string representation into
389 * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
394 HRESULT WINAPI CLSIDFromString16(
395 LPCOLESTR16 idstr, /* [in] string representation of guid */
396 CLSID *id /* [out] GUID converted from string */
398 BYTE *s = (BYTE *) idstr;
404 s = "{00000000-0000-0000-0000-000000000000}";
405 else { /* validate the CLSID string */
408 return CO_E_CLASSSTRING;
410 if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
411 return CO_E_CLASSSTRING;
415 if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
416 if (!(((s[i] >= '0') && (s[i] <= '9')) ||
417 ((s[i] >= 'a') && (s[i] <= 'f')) ||
418 ((s[i] >= 'A') && (s[i] <= 'F')))
420 return CO_E_CLASSSTRING;
424 Print(MAX_TRACE, ("%s -> %p\n", s, id));
426 /* quick lookup table */
427 memset(table, 0, 256);
429 for (i = 0; i < 10; i++) {
432 for (i = 0; i < 6; i++) {
433 table['A' + i] = i+10;
434 table['a' + i] = i+10;
437 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
441 s++; /* skip leading brace */
442 for (i = 0; i < 4; i++) {
443 p[3 - i] = table[*s]<<4 | table[*(s+1)];
449 for (i = 0; i < 2; i++) {
450 p[1-i] = table[*s]<<4 | table[*(s+1)];
456 for (i = 0; i < 2; i++) {
457 p[1-i] = table[*s]<<4 | table[*(s+1)];
463 /* these are just sequential bytes */
464 for (i = 0; i < 2; i++) {
465 *p++ = table[*s]<<4 | table[*(s+1)];
470 for (i = 0; i < 6; i++) {
471 *p++ = table[*s]<<4 | table[*(s+1)];
478 /******************************************************************************
479 * CoCreateGuid[OLE32.6]
482 HRESULT WINAPI CoCreateGuid(
483 GUID *pguid /* [out] points to the GUID to initialize */
485 return UuidCreate(pguid);
488 /******************************************************************************
489 * CLSIDFromString [OLE32.3]
490 * Converts a unique identifier from its string representation into
494 * If idstr is not a valid CLSID string then it gets treated as a ProgID
499 HRESULT WINAPI CLSIDFromString(
500 LPCOLESTR idstr, /* [in] string representation of GUID */
501 CLSID *id /* [out] GUID represented by above string */
504 LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr);
505 HRESULT ret = CLSIDFromString16(xid,id);
507 HeapFree(GetProcessHeap(),0,xid);
508 if(ret != S_OK) { /* It appears a ProgID is also valid */
509 ret = CLSIDFromProgID(idstr, id);
518 /******************************************************************************
519 * WINE_StringFromCLSID [Internal]
520 * Converts a GUID into the respective string representation.
525 * the string representation and HRESULT
527 static HRESULT WINE_StringFromCLSID(
528 const CLSID *id, /* [in] GUID to be converted */
529 LPSTR idstr /* [out] pointer to buffer to contain converted guid */
531 static const char *hex = "0123456789ABCDEF";
536 { Print(MIN_TRACE, ("called with id=Null\n"));
541 sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
542 id->Data1, id->Data2, id->Data3,
543 id->Data4[0], id->Data4[1]);
547 for (i = 2; i < 8; i++) {
548 *s++ = hex[id->Data4[i]>>4];
549 *s++ = hex[id->Data4[i] & 0xf];
555 Print(MAX_TRACE, ("%p->%s\n", id, idstr));
560 /******************************************************************************
561 * StringFromCLSID16 [COMPOBJ.19]
562 * Converts a GUID into the respective string representation.
563 * The target string is allocated using the OLE IMalloc.
565 * the string representation and HRESULT
567 HRESULT WINAPI StringFromCLSID16(
568 REFCLSID id, /* [in] the GUID to be converted */
569 LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
573 extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
574 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
579 ret = CoGetMalloc16(0,&mllc);
582 args[0] = (DWORD)mllc;
585 /* No need for a Callback entry, we have WOWCallback16Ex which does
586 * everything we need.
588 if (!K32WOWCallback16Ex(
589 (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
590 (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
597 WARN("CallTo16 IMalloc16 failed\n");
600 return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
607 /******************************************************************************
608 * StringFromCLSID [OLE32.151]
609 * Converts a GUID into the respective string representation.
610 * The target string is allocated using the OLE IMalloc.
612 * the string representation and HRESULT
614 HRESULT WINAPI StringFromCLSID(
615 REFCLSID id, /* [in] the GUID to be converted */
616 LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
622 if ((ret=CoGetMalloc(0,&mllc)))
625 ret=WINE_StringFromCLSID(id,buf);
627 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
628 *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
629 MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
631 IMalloc_Release ( mllc );
635 /******************************************************************************
636 * StringFromGUID2 [COMPOBJ.76] [OLE32.152]
638 * Converts a global unique identifier into a string of an API-
639 * specified fixed format. (The usual {.....} stuff.)
642 * The (UNICODE) string representation of the GUID in 'str'
643 * The length of the resulting string, 0 if there was any problem.
646 StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
650 if (WINE_StringFromCLSID(id,xguid))
652 return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
655 /******************************************************************************
656 * ProgIDFromCLSID [OLE32.133]
657 * Converts a class id into the respective Program ID. (By using a registry lookup)
658 * RETURNS S_OK on success
659 * riid associated with the progid
662 HRESULT WINAPI ProgIDFromCLSID(
663 REFCLSID clsid, /* [in] class id as found in registry */
664 LPOLESTR *lplpszProgID/* [out] associated Prog ID */
667 char strCLSID[50], *buf, *buf2;
673 WINE_StringFromCLSID(clsid, strCLSID);
675 buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
676 sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
677 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
678 ret = REGDB_E_CLASSNOTREG;
680 HeapFree(GetProcessHeap(), 0, buf);
684 buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
686 if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
687 ret = REGDB_E_CLASSNOTREG;
691 if (CoGetMalloc(0,&mllc))
695 DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
696 *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
697 MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
700 HeapFree(GetProcessHeap(), 0, buf2);
707 /******************************************************************************
708 * CLSIDFromProgID16 [COMPOBJ.61]
709 * Converts a program id into the respective GUID. (By using a registry lookup)
711 * riid associated with the progid
713 HRESULT WINAPI CLSIDFromProgID16(
714 LPCOLESTR16 progid, /* [in] program id as found in registry */
715 LPCLSID riid /* [out] associated CLSID */
722 buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
723 sprintf(buf,"%s\\CLSID",progid);
724 if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
725 HeapFree(GetProcessHeap(),0,buf);
726 return CO_E_CLASSSTRING;
728 HeapFree(GetProcessHeap(),0,buf);
729 buf2len = sizeof(buf2);
730 if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
732 return CO_E_CLASSSTRING;
735 return CLSIDFromString16(buf2,riid);
738 /******************************************************************************
739 * CLSIDFromProgID [OLE32.2]
740 * Converts a program id into the respective GUID. (By using a registry lookup)
742 * riid associated with the progid
744 HRESULT WINAPI CLSIDFromProgID(
745 LPCOLESTR progid, /* [in] program id as found in registry */
746 LPCLSID riid /* [out] associated CLSID */
749 LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid);
750 HRESULT ret = CLSIDFromProgID16(pid,riid);
752 HeapFree(GetProcessHeap(),0,pid);
762 /*****************************************************************************
763 * CoGetPSClsid [OLE32.22]
765 * This function returns the CLSID of the DLL that implements the proxy and stub
766 * for the specified interface.
768 * It determines this by searching the
769 * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
770 * and any interface id registered by CoRegisterPSClsid within the current process.
772 * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
774 HRESULT WINAPI CoGetPSClsid(
775 REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
776 CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
782 Print(MAX_TRACE, ("() riid=%s, pclsid=%p\n", PRINT_GUID(riid), pclsid));
784 /* Get the input iid as a string */
785 WINE_StringFromCLSID(riid, buf2);
786 /* Allocate memory for the registry key we will construct.
787 (length of iid string plus constant length of static text */
788 buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
791 return (E_OUTOFMEMORY);
794 /* Construct the registry key we want */
795 sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
798 if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
800 HeapFree(GetProcessHeap(),0,buf);
801 return (E_INVALIDARG);
803 HeapFree(GetProcessHeap(),0,buf);
805 /* ... Once we have the key, query the registry to get the
806 value of CLSID as a string, and convert it into a
807 proper CLSID structure to be passed back to the app */
808 buf2len = sizeof(buf2);
809 if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
816 /* We have the CLSid we want back from the registry as a string, so
817 lets convert it into a CLSID structure */
818 if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
823 Print(MAX_TRACE, ("() Returning CLSID=%s\n", PRINT_GUID(pclsid)));
829 /***********************************************************************
832 * This function write a CLSID on stream
834 HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
836 Print(MAX_TRACE, ("(%p,%p)\n",pStm,rclsid));
841 return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
844 /***********************************************************************
847 * This function read a CLSID from a stream
849 HRESULT WINAPI ReadClassStm(IStream *pStm,REFCLSID rclsid)
854 Print(MAX_TRACE, ("(%p,%p)\n",pStm,rclsid));
859 res = IStream_Read(pStm,(void*)rclsid,sizeof(CLSID),&nbByte);
864 if (nbByte != sizeof(CLSID))
870 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
871 /***********************************************************************
872 * LookupETask (COMPOBJ.94)
874 HRESULT WINAPI LookupETask16(PVOID hTask,LPVOID p) {
879 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
880 /***********************************************************************
881 * SetETask (COMPOBJ.95)
883 HRESULT WINAPI SetETask16(DWORD hTask, LPVOID p) {
888 /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
889 /***********************************************************************
890 * CallObjectInWOW (COMPOBJ.201)
892 HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
897 /******************************************************************************
898 * CoRegisterClassObject16 [COMPOBJ.5]
900 * Don't know where it registers it ...
902 HRESULT WINAPI CoRegisterClassObject16(
905 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
906 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
914 /******************************************************************************
915 * CoRevokeClassObject16 [COMPOBJ.6]
918 HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
926 * COM_GetRegisteredClassObject
928 * This internal method is used to scan the registered class list to
929 * find a class object.
932 * rclsid Class ID of the class to find.
933 * dwClsContext Class context to match.
934 * ppv [out] returns a pointer to the class object. Complying
935 * to normal COM usage, this method will increase the
936 * reference count on this object.
938 static HRESULT COM_GetRegisteredClassObject(
943 RegisteredClass* curClass;
951 * Iterate through the whole list and try to match the class ID.
953 curClass = firstRegisteredClass;
955 while (curClass != 0)
958 * Check if we have a match on the class ID.
960 if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
963 * Since we don't do out-of process or DCOM just right away, let's ignore the
968 * We have a match, return the pointer to the class object.
970 *ppUnk = curClass->classObject;
972 IUnknown_AddRef(curClass->classObject);
978 * Step to the next class in the list.
980 curClass = curClass->nextClass;
984 * If we get to here, we haven't found our class.
989 /******************************************************************************
990 * CoRegisterClassObject [OLE32.36]
992 * This method will register the class object for a given class ID.
994 * See the Windows documentation for more details.
996 HRESULT WINAPI CoRegisterClassObject(
999 DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
1000 DWORD flags, /* [in] REGCLS flags indicating how connections are made */
1001 LPDWORD lpdwRegister
1004 RegisteredClass* newClass;
1005 LPUNKNOWN foundObject;
1009 WINE_StringFromCLSID(rclsid,buf);
1011 Print(MAX_TRACE, ("(%s,%p,0x%08lx,0x%08lx,%p)\n",
1012 buf,pUnk,dwClsContext,flags,lpdwRegister));
1015 * Perform a sanity check on the parameters
1017 if ( (lpdwRegister==0) || (pUnk==0) )
1019 return E_INVALIDARG;
1023 * Initialize the cookie (out parameter)
1028 * First, check if the class is already registered.
1029 * If it is, this should cause an error.
1031 hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
1036 * The COM_GetRegisteredClassObject increased the reference count on the
1037 * object so it has to be released.
1039 IUnknown_Release(foundObject);
1041 return CO_E_OBJISREG;
1045 * If it is not registered, we must create a new entry for this class and
1046 * append it to the registered class list.
1047 * We use the address of the chain node as the cookie since we are sure it's
1050 newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
1053 * Initialize the node.
1055 newClass->classIdentifier = *rclsid;
1056 newClass->runContext = dwClsContext;
1057 newClass->connectFlags = flags;
1058 newClass->dwCookie = (DWORD)newClass;
1059 newClass->nextClass = firstRegisteredClass;
1062 * Since we're making a copy of the object pointer, we have to increase its
1065 newClass->classObject = pUnk;
1066 IUnknown_AddRef(newClass->classObject);
1068 firstRegisteredClass = newClass;
1071 * Assign the out parameter (cookie)
1073 *lpdwRegister = newClass->dwCookie;
1076 * We're successful Yippee!
1081 /***********************************************************************
1082 * CoRevokeClassObject [OLE32.40]
1084 * This method will remove a class object from the class registry
1086 * See the Windows documentation for more details.
1088 HRESULT WINAPI CoRevokeClassObject(
1091 RegisteredClass** prevClassLink;
1092 RegisteredClass* curClass;
1094 Print(MAX_TRACE, ("(%08lx)\n",dwRegister));
1097 * Iterate through the whole list and try to match the cookie.
1099 curClass = firstRegisteredClass;
1100 prevClassLink = &firstRegisteredClass;
1102 while (curClass != 0)
1105 * Check if we have a match on the cookie.
1107 if (curClass->dwCookie == dwRegister)
1110 * Remove the class from the chain.
1112 *prevClassLink = curClass->nextClass;
1115 * Release the reference to the class object.
1117 IUnknown_Release(curClass->classObject);
1120 * Free the memory used by the chain node.
1122 HeapFree(GetProcessHeap(), 0, curClass);
1128 * Step to the next class in the list.
1130 prevClassLink = &(curClass->nextClass);
1131 curClass = curClass->nextClass;
1135 * If we get to here, we haven't found our class.
1137 return E_INVALIDARG;
1140 /***********************************************************************
1141 * CoGetClassObject [COMPOBJ.7]
1143 HRESULT WINAPI CoGetClassObject(
1144 REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
1145 REFIID iid, LPVOID *ppv
1147 LPUNKNOWN regClassObject;
1148 HRESULT hres = E_UNEXPECTED;
1150 WCHAR dllName[MAX_PATH+1];
1151 DWORD dllNameLen = sizeof(dllName);
1153 typedef HRESULT CALLBACK (*DllGetClassObjectFunc)(REFCLSID clsid,
1154 REFIID iid, LPVOID *ppv);
1155 DllGetClassObjectFunc DllGetClassObject;
1157 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
1159 Print(MIN_TRACE, ("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
1165 Print(MIN_TRACE, ("\tpServerInfo: name=%S\n",pServerInfo->pwszName));
1166 Print(MIN_TRACE, ("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo));
1170 * First, try and see if we can't match the class ID with one of the
1171 * registered classes.
1173 if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
1176 * Get the required interface from the retrieved pointer.
1178 hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
1181 * Since QI got another reference on the pointer, we want to release the
1182 * one we already have. If QI was unsuccessful, this will release the object. This
1183 * is good since we are not returning it in the "out" parameter.
1185 IUnknown_Release(regClassObject);
1190 /* out of process and remote servers not supported yet */
1191 if ( ((CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER) & dwClsContext)
1192 && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
1194 Print(MIN_TRACE, ("%s %s not supported!\n",
1195 (dwClsContext&CLSCTX_LOCAL_SERVER)?"CLSCTX_LOCAL_SERVER":"",
1196 (dwClsContext&CLSCTX_REMOTE_SERVER)?"CLSCTX_REMOTE_SERVER":""
1198 return E_ACCESSDENIED;
1201 if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
1205 sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
1206 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
1208 if (hres != ERROR_SUCCESS) {
1209 return REGDB_E_CLASSNOTREG;
1212 memset(dllName,0,sizeof(dllName));
1213 hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
1215 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
1217 Print(MAX_TRACE, ("found InprocServer32 dll %S\n", dllName));
1219 /* open dll, call DllGetClassObject */
1220 hLibrary = CoLoadLibrary(dllName, TRUE);
1221 if (hLibrary == 0) {
1222 Print(MIN_TRACE, ("couldn't load InprocServer32 dll %S\n", dllName));
1223 return E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
1225 DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject");
1226 if (!DllGetClassObject) {
1227 /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
1228 Print(MIN_TRACE, ("couldn't find function DllGetClassObject in %S\n", dllName));
1229 return E_ACCESSDENIED;
1233 * Ask the DLL for its class object. (there was a note here about class
1234 * factories but this is good.
1236 return DllGetClassObject(rclsid, iid, ppv);
1241 /***********************************************************************
1242 * CoResumeClassObjects
1244 * Resumes classobjects registered with REGCLS suspended
1246 HRESULT WINAPI CoResumeClassObjects(void)
1252 /***********************************************************************
1255 * This function supplies the CLSID associated with the given filename.
1257 HRESULT WINAPI GetClassFile(LPOLESTR filePathName,CLSID *pclsid)
1261 int nbElm=0,length=0,i=0;
1263 LPOLESTR *pathDec=0,absFile=0,progId=0;
1264 WCHAR extention[100]={0};
1266 Print(MAX_TRACE, ("()\n"));
1268 /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
1269 if((StgIsStorageFile(filePathName))==S_OK){
1271 res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
1274 res=ReadClassStg(pstg,pclsid);
1276 IStorage_Release(pstg);
1280 /* if the file is not a storage object then attemps to match various bits in the file against a
1281 pattern in the registry. this case is not frequently used ! so I present only the psodocode for
1284 for(i=0;i<nFileTypes;i++)
1286 for(i=0;j<nPatternsForType;j++){
1291 pat=ReadPatternFromRegistry(i,j);
1292 hFile=CreateFileW(filePathName,,,,,,hFile);
1293 SetFilePosition(hFile,pat.offset);
1294 ReadFile(hFile,buf,pat.size,NULL,NULL);
1295 if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
1297 *pclsid=ReadCLSIDFromRegistry(i);
1303 /* if the obove strategies fail then search for the extension key in the registry */
1305 /* get the last element (absolute file) in the path name */
1306 nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
1307 absFile=pathDec[nbElm-1];
1309 /* failed if the path represente a directory and not an absolute file name*/
1310 if (lstrcmpW(absFile,(LPOLESTR)"\\"))
1311 return MK_E_INVALIDEXTENSION;
1313 /* get the extension of the file */
1314 length=lstrlenW(absFile);
1315 for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
1317 /* get the progId associated to the extension */
1318 progId=CoTaskMemAlloc(sizeProgId);
1320 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1322 if (res==ERROR_MORE_DATA){
1324 progId = CoTaskMemRealloc(progId,sizeProgId);
1325 res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
1327 if (res==ERROR_SUCCESS)
1328 /* return the clsid associated to the progId */
1329 res= CLSIDFromProgID(progId,pclsid);
1331 for(i=0; pathDec[i]!=NULL;i++)
1332 CoTaskMemFree(pathDec[i]);
1333 CoTaskMemFree(pathDec);
1335 CoTaskMemFree(progId);
1337 if (res==ERROR_SUCCESS)
1340 return MK_E_INVALIDEXTENSION;
1342 /******************************************************************************
1343 * CoRegisterMessageFilter16 [COMPOBJ.27]
1345 HRESULT WINAPI CoRegisterMessageFilter16(
1346 DWORD lpMessageFilter,
1347 DWORD *lplpMessageFilter
1353 /***********************************************************************
1354 * CoCreateInstance [COMPOBJ.13, OLE32.7]
1356 HRESULT WINAPI CoCreateInstance(
1358 LPUNKNOWN pUnkOuter,
1364 LPCLASSFACTORY lpclf = 0;
1373 * Initialize the "out" parameter
1378 * Get a class factory to construct the object we want.
1380 hres = CoGetClassObject(rclsid,
1387 Print(MIN_TRACE, ("no instance created for %s, hres is 0x%08lx\n",PRINT_GUID(iid),hres));
1392 * Create the object and don't forget to release the factory
1394 hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
1395 IClassFactory_Release(lpclf);
1400 /***********************************************************************
1401 * CoCreateInstanceEx [OLE32.165]
1403 HRESULT WINAPI CoCreateInstanceEx(
1405 LPUNKNOWN pUnkOuter,
1407 COSERVERINFO* pServerInfo,
1411 IUnknown* pUnk = NULL;
1414 int successCount = 0;
1419 if ( (cmq==0) || (pResults==NULL))
1420 return E_INVALIDARG;
1422 if (pServerInfo!=NULL)
1423 Print(MIN_TRACE, ("() non-NULL pServerInfo not supported!\n"));
1426 * Initialize all the "out" parameters.
1428 for (index = 0; index < cmq; index++)
1430 pResults[index].pItf = NULL;
1431 pResults[index].hr = E_NOINTERFACE;
1435 * Get the object and get its IUnknown pointer.
1437 hr = CoCreateInstance(rclsid,
1447 * Then, query for all the interfaces requested.
1449 for (index = 0; index < cmq; index++)
1451 pResults[index].hr = IUnknown_QueryInterface(pUnk,
1452 pResults[index].pIID,
1453 (VOID**)&(pResults[index].pItf));
1455 if (pResults[index].hr == S_OK)
1460 * Release our temporary unknown pointer.
1462 IUnknown_Release(pUnk);
1464 if (successCount == 0)
1465 return E_NOINTERFACE;
1467 if (successCount!=cmq)
1468 return CO_S_NOTALLINTERFACES;
1473 /***********************************************************************
1474 * CoFreeLibrary [COMPOBJ.13]
1476 void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
1478 OpenDll *ptr, *prev;
1481 /* lookup library in linked list */
1483 for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
1484 if (ptr->hLibrary == hLibrary) {
1491 /* shouldn't happen if user passed in a valid hLibrary */
1494 /* assert: ptr points to the library entry to free */
1496 /* free library and remove node from list */
1497 FreeLibrary(hLibrary);
1498 if (ptr == openDllList) {
1499 tmp = openDllList->next;
1500 HeapFree(GetProcessHeap(), 0, openDllList);
1504 HeapFree(GetProcessHeap(), 0, ptr);
1511 /***********************************************************************
1512 * CoFreeAllLibraries [COMPOBJ.12]
1514 void WINAPI CoFreeAllLibraries(void)
1518 for (ptr = openDllList; ptr != NULL; ) {
1520 CoFreeLibrary(ptr->hLibrary);
1527 /***********************************************************************
1528 * CoFreeUnusedLibraries [COMPOBJ.17]
1530 void WINAPI CoFreeUnusedLibraries(void)
1533 typedef HRESULT(*DllCanUnloadNowFunc)(void);
1534 DllCanUnloadNowFunc DllCanUnloadNow;
1536 for (ptr = openDllList; ptr != NULL; ) {
1537 DllCanUnloadNow = (DllCanUnloadNowFunc)
1538 GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
1540 if ( (DllCanUnloadNow != NULL) &&
1541 (DllCanUnloadNow() == S_OK) ) {
1543 CoFreeLibrary(ptr->hLibrary);
1551 /***********************************************************************
1552 * CoFileTimeNow [COMPOBJ.82, OLE32.10]
1554 * the current system time in lpFileTime
1556 HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
1558 GetSystemTimeAsFileTime( lpFileTime );
1562 /***********************************************************************
1563 * CoTaskMemAlloc (OLE32.43)
1565 * pointer to newly allocated block
1567 LPVOID WINAPI CoTaskMemAlloc(
1568 ULONG size /* [in] size of memoryblock to be allocated */
1571 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1576 return IMalloc_Alloc(lpmalloc,size);
1578 /***********************************************************************
1579 * CoTaskMemFree (OLE32.44)
1581 VOID WINAPI CoTaskMemFree(
1582 LPVOID ptr /* [in] pointer to be freed */
1585 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1590 IMalloc_Free(lpmalloc, ptr);
1593 /***********************************************************************
1594 * CoTaskMemRealloc (OLE32.45)
1596 * pointer to newly allocated block
1598 LPVOID WINAPI CoTaskMemRealloc(
1600 ULONG size) /* [in] size of memoryblock to be allocated */
1603 HRESULT ret = CoGetMalloc(0,&lpmalloc);
1608 return IMalloc_Realloc(lpmalloc, pvOld, size);
1611 /***********************************************************************
1612 * CoLoadLibrary (OLE32.30)
1614 HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
1620 Print(MAX_TRACE, ("(%S, %d)\n", lpszLibName, bAutoFree));
1622 hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
1627 if (openDllList == NULL) {
1628 /* empty list -- add first node */
1629 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1630 openDllList->hLibrary=hLibrary;
1631 openDllList->next = NULL;
1633 /* search for this dll */
1635 for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
1636 if (ptr->hLibrary == hLibrary) {
1642 /* dll not found, add it */
1644 openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
1645 openDllList->hLibrary = hLibrary;
1646 openDllList->next = tmp;
1653 /***********************************************************************
1654 * CoInitializeWOW (OLE32.27)
1656 HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
1661 /******************************************************************************
1662 * CoLockObjectExternal16 [COMPOBJ.63]
1664 HRESULT WINAPI CoLockObjectExternal16(
1665 LPUNKNOWN pUnk, /* [in] object to be locked */
1666 BOOL fLock, /* [in] do lock */
1667 BOOL fLastUnlockReleases /* [in] ? */
1673 /******************************************************************************
1674 * CoLockObjectExternal [OLE32.31]
1676 HRESULT WINAPI CoLockObjectExternal(
1677 LPUNKNOWN pUnk, /* [in] object to be locked */
1678 BOOL fLock, /* [in] do lock */
1679 BOOL fLastUnlockReleases) /* [in] unlock all */
1685 * Increment the external lock coutner, COM_ExternalLockAddRef also
1686 * increment the object's internal lock counter.
1688 COM_ExternalLockAddRef( pUnk);
1693 * Decrement the external lock coutner, COM_ExternalLockRelease also
1694 * decrement the object's internal lock counter.
1696 COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
1702 /***********************************************************************
1703 * CoGetState16 [COMPOBJ.115]
1705 HRESULT WINAPI CoGetState16(LPDWORD state)
1710 /***********************************************************************
1711 * CoSetState [COM32.42]
1713 HRESULT WINAPI CoSetState(LPDWORD state)
1718 /***********************************************************************
1719 * CoCreateFreeThreadedMarshaler [OLE32.5]
1721 HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
1728 /***********************************************************************
1729 * DllGetClassObject [OLE32.63]
1731 HRESULT WINAPI OLE32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
1735 return CLASS_E_CLASSNOTAVAILABLE;
1740 * COM_RevokeAllClasses
1742 * This method is called when the COM libraries are uninitialized to
1743 * release all the references to the class objects registered with
1746 static void COM_RevokeAllClasses()
1748 while (firstRegisteredClass!=0)
1750 CoRevokeClassObject(firstRegisteredClass->dwCookie);
1754 /****************************************************************************
1755 * COM External Lock methods implementation
1758 /****************************************************************************
1759 * Public - Method that increments the count for a IUnknown* in the linked
1760 * list. The item is inserted if not already in the list.
1762 static void COM_ExternalLockAddRef(
1765 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1768 * Add an external lock to the object. If it was already externally
1769 * locked, just increase the reference count. If it was not.
1770 * add the item to the list.
1772 if ( externalLock == EL_NOT_FOUND )
1773 COM_ExternalLockInsert(pUnk);
1775 externalLock->uRefCount++;
1778 * Add an internal lock to the object
1780 IUnknown_AddRef(pUnk);
1783 /****************************************************************************
1784 * Public - Method that decrements the count for a IUnknown* in the linked
1785 * list. The item is removed from the list if its count end up at zero or if
1788 static void COM_ExternalLockRelease(
1792 COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
1794 if ( externalLock != EL_NOT_FOUND )
1798 externalLock->uRefCount--; /* release external locks */
1799 IUnknown_Release(pUnk); /* release local locks as well */
1801 if ( bRelAll == FALSE )
1802 break; /* perform single release */
1804 } while ( externalLock->uRefCount > 0 );
1806 if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
1807 COM_ExternalLockDelete(externalLock);
1810 /****************************************************************************
1811 * Public - Method that frees the content of the list.
1813 static void COM_ExternalLockFreeList()
1815 COM_ExternalLock *head;
1817 head = elList.head; /* grab it by the head */
1818 while ( head != EL_END_OF_LIST )
1820 COM_ExternalLockDelete(head); /* get rid of the head stuff */
1822 head = elList.head; /* get the new head... */
1826 /****************************************************************************
1827 * Public - Method that dump the content of the list.
1829 void COM_ExternalLockDump()
1831 COM_ExternalLock *current = elList.head;
1833 Print(MAX_TRACE, ("\nExternal lock list contains:\n"));
1835 while ( current != EL_END_OF_LIST )
1837 Print(MAX_TRACE, ("\t%p with %lu references count.\n", current->pUnk, current->uRefCount));
1839 /* Skip to the next item */
1840 current = current->next;
1845 /****************************************************************************
1846 * Internal - Find a IUnknown* in the linked list
1848 static COM_ExternalLock* COM_ExternalLockFind(
1851 return COM_ExternalLockLocate(elList.head, pUnk);
1854 /****************************************************************************
1855 * Internal - Recursivity agent for IUnknownExternalLockList_Find
1857 static COM_ExternalLock* COM_ExternalLockLocate(
1858 COM_ExternalLock *element,
1861 if ( element == EL_END_OF_LIST )
1862 return EL_NOT_FOUND;
1864 else if ( element->pUnk == pUnk ) /* We found it */
1867 else /* Not the right guy, keep on looking */
1868 return COM_ExternalLockLocate( element->next, pUnk);
1871 /****************************************************************************
1872 * Internal - Insert a new IUnknown* to the linked list
1874 static BOOL COM_ExternalLockInsert(
1877 COM_ExternalLock *newLock = NULL;
1878 COM_ExternalLock *previousHead = NULL;
1881 * Allocate space for the new storage object
1883 newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
1887 if ( elList.head == EL_END_OF_LIST )
1889 elList.head = newLock; /* The list is empty */
1894 * insert does it at the head
1896 previousHead = elList.head;
1897 elList.head = newLock;
1901 * Set new list item data member
1903 newLock->pUnk = pUnk;
1904 newLock->uRefCount = 1;
1905 newLock->next = previousHead;
1913 /****************************************************************************
1914 * Internal - Method that removes an item from the linked list.
1916 static void COM_ExternalLockDelete(
1917 COM_ExternalLock *itemList)
1919 COM_ExternalLock *current = elList.head;
1921 if ( current == itemList )
1924 * this section handles the deletion of the first node
1926 elList.head = itemList->next;
1927 HeapFree( GetProcessHeap(), 0, itemList);
1933 if ( current->next == itemList ) /* We found the item to free */
1935 current->next = itemList->next; /* readjust the list pointers */
1937 HeapFree( GetProcessHeap(), 0, itemList);
1941 /* Skip to the next item */
1942 current = current->next;
1944 } while ( current != EL_END_OF_LIST );
1948 /***********************************************************************
1949 * COMPOBJ_DllEntryPoint [COMPOBJ.entry]
1951 * Initialization code for the COMPOBJ DLL
1955 BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, DWORD hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
1957 Print(MAX_TRACE, ("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
1961 case DLL_PROCESS_ATTACH:
1963 if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
1967 case DLL_PROCESS_DETACH:
1969 if(!--COMPOBJ_Attach)
1970 COMPOBJ_hInstance = 0;
1977 /******************************************************************************
1978 * OleGetAutoConvert [OLE32.104]
1980 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
1988 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
1989 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
1991 res = REGDB_E_CLASSNOTREG;
1995 /* we can just query for the default value of AutoConvertTo key like that,
1996 without opening the AutoConvertTo key and querying for NULL (default) */
1997 if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
1999 res = REGDB_E_KEYMISSING;
2002 MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
2003 CLSIDFromString(wbuf,pClsidNew);
2005 if (hkey) RegCloseKey(hkey);
2010 /******************************************************************************
2011 * OleSetAutoConvert [OLE32.126]
2013 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2015 HKEY hkey = 0, hkeyConvert = 0;
2016 char buf[200], szClsidNew[200];
2019 Print(MAX_TRACE, ("(%p,%p);\n", clsidOld, clsidNew));
2020 sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
2021 WINE_StringFromCLSID(clsidNew, szClsidNew);
2022 if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
2024 res = REGDB_E_CLASSNOTREG;
2027 if (RegCreateKeyA(hkey, "AutoConvertTo", &hkeyConvert))
2029 res = REGDB_E_WRITEREGDB;
2032 if (RegSetValueExA(hkeyConvert, NULL, 0,
2033 REG_SZ, (LPBYTE)szClsidNew, strlen(szClsidNew)+1))
2035 res = REGDB_E_WRITEREGDB;
2040 if (hkeyConvert) RegCloseKey(hkeyConvert);
2041 if (hkey) RegCloseKey(hkey);
2046 /***********************************************************************
2047 * IsEqualGUID [OLE32.76]
2049 * Compares two Unique Identifiers.
2055 BOOL WINAPI IsEqualGUID(
2056 REFGUID rguid1, /* [in] unique id 1 */
2057 REFGUID rguid2 /* [in] unique id 2 */
2060 return !memcmp(rguid1,rguid2,sizeof(GUID));