Debian Codegraph @

shell/source/win32/shlxthandler/util/registry.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21 #if !defined WIN32_LEAN_AND_MEAN
22 # define WIN32_LEAN_AND_MEAN
23 #endif
24 #include <windows.h>
25
26 #include <malloc.h>
27 #include <registry.hxx>
28
29 #include <objbase.h>
30
31 bool SetRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, const Filepath_char_t* Value)
32 {
33 int rc = RegSetKeyValueW(RootKey, KeyName, ValueName, REG_SZ, Value,
34 (wcslen(Value) + 1) * sizeof(*Value));
35 return (ERROR_SUCCESS == rc);
36 }
37
38 bool DeleteRegistryTree(HKEY RootKey, const Filepath_char_t* KeyName)
39 {
40 return (ERROR_SUCCESS == RegDeleteTreeW(RootKey, KeyName));
41 }
42
43 bool DeleteRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName)
44 {
45 return (ERROR_SUCCESS == RegDeleteKeyW(RootKey, KeyName));
46 }
47
48 // Convert a CLSID to a char string.
49 Filepath_t ClsidToString(const CLSID& clsid)
50 {
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 {};
55 }
56
57
58 bool QueryRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, Filepath_char_t *pszData, DWORD dwBufLen)
59 {
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);
64 }
65
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */