CoTreatAsClass implemented correctly

Warren Turkal wt at midsouth.rr.com
Sun Mar 28 08:10:38 CST 2004


This patch fixes the implementation of CoTreatAsClass currently in Wine.
Wine currently does not follow what MSDN says at all for this function. This
function is supposed to set the TreatAs registry key. The current version
sets the AutoTreatAs registry key. This version properly modifies the TreatAs
registry key.

I also implemented what is described in the MSDN this way:

"If there is no CLSID assigned to the AutoTreatAs key in the registry, setting
clsidNew and clsidOld to the same value removes the TreatAs entry, so there is
no emulation. If there is a CLSID assigned to the AutoTreatAs key, that CLSID
is assigned to the TreatAs key."

That is where the major complication in the new code comes.

The msdn entry is located at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cmf_a2c_9cqb.asp

On a side note, it might be useful to pull the string length
of the CLSID (39) into a const variable.

wt

Index: compobj.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/compobj.c,v
retrieving revision 1.90
diff -u -3 -p -r1.90 compobj.c
--- compobj.c   23 Mar 2004 23:20:16 -0000      1.90
+++ compobj.c   28 Mar 2004 13:54:50 -0000
@@ -2010,24 +2010,46 @@ HRESULT WINAPI OleDoAutoConvert(IStorage
 
 /******************************************************************************
  *              CoTreatAsClass        [OLE32.@]
+ * Sets TreatAs value of a class
  */
 HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
 {
     HKEY hkey = 0;
-    char buf[200], szClsidNew[200];
+    char buf[47];
+    char szClsidOld[39], szClsidNew[39];
     HRESULT res = S_OK;
+    char auto_treat_as[39];
+    long auto_treat_as_size = 39;
+    CLSID id;
 
-    FIXME("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
     sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
+    WINE_StringFromCLSID(clsidOld, szClsidOld);
     WINE_StringFromCLSID(clsidNew, szClsidNew);
     if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
     {
-        res = REGDB_E_CLASSNOTREG;
+       res = REGDB_E_CLASSNOTREG;
        goto done;
     }
-    if (RegSetValueA(hkey, "AutoTreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
+    if (strcmp(szClsidOld, szClsidNew))
     {
-        res = REGDB_E_WRITEREGDB;
+       if (!RegQueryValueA(hkey, "AutoTreatAs", auto_treat_as, &auto_treat_as_size) &&
+           !__CLSIDFromStringA(auto_treat_as, &id))
+       {
+           if (RegSetValueA(hkey, "TreatAs", REG_SZ, auto_treat_as, strlen(auto_treat_as)+1))
+           {
+               res = REGDB_E_WRITEREGDB;
+               goto done;
+           }
+       }
+       else
+       {
+           RegDeleteKeyA(hkey, "TreatAs");
+           goto done;
+       }
+    }
+    else if (RegSetValueA(hkey, "TreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
+    {
+       res = REGDB_E_WRITEREGDB;
        goto done;
     }
 
-- 
Warren Turkal
President, GOLUM, Inc.
http://www.golum.org




More information about the wine-patches mailing list