tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / shell / source / win32 / shlxthandler / util / registry.cxx
blob209eb399c9234d244d8be268c714d6cc4d43d938
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #if !defined WIN32_LEAN_AND_MEAN
22 # define WIN32_LEAN_AND_MEAN
23 #endif
24 #include <windows.h>
26 #include <malloc.h>
27 #include <registry.hxx>
29 #include <objbase.h>
31 bool SetRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, const Filepath_char_t* Value)
33 int rc = RegSetKeyValueW(RootKey, KeyName, ValueName, REG_SZ, Value,
34 (wcslen(Value) + 1) * sizeof(*Value));
35 return (ERROR_SUCCESS == rc);
38 bool DeleteRegistryTree(HKEY RootKey, const Filepath_char_t* KeyName)
40 return (ERROR_SUCCESS == RegDeleteTreeW(RootKey, KeyName));
43 bool DeleteRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName)
45 return (ERROR_SUCCESS == RegDeleteKeyW(RootKey, KeyName));
48 // Convert a CLSID to a char string.
49 Filepath_t ClsidToString(const CLSID& clsid)
51 wchar_t wszCLSID[std::size(L"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}")];
52 if (StringFromGUID2(clsid, wszCLSID, std::size(wszCLSID)))
53 return std::wstring(wszCLSID);
54 return {};
58 bool QueryRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, Filepath_char_t *pszData, DWORD dwBufLen)
60 DWORD dwBytes = dwBufLen * sizeof(*pszData);
61 LSTATUS rc = RegGetValueW(RootKey, KeyName, ValueName, RRF_RT_REG_SZ, nullptr,
62 pszData, &dwBytes);
63 return (ERROR_SUCCESS == rc);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */