VirtualBox

source: vbox/trunk/src/VBox/Installer/win/InstallHelper/VBoxCommon.cpp@ 99828

Last change on this file since 99828 was 99828, checked in by vboxsync, 17 months ago

*: A bunch of adjustments that allows using /permissive- with Visual C++ (qt 6.x necessity).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: VBoxCommon.cpp 99828 2023-05-17 13:48:57Z vboxsync $ */
2/** @file
3 * VBoxCommon - Misc helper routines for install helper.
4 *
5 * This is used by internal/serial.cpp and VBoxInstallHelper.cpp.
6 */
7
8/*
9 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30
31/*********************************************************************************************************************************
32* Header Files *
33*********************************************************************************************************************************/
34#include <iprt/win/windows.h>
35#include <msi.h>
36#include <msiquery.h>
37
38#include <iprt/string.h>
39#include <iprt/utf16.h>
40
41
42UINT VBoxGetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, WCHAR *pwszValueBuf, DWORD cwcValueBuf)
43{
44 RT_BZERO(pwszValueBuf, cwcValueBuf * sizeof(pwszValueBuf[0]));
45
46 /** @todo r=bird: why do we need to query the size first and then the data.
47 * The API should be perfectly capable of doing that without our help. */
48 WCHAR wcDummy = 0;
49 DWORD cwcNeeded = 0;
50 UINT uiRet = MsiGetPropertyW(hMsi, pwszName, &wcDummy, &cwcNeeded);
51 if (uiRet == ERROR_MORE_DATA)
52 {
53 ++cwcNeeded; /* On output does not include terminating null, so add 1. */
54
55 if (cwcNeeded > cwcValueBuf)
56 return ERROR_MORE_DATA;
57 uiRet = MsiGetPropertyW(hMsi, pwszName, pwszValueBuf, &cwcNeeded);
58 }
59 return uiRet;
60}
61
62#if 0 /* unused */
63/**
64 * Retrieves a MSI property (in UTF-8).
65 *
66 * Convenience function for VBoxGetMsiProp().
67 *
68 * @returns VBox status code.
69 * @param hMsi MSI handle to use.
70 * @param pcszName Name of property to retrieve.
71 * @param ppszValue Where to store the allocated value on success.
72 * Must be free'd using RTStrFree() by the caller.
73 */
74int VBoxGetMsiPropUtf8(MSIHANDLE hMsi, const char *pcszName, char **ppszValue)
75{
76 PRTUTF16 pwszName;
77 int rc = RTStrToUtf16(pcszName, &pwszName);
78 if (RT_SUCCESS(rc))
79 {
80 WCHAR wszValue[1024]; /* 1024 should be enough for everybody (tm). */
81 if (VBoxGetMsiProp(hMsi, pwszName, wszValue, sizeof(wszValue)) == ERROR_SUCCESS)
82 rc = RTUtf16ToUtf8(wszValue, ppszValue);
83 else
84 rc = VERR_NOT_FOUND;
85
86 RTUtf16Free(pwszName);
87 }
88
89 return rc;
90}
91#endif
92
93UINT VBoxSetMsiProp(MSIHANDLE hMsi, const WCHAR *pwszName, const WCHAR *pwszValue)
94{
95 return MsiSetPropertyW(hMsi, pwszName, pwszValue);
96}
97
98UINT VBoxSetMsiPropDWORD(MSIHANDLE hMsi, const WCHAR *pwszName, DWORD dwVal)
99{
100 wchar_t wszTemp[32];
101 RTUtf16Printf(wszTemp, RT_ELEMENTS(wszTemp), "%u", dwVal);
102 return VBoxSetMsiProp(hMsi, pwszName, wszTemp);
103}
104
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette