From 0213ebefbef39e0766ce56a1e60a41a2edbb8421 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 10 Aug 2020 11:12:50 +0300 Subject: [PATCH] combase: Move ProgIDFromCLSID(). Signed-off-by: Nikolay Sivov Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/combase/combase.c | 84 +++++++++++++++++++++++++++++++++++++++ dlls/combase/combase.spec | 2 +- dlls/ole32/compobj.c | 73 ---------------------------------- dlls/ole32/ole32.spec | 2 +- 4 files changed, 86 insertions(+), 75 deletions(-) diff --git a/dlls/combase/combase.c b/dlls/combase/combase.c index a757407c71e..6b8eb4ee7a9 100644 --- a/dlls/combase/combase.c +++ b/dlls/combase/combase.c @@ -33,6 +33,28 @@ WINE_DEFAULT_DEBUG_CHANNEL(ole); #define CHARS_IN_GUID 39 +struct comclassredirect_data +{ + ULONG size; + ULONG flags; + DWORD model; + GUID clsid; + GUID alias; + GUID clsid2; + GUID tlbid; + ULONG name_len; + ULONG name_offset; + ULONG progid_len; + ULONG progid_offset; + ULONG clrdata_len; + ULONG clrdata_offset; + DWORD miscstatus; + DWORD miscstatuscontent; + DWORD miscstatusthumbnail; + DWORD miscstatusicon; + DWORD miscstatusdocprint; +}; + static NTSTATUS create_key(HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr) { NTSTATUS status = NtCreateKey((HANDLE *)retkey, access, attr, 0, NULL, 0, NULL); @@ -831,6 +853,68 @@ done: return hr; } +/****************************************************************************** + * ProgIDFromCLSID (combase.@) + */ +HRESULT WINAPI DECLSPEC_HOTPATCH ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *progid) +{ + ACTCTX_SECTION_KEYED_DATA data; + LONG progidlen = 0; + HKEY hkey; + HRESULT hr; + + if (!progid) + return E_INVALIDARG; + + *progid = NULL; + + data.cbSize = sizeof(data); + if (FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, + clsid, &data)) + { + struct comclassredirect_data *comclass = (struct comclassredirect_data *)data.lpData; + if (comclass->progid_len) + { + WCHAR *ptrW; + + *progid = CoTaskMemAlloc(comclass->progid_len + sizeof(WCHAR)); + if (!*progid) return E_OUTOFMEMORY; + + ptrW = (WCHAR *)((BYTE *)comclass + comclass->progid_offset); + memcpy(*progid, ptrW, comclass->progid_len + sizeof(WCHAR)); + return S_OK; + } + else + return REGDB_E_CLASSNOTREG; + } + + hr = open_key_for_clsid(clsid, L"ProgID", KEY_READ, &hkey); + if (FAILED(hr)) + return hr; + + if (RegQueryValueW(hkey, NULL, NULL, &progidlen)) + hr = REGDB_E_CLASSNOTREG; + + if (hr == S_OK) + { + *progid = CoTaskMemAlloc(progidlen * sizeof(WCHAR)); + if (*progid) + { + if (RegQueryValueW(hkey, NULL, *progid, &progidlen)) + { + hr = REGDB_E_CLASSNOTREG; + CoTaskMemFree(*progid); + *progid = NULL; + } + } + else + hr = E_OUTOFMEMORY; + } + + RegCloseKey(hkey); + return hr; +} + static void init_multi_qi(DWORD count, MULTI_QI *mqi, HRESULT hr) { ULONG i; diff --git a/dlls/combase/combase.spec b/dlls/combase/combase.spec index 497af6da8c0..a90a418764d 100644 --- a/dlls/combase/combase.spec +++ b/dlls/combase/combase.spec @@ -279,7 +279,7 @@ @ stub NdrExtStubInitialize @ stub NdrOleDllGetClassObject @ stub NdrpFindInterface -@ stdcall ProgIDFromCLSID(ptr ptr) ole32.ProgIDFromCLSID +@ stdcall ProgIDFromCLSID(ptr ptr) @ stdcall PropVariantClear(ptr) @ stdcall PropVariantCopy(ptr ptr) @ stub ReleaseFuncDescs diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 1f6a952f15a..47b815b752e 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -2485,79 +2485,6 @@ HRESULT COM_OpenKeyForAppIdFromCLSID(REFCLSID clsid, REGSAM access, HKEY *subkey return S_OK; } -/****************************************************************************** - * ProgIDFromCLSID [OLE32.@] - * - * Converts a class id into the respective program ID. - * - * PARAMS - * clsid [I] Class ID, as found in registry. - * ppszProgID [O] Associated ProgID. - * - * RETURNS - * S_OK - * E_OUTOFMEMORY - * REGDB_E_CLASSNOTREG if the given clsid has no associated ProgID - */ -HRESULT WINAPI DECLSPEC_HOTPATCH ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *ppszProgID) -{ - static const WCHAR wszProgID[] = {'P','r','o','g','I','D',0}; - ACTCTX_SECTION_KEYED_DATA data; - HKEY hkey; - HRESULT ret; - LONG progidlen = 0; - - if (!ppszProgID) - return E_INVALIDARG; - - *ppszProgID = NULL; - - data.cbSize = sizeof(data); - if (FindActCtxSectionGuid(0, NULL, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, - clsid, &data)) - { - struct comclassredirect_data *comclass = (struct comclassredirect_data*)data.lpData; - if (comclass->progid_len) - { - WCHAR *ptrW; - - *ppszProgID = CoTaskMemAlloc(comclass->progid_len + sizeof(WCHAR)); - if (!*ppszProgID) return E_OUTOFMEMORY; - - ptrW = (WCHAR*)((BYTE*)comclass + comclass->progid_offset); - memcpy(*ppszProgID, ptrW, comclass->progid_len + sizeof(WCHAR)); - return S_OK; - } - else - return REGDB_E_CLASSNOTREG; - } - - ret = COM_OpenKeyForCLSID(clsid, wszProgID, KEY_READ, &hkey); - if (FAILED(ret)) - return ret; - - if (RegQueryValueW(hkey, NULL, NULL, &progidlen)) - ret = REGDB_E_CLASSNOTREG; - - if (ret == S_OK) - { - *ppszProgID = CoTaskMemAlloc(progidlen * sizeof(WCHAR)); - if (*ppszProgID) - { - if (RegQueryValueW(hkey, NULL, *ppszProgID, &progidlen)) { - ret = REGDB_E_CLASSNOTREG; - CoTaskMemFree(*ppszProgID); - *ppszProgID = NULL; - } - } - else - ret = E_OUTOFMEMORY; - } - - RegCloseKey(hkey); - return ret; -} - /****************************************************************************** * CLSIDFromProgID [OLE32.@] * diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec index e51b2b5887d..74eb6f01062 100644 --- a/dlls/ole32/ole32.spec +++ b/dlls/ole32/ole32.spec @@ -237,7 +237,7 @@ @ stdcall OleTranslateAccelerator(ptr ptr ptr) @ stdcall OleUninitialize() @ stub OpenOrCreateStream -@ stdcall ProgIDFromCLSID(ptr ptr) +@ stdcall ProgIDFromCLSID(ptr ptr) combase.ProgIDFromCLSID @ stdcall PropStgNameToFmtId(wstr ptr) @ stdcall PropSysAllocString(wstr) @ stdcall PropSysFreeString(wstr)