Windows allows the registration of 64bit typelibs from 32bit programs even on a pure Win32 install.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51864
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- v2: Handle insufficient privileges in the testcase. --- dlls/oleaut32/tests/typelib.c | 180 ++++++++++++++++++++++++++++++++++ dlls/oleaut32/typelib.c | 4 - 2 files changed, 180 insertions(+), 4 deletions(-)
diff --git a/dlls/oleaut32/tests/typelib.c b/dlls/oleaut32/tests/typelib.c index 825851c948e..78290c94dfe 100644 --- a/dlls/oleaut32/tests/typelib.c +++ b/dlls/oleaut32/tests/typelib.c @@ -6848,6 +6848,185 @@ static void test_register_typelib(BOOL system_registration) DeleteFileW(filename); }
+static void test_register_typelib_64(void) +{ + ICreateTypeInfo *createti, *createti_co; + ELEMDESC elemdesc[5], elemdesc2[5]; + FUNCDESC funcdesc, funcdesc2; + ITypeInfo *unknown, *tinfo; + ITypeLib *stdole, *typelib; + ICreateTypeLib2 *createtl; + WCHAR filename[MAX_PATH]; + HREFTYPE hreftype; + HRESULT hr; + + static const WCHAR wszStdOle2[] = { 's','t','d','o','l','e','2','.','t','l','b',0 }; + + static OLECHAR typelibW[] = { 'W','i','n','e','T','e','s','t','T','y','p','e','L','i','b',0}; + static OLECHAR helpfileW[] = { 'C',':','\','b','o','g','u','s','.','h','l','p',0 }; + static OLECHAR dllfileW[] = { 'C',':','\','b','o','g','u','s','.','d','l','l',0 }; + static OLECHAR interface1W[] = { 'I','T','e','s','t','W','i','n','e','6', '4', 0}; + static OLECHAR coclassW[] = {'W','i','n','e','T','e','s','t','C','o','c','l','a','s','s',0 }; + static OLECHAR func1W[] = { 'f','u','n','c','1',0 }; + static OLECHAR func2W[] = { 'f','u','n','c','2',0 }; + static OLECHAR param1W[] = { 'p','a','r','a','m','1',0 }; + static OLECHAR param2W[] = { 'p','a','r','a','m','2',0 }; + static OLECHAR *names1[] = { func1W, param1W, param2W }; + static OLECHAR *names2[] = { func2W, param1W }; + static const GUID tlcustguid = { 0x512d2fec,0xcaf6,0x4c33,{0xbc,0x38,0x84,0x2f,0x2e,0x37,0x0d,0x7b} }; + static const GUID coclassguid = { 0x317cd4dd,0x0ce0,0x4525,{0x8d,0x33,0x68,0x14,0x4c,0x53,0x60,0xe9} }; + static const GUID interfaceguid = { 0x35cc5cea,0x11cc,0x4bca,{0x89,0x8c,0xf8,0x92,0x8e,0xb8,0xda,0x24} }; + + static const SYSKIND sys = SYS_WIN64; + + hr = LoadTypeLib(wszStdOle2, &stdole); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &unknown); + ok(hr == S_OK, "got %08x\n", hr); + + GetTempFileNameW(L".", L"tlb", 0, filename); + + hr = CreateTypeLib2(sys, filename, &createtl); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_SetName(createtl, typelibW); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_SetHelpFileName(createtl, helpfileW); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_SetHelpStringDll(createtl, dllfileW); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_SetGuid(createtl, &tlcustguid); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_SetVersion(createtl, 1, 0); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_CreateTypeInfo(createtl, coclassW, TKIND_COCLASS, &createti_co); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeLib2_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, &createti); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_LayOut(createti); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetGuid(createti, &interfaceguid); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetVersion(createti, 1, 0); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, &hreftype); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_AddImplType(createti, 0, hreftype); + ok(hr == S_OK, "got %08x\n", hr); + + elemdesc[0].tdesc.vt = VT_UINT; + U(elemdesc[0]).idldesc.dwReserved = 0; + U(elemdesc[0]).idldesc.wIDLFlags = IDLFLAG_FIN; + + elemdesc[1].tdesc.vt = VT_DECIMAL; + U(elemdesc[1]).idldesc.dwReserved = 0; + U(elemdesc[1]).idldesc.wIDLFlags = IDLFLAG_FIN; + + memset(&funcdesc, 0, sizeof(FUNCDESC)); + funcdesc.funckind = FUNC_PUREVIRTUAL; + funcdesc.invkind = INVOKE_FUNC; + funcdesc.callconv = CC_STDCALL; + funcdesc.cParams = 2; + funcdesc.memid = 0x1; + funcdesc.elemdescFunc.tdesc.vt = VT_HRESULT; + funcdesc.lprgelemdescParam = elemdesc; + + hr = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc); + ok(hr == S_OK, "got %08x\n", hr); + + elemdesc2[0].tdesc.vt = VT_UINT; + U(elemdesc2[0]).idldesc.dwReserved = 0; + U(elemdesc2[0]).idldesc.wIDLFlags = IDLFLAG_FIN | IDLFLAG_FOUT; + + memset(&funcdesc2, 0, sizeof(FUNCDESC)); + funcdesc2.funckind = FUNC_PUREVIRTUAL; + funcdesc2.invkind = INVOKE_FUNC; + funcdesc.callconv = CC_STDCALL; + funcdesc2.cParams = 1; + funcdesc2.memid = 0x2; + funcdesc2.elemdescFunc.tdesc.vt = VT_HRESULT; + funcdesc2.lprgelemdescParam = elemdesc2; + + hr = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc2); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0xabcdefab); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetFuncHelpContext(createti, 1, 0xabcdefab); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names1, 3); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetFuncAndParamNames(createti, 1, names2, 2); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetTypeFlags(createti, TYPEFLAG_FOLEAUTOMATION | TYPEFLAG_FNONEXTENSIBLE | TYPEFLAG_FDUAL); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&tinfo); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ITypeInfo_GetRefTypeOfImplType(tinfo, 0, &hreftype); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetGuid(createti_co, &coclassguid); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_AddRefTypeInfo(createti_co, tinfo, &hreftype); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_AddImplType(createti_co, 0, hreftype); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_SetImplTypeFlags(createti_co, 0, IMPLTYPEFLAG_FDEFAULT); + ok(hr == S_OK, "got %08x\n", hr); + + hr = ICreateTypeInfo_Release(createti_co); + ok(hr == S_OK, "got %08x\n", hr); + + ICreateTypeInfo_Release(createti); + + hr = ICreateTypeLib2_SaveAllChanges(createtl); + ok(hr == S_OK, "got %08x\n", hr); + + ICreateTypeLib2_Release(createtl); + + trace("TypeLib to load: %ls\n", filename); + hr = LoadTypeLibEx(filename, REGKIND_NONE, &typelib); + ok(hr == S_OK, "got: %08x\n", hr); + + if(typelib) + { + hr = RegisterTypeLib(typelib, filename, NULL); + if (hr == TYPE_E_REGISTRYACCESS) + { + win_skip("Insufficient privileges to register typelib in the registry\n"); + ITypeLib_Release(typelib); + DeleteFileW(filename); + return; + } + ok(hr == S_OK, "got: %08x\n", hr); + + ITypeLib_Release(typelib); + } + + DeleteFileW(filename); +} + static void test_LoadTypeLib(void) { ITypeLib *tl; @@ -8351,6 +8530,7 @@ START_TEST(typelib)
test_register_typelib(TRUE); test_register_typelib(FALSE); + test_register_typelib_64(); test_create_typelibs(); test_LoadTypeLib(); test_TypeInfo2_GetContainingTypeLib(); diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index 70f15679811..ef546379174 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -629,10 +629,6 @@ HRESULT WINAPI RegisterTypeLib(ITypeLib *ptlib, const WCHAR *szFullPath, const W if (FAILED(ITypeLib_GetLibAttr(ptlib, &attr))) return E_FAIL;
-#ifndef _WIN64 - if (attr->syskind == SYS_WIN64) return TYPE_E_BADMODULEKIND; -#endif - get_typelib_key( &attr->guid, attr->wMajorVerNum, attr->wMinorVerNum, keyName );
res = S_OK;
Windows writes a typelib's name into the registry when the typelib doesn't provide a documentation.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- v2: Style improvements. --- dlls/oleaut32/tests/typelib.c | 39 +++++++++++++++++++++++++++++++++++ dlls/oleaut32/typelib.c | 34 +++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/dlls/oleaut32/tests/typelib.c b/dlls/oleaut32/tests/typelib.c index 78290c94dfe..fd83c3abb8a 100644 --- a/dlls/oleaut32/tests/typelib.c +++ b/dlls/oleaut32/tests/typelib.c @@ -6850,6 +6850,7 @@ static void test_register_typelib(BOOL system_registration)
static void test_register_typelib_64(void) { + REGSAM opposite = (sizeof(void*) == 8 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY); ICreateTypeInfo *createti, *createti_co; ELEMDESC elemdesc[5], elemdesc2[5]; FUNCDESC funcdesc, funcdesc2; @@ -6857,6 +6858,7 @@ static void test_register_typelib_64(void) ITypeLib *stdole, *typelib; ICreateTypeLib2 *createtl; WCHAR filename[MAX_PATH]; + BOOL is_wow64 = FALSE; HREFTYPE hreftype; HRESULT hr;
@@ -6879,6 +6881,9 @@ static void test_register_typelib_64(void)
static const SYSKIND sys = SYS_WIN64;
+ if (pIsWow64Process) + pIsWow64Process(GetCurrentProcess(), &is_wow64); + hr = LoadTypeLib(wszStdOle2, &stdole); ok(hr == S_OK, "got %08x\n", hr);
@@ -7011,6 +7016,11 @@ static void test_register_typelib_64(void)
if(typelib) { + WCHAR key_name[MAX_PATH], uuid[40]; + OLECHAR tlb_name[16]; + HKEY hkey; + LONG size; + hr = RegisterTypeLib(typelib, filename, NULL); if (hr == TYPE_E_REGISTRYACCESS) { @@ -7022,6 +7032,35 @@ static void test_register_typelib_64(void) ok(hr == S_OK, "got: %08x\n", hr);
ITypeLib_Release(typelib); + + StringFromGUID2(&tlcustguid, uuid, ARRAY_SIZE(uuid)); + swprintf(key_name, sizeof(key_name), L"TypeLib\%ls\1.0", uuid); + + hr = RegOpenKeyExW(HKEY_CLASSES_ROOT, key_name, 0, KEY_READ, &hkey); + ok(hr == S_OK, "got %08x\n", hr); + + size = sizeof(tlb_name); + hr = RegQueryValueW(hkey, L"", tlb_name, &size); + ok(hr == S_OK, "got %08x\n", hr); + + /* The typelib should be registered in WoW64_32 and WoW64_64 mode */ + if(is_win64 || is_wow64) + { + hr = RegOpenKeyExW(HKEY_CLASSES_ROOT, key_name, 0, KEY_READ | opposite, &hkey); + ok(hr == S_OK, "got %08x\n", hr); + + if(hkey) + { + size = sizeof(tlb_name); + hr = RegQueryValueW(hkey, L"", tlb_name, &size); + ok(hr == S_OK, "got %08x\n", hr); + + RegCloseKey(hkey); + } + } + + ok(!wcscmp(tlb_name, typelibW), + "Got unexpected TypLib description: %ls\n", tlb_name); }
DeleteFileW(filename); diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index ef546379174..9c18a383285 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -636,18 +636,36 @@ HRESULT WINAPI RegisterTypeLib(ITypeLib *ptlib, const WCHAR *szFullPath, const W KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) { LPOLESTR doc; + LPOLESTR libName; + BOOL nameSet = FALSE;
- /* Set the human-readable name of the typelib */ - if (FAILED(ITypeLib_GetDocumentation(ptlib, -1, NULL, &doc, NULL, NULL))) - res = E_FAIL; - else if (doc) + /* Set the human-readable name of the typelib to + the typelib's doc, if it exists, else to the typelib's name. */ + if (SUCCEEDED(ITypeLib_GetDocumentation(ptlib, -1, &libName, &doc, NULL, NULL))) { - if (RegSetValueExW(key, NULL, 0, REG_SZ, - (BYTE *)doc, (lstrlenW(doc)+1) * sizeof(OLECHAR)) != ERROR_SUCCESS) - res = E_FAIL; + if (doc) + { + if (RegSetValueExW(key, NULL, 0, REG_SZ, + (BYTE *)doc, (lstrlenW(doc)+1) * sizeof(OLECHAR)) != ERROR_SUCCESS) + res = E_FAIL; + + nameSet = TRUE; + SysFreeString(doc); + } + if(libName) + { + if(!nameSet) + { + if (RegSetValueExW(key, NULL, 0, REG_SZ, + (BYTE *)libName, (lstrlenW(libName)+1) * sizeof(OLECHAR)) != ERROR_SUCCESS) + res = E_FAIL; + }
- SysFreeString(doc); + SysFreeString(libName); + } } + else + res = E_FAIL;
/* Make up the name of the typelib path subkey */ if (!get_lcid_subkey( attr->lcid, attr->syskind, tmp )) res = E_FAIL;