diff options
Diffstat (limited to 'shell/source/win32/spsupp')
-rw-r--r-- | shell/source/win32/spsupp/registrar.cxx | 51 | ||||
-rw-r--r-- | shell/source/win32/spsupp/spsuppServ.cxx | 20 |
2 files changed, 48 insertions, 23 deletions
diff --git a/shell/source/win32/spsupp/registrar.cxx b/shell/source/win32/spsupp/registrar.cxx index 7c3bbb881612..008c2ac59c82 100644 --- a/shell/source/win32/spsupp/registrar.cxx +++ b/shell/source/win32/spsupp/registrar.cxx @@ -76,7 +76,7 @@ namespace { return HRESULT_FROM_WIN32(iRetVal); } -} +} // namespace // see http://stackoverflow.com/questions/284619 // see https://msdn.microsoft.com/en-us/library/ms691424 @@ -88,12 +88,9 @@ Registrar::Registrar(REFIID riidCLSID) E_UNEXPECTED: S_OK; } -HRESULT Registrar::RegisterObject(REFIID riidTypeLib, - const wchar_t* sProgram, - const wchar_t* sComponent, - int nVersion, - const wchar_t* Path, - bool bSetDefault) +HRESULT Registrar::RegisterObject(REFIID riidTypeLib, const wchar_t* sProgram, + const wchar_t* sComponent, std::initializer_list<int> aVersions, + const wchar_t* Path) { if (!wcslen(sComponent) || !wcslen(sProgram)) return E_INVALIDARG; @@ -167,15 +164,16 @@ HRESULT Registrar::RegisterObject(REFIID riidTypeLib, } // ProgID - return RegisterProgID(sProgram, sComponent, nVersion, bSetDefault); + return RegisterProgIDs(sProgram, sComponent, aVersions); } -HRESULT Registrar::UnRegisterObject(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion) +HRESULT Registrar::UnRegisterObject(const wchar_t* sProgram, const wchar_t* sComponent, + std::initializer_list<int> aVersions) { if (FAILED(m_ConstructionResult)) return m_ConstructionResult; // ProgID - UnRegisterProgID(sProgram, sComponent, nVersion); + UnRegisterProgIDs(sProgram, sComponent, aVersions); // CLSID wchar_t sBuf[MAX_PATH]; swprintf(sBuf, MAX_PATH, L"CLSID\\%s\\InProcServer32", m_sCLSID); @@ -187,7 +185,8 @@ HRESULT Registrar::UnRegisterObject(const wchar_t* sProgram, const wchar_t* sCom swprintf(sBuf, MAX_PATH, L"CLSID\\%s\\TypeLib", m_sCLSID); RegDel(HKEY_CLASSES_ROOT, sBuf); swprintf(sBuf, MAX_PATH, L"CLSID\\%s", m_sCLSID); - return RegDel(HKEY_CLASSES_ROOT, sBuf); + RegDel(HKEY_CLASSES_ROOT, sBuf); + return S_OK; } HRESULT Registrar::RegisterProgID(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion, bool bSetDefault) @@ -222,6 +221,22 @@ HRESULT Registrar::RegisterProgID(const wchar_t* sProgram, const wchar_t* sCompo return hr; } +HRESULT Registrar::RegisterProgIDs(const wchar_t* sProgram, const wchar_t* sComponent, + std::initializer_list<int> aVersions) +{ + HRESULT hr = S_OK; + bool bDefaultRegistered = false; + for (int nVersion : aVersions) + { + if (SUCCEEDED(hr)) + { + hr = RegisterProgID(sProgram, sComponent, nVersion, !bDefaultRegistered); + bDefaultRegistered = true; + } + } + return hr; +} + HRESULT Registrar::UnRegisterProgID(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion) { if (FAILED(m_ConstructionResult)) @@ -258,4 +273,18 @@ HRESULT Registrar::UnRegisterProgID(const wchar_t* sProgram, const wchar_t* sCom return hr; } +HRESULT Registrar::UnRegisterProgIDs(const wchar_t* sProgram, const wchar_t* sComponent, + std::initializer_list<int> aVersions) +{ + HRESULT hr = S_OK; + // Try all ProgIDs regardless of error, but make sure to return failure result if some failed + for (int nVersion : aVersions) + { + HRESULT hrLast = UnRegisterProgID(sProgram, sComponent, nVersion); + if (SUCCEEDED(hr)) + hr = hrLast; + } + return hr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/spsupp/spsuppServ.cxx b/shell/source/win32/spsupp/spsuppServ.cxx index 64b2090c4cf9..c5b10e53b943 100644 --- a/shell/source/win32/spsupp/spsuppServ.cxx +++ b/shell/source/win32/spsupp/spsuppServ.cxx @@ -128,7 +128,9 @@ STDAPI DllRegisterServer(void) if (FAILED(hr)) return hr; - return Registrar(CLSID_spsupp).RegisterObject(LIBID_spsupp, L"LOSPSupport", L"OpenDocuments", 1, szFile, true); + // Default is v.5 + return Registrar(CLSID_spsupp) + .RegisterObject(LIBID_spsupp, L"LOSPSupport", L"OpenDocuments", { 5, 1, 2, 3, 4 }, szFile); } STDAPI DllUnregisterServer(void) @@ -148,7 +150,8 @@ STDAPI DllUnregisterServer(void) if (FAILED(hr)) return hr; - return Registrar(CLSID_spsupp).UnRegisterObject(L"LOSPSupport", L"OpenDocuments", 1); + return Registrar(CLSID_spsupp) + .UnRegisterObject(L"LOSPSupport", L"OpenDocuments", { 1, 2, 3, 4, 5 }); } // This is called when regsvr32.exe is called with "/i" flag @@ -162,19 +165,12 @@ STDAPI DllInstall(BOOL bInstall, _In_opt_ PCWSTR pszCmdLine) Registrar registrar(CLSID_spsupp); if (bInstall) { - hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 3, true); - if (SUCCEEDED(hr)) - hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 2, false); - if (SUCCEEDED(hr)) - hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 1, false); + // Default is v.5 + hr = registrar.RegisterProgIDs(L"SharePoint", L"OpenDocuments", { 5, 1, 2, 3, 4 }); } else { - // Try all ProgIDs regardless of error, but make sure to return failure result if at least one failed - hr = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 1); - HRESULT hrLast; - hr = SUCCEEDED(hrLast = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 2)) ? hr : hrLast; - hr = SUCCEEDED(hrLast = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 3)) ? hr : hrLast; + hr = registrar.UnRegisterProgIDs(L"SharePoint", L"OpenDocuments", { 1, 2, 3, 4, 5 }); } return hr; } |