VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/nt/ntDisplay.cpp@ 100945

Last change on this file since 100945 was 100945, checked in by vboxsync, 21 months ago

ValKit: Added ntDisplay.exe utility, it will contain various tests for Virtual Display device, svn properties corrected

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: ntDisplay.cpp 100945 2023-08-22 17:15:54Z vboxsync $ */
2/** @file
3 * Test cases for Display device and DirectX 3D rendering - NT.
4 */
5
6/*
7 * Copyright (C) 2007-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.215389.xyz.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/win/windows.h>
42#include <iprt/win/setupapi.h>
43#include <devguid.h>
44
45#include <iprt/initterm.h>
46#include <iprt/getopt.h>
47#include <iprt/message.h>
48#include <iprt/stream.h>
49#include <iprt/string.h>
50#include <iprt/thread.h>
51#include <iprt/errcore.h>
52
53/*********************************************************************************************************************************
54* Global Variables *
55*********************************************************************************************************************************/
56/** How chatty we should be. */
57static uint32_t g_cVerbosity = 0;
58
59NTSTATUS SetDisplayDeviceState(bool bEnable)
60{
61 HDEVINFO hDevs = NULL;
62 SP_DEVINFO_DATA DevInfo;
63 NTSTATUS rcNt = (NTSTATUS)0;
64
65 hDevs = SetupDiGetClassDevs(&GUID_DEVCLASS_DISPLAY, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
66
67 if (hDevs == INVALID_HANDLE_VALUE)
68 {
69 rcNt = GetLastError();
70 RTMsgError("SetupDiGetClassDevs failed: %#x\n", rcNt);
71 return rcNt;
72 }
73
74 RT_ZERO(DevInfo);
75 DevInfo.cbSize = sizeof(SP_DEVINFO_DATA);
76
77 if (SetupDiEnumDeviceInfo(hDevs, 0, &DevInfo))
78 {
79 SP_PROPCHANGE_PARAMS PropChangeParams;
80
81 RT_ZERO(PropChangeParams);
82 PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
83 PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
84 PropChangeParams.StateChange = bEnable ? DICS_ENABLE : DICS_DISABLE;
85 PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
86 PropChangeParams.HwProfile = 0;
87
88 if (SetupDiSetClassInstallParams(hDevs, &DevInfo, &PropChangeParams.ClassInstallHeader, sizeof(PropChangeParams)))
89 {
90 if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevs, &DevInfo))
91 {
92 if (g_cVerbosity >= 1)
93 RTPrintf("debug: device %s\n", bEnable ? "enabled" : "disabled");
94 }
95 else
96 {
97 rcNt = GetLastError();
98 RTMsgError("SetupDiCallClassInstaller failed: %#x\n", rcNt);
99 }
100 }
101 else
102 {
103 rcNt = GetLastError();
104 RTMsgError("SetupDiSetClassInstallParams failed: %#x\n", rcNt);
105 }
106 }
107
108 SetupDiDestroyDeviceInfoList(hDevs);
109
110 return rcNt;
111}
112
113int main(int argc, char **argv)
114{
115 /*
116 * Init IPRT.
117 */
118 int rc = RTR3InitExe(argc, &argv, 0);
119 if (RT_FAILURE(rc))
120 return RTMsgInitFailure(rc);
121
122 /*
123 * Parse arguments.
124 */
125 bool fEnable = true;
126
127 static const RTGETOPTDEF s_aOptions[] =
128 {
129 { "--enable", 'e', RTGETOPT_REQ_UINT32 },
130 { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
131 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
132 };
133
134 RTGETOPTSTATE State;
135 RTGetOptInit(&State, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
136 RTGETOPTUNION ValueUnion;
137 int chOpt;
138 while ((chOpt = RTGetOpt(&State, &ValueUnion)) != 0)
139 {
140 switch (chOpt)
141 {
142 case 'e': fEnable = RT_BOOL(ValueUnion.u32); break;
143 case 'q': g_cVerbosity = 0; break;
144 case 'v': g_cVerbosity += 1; break;
145 case 'h':
146 RTPrintf("usage: ntDisplay.exe [-e|--enable <0 or 1>]\n");
147 return 0;
148
149 default:
150 return RTGetOptPrintError(chOpt, &ValueUnion);
151 }
152 }
153
154 NTSTATUS rcNt = SetDisplayDeviceState(fEnable);
155
156 return RTErrConvertFromNtStatus(rcNt);
157}
Note: See TracBrowser for help on using the repository browser.

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