Kaydet (Commit) a11536d5 authored tarafından Mike Kaganski's avatar Mike Kaganski

Use lambdas to initialize statics

Change-Id: Ib03bfd795967ba70333d71d9e5eeec97be90be79
Reviewed-on: https://gerrit.libreoffice.org/72334
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 38ea76ed
...@@ -37,35 +37,33 @@ HANDLE g_hModule; ...@@ -37,35 +37,33 @@ HANDLE g_hModule;
ITypeLib* GetTypeLib() ITypeLib* GetTypeLib()
{ {
typedef std::unique_ptr<ITypeLib, void(*)(IUnknown* p)> ITypeLibGuard; typedef std::unique_ptr<ITypeLib, void(*)(IUnknown* p)> ITypeLibGuard;
static ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); }); static ITypeLibGuard s_aITypeLibGuard = [] {
if (!aITypeLibGuard.get()) ITypeLibGuard aITypeLibGuard(nullptr, [](IUnknown* p) { if (p) p->Release(); });
{
wchar_t szFile[MAX_PATH]; wchar_t szFile[MAX_PATH];
if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), szFile, MAX_PATH) == 0) if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), szFile, MAX_PATH) == 0)
return nullptr; return aITypeLibGuard;
ITypeLib* pTypeLib; ITypeLib* pTypeLib;
HRESULT hr = LoadTypeLib(szFile, &pTypeLib); if (FAILED(LoadTypeLib(szFile, &pTypeLib)))
if (FAILED(hr)) return aITypeLibGuard;
return nullptr;
aITypeLibGuard.reset(pTypeLib); aITypeLibGuard.reset(pTypeLib);
} return aITypeLibGuard;
return aITypeLibGuard.get(); }();
return s_aITypeLibGuard.get();
} }
const wchar_t* GetLOPath() const wchar_t* GetLOPath()
{ {
static wchar_t sPath[MAX_PATH] = { 0 }; static wchar_t* s_sPath = []() -> wchar_t* {
if (*sPath == 0) static wchar_t sPath[MAX_PATH];
{
// Initialization
if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), sPath, MAX_PATH) == 0) if (GetModuleFileNameW(static_cast<HMODULE>(g_hModule), sPath, MAX_PATH) == 0)
return nullptr; return nullptr;
wchar_t* pSlashPos = wcsrchr(sPath, L'\\'); wchar_t* pSlashPos = wcsrchr(sPath, L'\\');
if (pSlashPos == nullptr) if (pSlashPos == nullptr)
return nullptr; return nullptr;
wcscpy(pSlashPos+1, L"soffice.exe"); wcscpy(pSlashPos + 1, L"soffice.exe");
} return sPath;
return sPath; }();
return s_sPath;
} }
BOOL APIENTRY DllMain( HANDLE hinstDLL, BOOL APIENTRY DllMain( HANDLE hinstDLL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment