Register typelib marshaling for OLE Automation-compatible interfaces.
authorOve Kaaven <ovek@transgaming.com>
Fri, 21 Sep 2001 21:00:37 +0000 (21:00 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 21 Sep 2001 21:00:37 +0000 (21:00 +0000)
dlls/oleaut32/oleaut32.spec
dlls/oleaut32/typelib.c

index deeb223..9734216 100644 (file)
@@ -144,14 +144,14 @@ debug_channels (ole typelib)
 160 stdcall CreateTypeLib(long wstr ptr) CreateTypeLib
 161 stdcall LoadTypeLib (wstr ptr) LoadTypeLib
 162 stdcall LoadRegTypeLib (ptr long long long ptr) LoadRegTypeLib
-163 stdcall RegisterTypeLib(ptr str str) RegisterTypeLib
+163 stdcall RegisterTypeLib(ptr wstr wstr) RegisterTypeLib
 164 stdcall QueryPathOfRegTypeLib(ptr long long long ptr) QueryPathOfRegTypeLib
 165 stdcall LHashValOfNameSys(long long wstr) LHashValOfNameSys
 166 stdcall LHashValOfNameSysA(long long str) LHashValOfNameSysA
 170 stdcall OaBuildVersion() OaBuildVersion
 171 stub ClearCustData
 180 stub CreateTypeLib2
-183 stdcall LoadTypeLibEx (ptr long ptr) LoadTypeLibEx
+183 stdcall LoadTypeLibEx (wstr long ptr) LoadTypeLibEx
 184 stdcall SystemTimeToVariantTime(ptr ptr) SystemTimeToVariantTime
 185 stdcall VariantTimeToSystemTime(double ptr) VariantTimeToSystemTime
 186 stdcall UnRegisterTypeLib (ptr long long long long) UnRegisterTypeLib
index c8dbb2b..56ad725 100644 (file)
@@ -345,6 +345,9 @@ HRESULT WINAPI RegisterTypeLib(
     LPSTR guidA;
     CHAR keyName[120];
     HKEY key, subKey;
+    UINT types, tidx;
+    TYPEKIND kind;
+    static const char *PSOA = "{00020424-0000-0000-C000-000000000046}";
 
     if (ptlib == NULL || szFullPath == NULL)
         return E_INVALIDARG;
@@ -403,7 +406,90 @@ HRESULT WINAPI RegisterTypeLib(
     else
         res = E_FAIL;
 
+    /* register OLE Automation-compatible interfaces for this typelib */
+    types = ITypeLib_GetTypeInfoCount(ptlib);
+    for (tidx=0; tidx<types; tidx++) {
+       if (SUCCEEDED(ITypeLib_GetTypeInfoType(ptlib, tidx, &kind))) {
+           LPOLESTR name = NULL;
+           ITypeInfo *tinfo = NULL;
+           BOOL stop = FALSE;
+           ITypeLib_GetDocumentation(ptlib, tidx, &name, NULL, NULL, NULL);
+           switch (kind) {
+           case TKIND_INTERFACE:
+               TRACE_(typelib)("%d: interface %s\n", tidx, debugstr_w(name));
+               ITypeLib_GetTypeInfo(ptlib, tidx, &tinfo);
+               break;
+           case TKIND_DISPATCH:
+               TRACE_(typelib)("%d: dispinterface %s\n", tidx, debugstr_w(name));
+               /* ITypeLib_GetTypeInfo(ptlib, tidx, &tinfo); */
+               break;
+           case TKIND_COCLASS:
+               TRACE_(typelib)("%d: coclass %s\n", tidx, debugstr_w(name));
+               /* coclasses should probably not be registered? */
+               break;
+           default:
+               TRACE_(typelib)("%d: %s\n", tidx, debugstr_w(name));
+               break;
+           }
+           if (tinfo) {
+               TYPEATTR *tattr = NULL;
+               ITypeInfo_GetTypeAttr(tinfo, &tattr);
+               if (tattr) {
+                   TRACE_(typelib)("guid=%s, flags=%04x\n",
+                                   debugstr_guid(&tattr->guid),
+                                   tattr->wTypeFlags);
+                   if (tattr->wTypeFlags & TYPEFLAG_FOLEAUTOMATION) {
+                       /* register interface<->typelib coupling */
+                       StringFromGUID2(&tattr->guid, guid, 80);
+                       guidA = HEAP_strdupWtoA(GetProcessHeap(), 0, guid);
+                       snprintf(keyName, sizeof(keyName), "Interface\\%s", guidA);
+                       HeapFree(GetProcessHeap(), 0, guidA);
+
+                       if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyName, 0, NULL, 0,
+                                           KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
+                           if (name)
+                               RegSetValueExW(key, NULL, 0, REG_SZ,
+                                              (BYTE *)name, lstrlenW(name) * sizeof(OLECHAR));
+
+                           if (RegCreateKeyExA(key, "ProxyStubClsid", 0, NULL, 0,
+                               KEY_WRITE, NULL, &subKey, NULL) == ERROR_SUCCESS) {
+                               RegSetValueExA(subKey, NULL, 0, REG_SZ,
+                                              PSOA, strlen(PSOA));
+                               RegCloseKey(subKey);
+                           }
+                           if (RegCreateKeyExA(key, "ProxyStubClsid32", 0, NULL, 0,
+                               KEY_WRITE, NULL, &subKey, NULL) == ERROR_SUCCESS) {
+                               RegSetValueExA(subKey, NULL, 0, REG_SZ,
+                                              PSOA, strlen(PSOA));
+                               RegCloseKey(subKey);
+                           }
+
+                           if (RegCreateKeyExA(key, "TypeLib", 0, NULL, 0,
+                               KEY_WRITE, NULL, &subKey, NULL) == ERROR_SUCCESS) {
+                               CHAR ver[32];
+                               StringFromGUID2(&attr->guid, guid, 80);
+                               snprintf(ver, sizeof(ver), "%x.%x",
+                                        attr->wMajorVerNum, attr->wMinorVerNum);
+                               RegSetValueExW(subKey, NULL, 0, REG_SZ,
+                                              (BYTE *)guid, lstrlenW(guid) * sizeof(OLECHAR));
+                               RegSetValueExA(subKey, "Version", 0, REG_SZ,
+                                              ver, lstrlenA(ver));
+                               RegCloseKey(subKey);
+                           }
+                           RegCloseKey(key);
+                       }
+                   }
+                   ITypeInfo_ReleaseTypeAttr(tinfo, tattr);
+               }
+               ITypeInfo_Release(tinfo);
+           }
+           SysFreeString(name);
+           if (stop) break;
+       }
+    }
+
     ITypeLib_ReleaseTLibAttr(ptlib, attr);
+
     return res;
 }