ReactOS 0.4.16-dev-297-gc569aee
control.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <winreg.h>
#include <shellapi.h>
#include <strsafe.h>
#include <objbase.h>
#include <shobjidl.h>
#include <shlguid.h>
#include "resource.h"
Include dependency graph for control.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define COBJMACROS
 
#define MAX_VALUE_NAME   16383
 
#define RUNDLL(param)    ((INT_PTR)ShellExecuteW(NULL, L"open", L"rundll32.exe", (param), NULL, SW_SHOWDEFAULT) > 32)
 

Functions

VOID WINAPI Control_RunDLLW (HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow)
 
static BOOL IsSwitch (LPCWSTR Switch, LPCWSTR Arg)
 
static HRESULT OpenControlPanelItem (LPCWSTR Name, LPCWSTR Page)
 
static INT OpenShellFolder (LPWSTR lpFolderCLSID)
 
static INT RunControlPanel (LPCWSTR lpCmd)
 
INT WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 13 of file control.c.

◆ MAX_VALUE_NAME

#define MAX_VALUE_NAME   16383

Definition at line 28 of file control.c.

◆ RUNDLL

#define RUNDLL (   param)     ((INT_PTR)ShellExecuteW(NULL, L"open", L"rundll32.exe", (param), NULL, SW_SHOWDEFAULT) > 32)

Definition at line 35 of file control.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 12 of file control.c.

Function Documentation

◆ Control_RunDLLW()

VOID WINAPI Control_RunDLLW ( HWND  hWnd,
HINSTANCE  hInst,
LPCWSTR  cmd,
DWORD  nCmdShow 
)

Definition at line 1173 of file control.c.

1174{
1175 CPanel panel;
1176
1177 TRACE("(%p, %p, %s, 0x%08x)\n",
1178 hWnd, hInst, debugstr_w(cmd), nCmdShow);
1179
1180#ifndef __REACTOS__
1181 memset(&panel, 0, sizeof(panel));
1182 list_init( &panel.applets );
1183#endif
1184
1185 if (!cmd || !*cmd) {
1186 Control_DoWindow(&panel, hWnd, hInst);
1187 } else {
1188 Control_DoLaunch(&panel, hWnd, cmd);
1189 }
1190}
HWND hWnd
Definition: settings.c:17
static void list_init(struct list_entry *head)
Definition: list.h:51
static void Control_DoWindow(CPanel *panel, HWND hWnd, HINSTANCE hInst)
Definition: control.c:703
static void Control_DoLaunch(CPanel *panel, HWND hWnd, LPCWSTR wszCmd)
Definition: control.c:867
HINSTANCE hInst
Definition: dxdiag.c:13
#define debugstr_w
Definition: kernel32.h:32
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cpanel.h:56
struct list applets
Definition: cpanel.h:57
Definition: ftp_var.h:139

Referenced by Control_RunDLLA().

◆ IsSwitch()

static BOOL IsSwitch ( LPCWSTR  Switch,
LPCWSTR  Arg 
)
static

Definition at line 43 of file control.c.

44{
45 if (*Arg == '/' || *Arg == '-')
46 {
47 return !lstrcmpiW(Arg+1, Switch);
48 }
49 return FALSE;
50}
#define FALSE
Definition: types.h:117
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4262

Referenced by wWinMain().

◆ OpenControlPanelItem()

static HRESULT OpenControlPanelItem ( LPCWSTR  Name,
LPCWSTR  Page 
)
static

Definition at line 53 of file control.c.

54{
56 if (SUCCEEDED(hr))
57 {
58 IOpenControlPanel *pOCP;
59 hr = CoCreateInstance(&CLSID_OpenControlPanel, NULL, CLSCTX_INPROC_SERVER,
60 &IID_IOpenControlPanel, (void**)&pOCP);
61 if (SUCCEEDED(hr))
62 {
63 hr = IOpenControlPanel_Open(pOCP, Name, Page, NULL);
64 IOpenControlPanel_Release(pOCP);
65 }
67 }
68 return hr;
69}
#define NULL
Definition: types.h:112
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define SUCCEEDED(hr)
Definition: intsafe.h:50
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
Definition: mm.h:1306
HRESULT hr
Definition: shlfolder.c:183

Referenced by wWinMain().

◆ OpenShellFolder()

static INT OpenShellFolder ( LPWSTR  lpFolderCLSID)
static

Definition at line 72 of file control.c.

73{
74 WCHAR szParameters[MAX_PATH];
75
76 /*
77 * Open a shell folder using "explorer.exe". If Explorer shell is not
78 * available, use ReactOS's alternative file browser instead.
79 * The passed CLSIDs are all subfolders of the "Control Panel" shell folder.
80 */
81 StringCbCopyW(szParameters, sizeof(szParameters), L"/n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}");
82 StringCbCatW(szParameters, sizeof(szParameters), lpFolderCLSID);
83
85 L"open",
86 GetShellWindow() ? L"explorer.exe" : L"filebrowser.exe",
87 szParameters,
88 NULL,
89 SW_SHOWDEFAULT) > 32;
90}
#define MAX_PATH
Definition: compat.h:34
#define L(x)
Definition: ntvdm.h:50
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2492
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
int32_t INT_PTR
Definition: typedefs.h:64
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
#define SW_SHOWDEFAULT
Definition: winuser.h:783
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wWinMain().

◆ RunControlPanel()

static INT RunControlPanel ( LPCWSTR  lpCmd)
static

Definition at line 93 of file control.c.

94{
95 WCHAR szParameters[MAX_PATH];
96 StringCchCopyW(szParameters, ARRAYSIZE(szParameters), L"shell32.dll,Control_RunDLL ");
97 if (FAILED(StringCchCatW(szParameters, ARRAYSIZE(szParameters), lpCmd)))
98 return 0;
99
100 return RUNDLL(szParameters);
101}
#define RUNDLL(param)
Definition: control.c:35
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define FAILED(hr)
Definition: intsafe.h:51
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149

Referenced by DECLARE_INTERFACE_(), and wWinMain().

◆ wWinMain()

INT WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 105 of file control.c.

109{
110 HKEY hKey;
111 LPWSTR *argv;
112 int argc;
113
114 /* Show the control panel window if no argument or "panel" was passed */
115 if (*lpCmdLine == 0 || !_wcsicmp(lpCmdLine, L"panel"))
116 return OpenShellFolder(L"");
117
118 /* Map legacy control panels */
119 if (!_wcsicmp(lpCmdLine, L"sticpl.cpl")) lpCmdLine = (LPWSTR) L"scannercamera";
120
121 /* Check one of the built-in control panel handlers */
122 if (!_wcsicmp(lpCmdLine, L"admintools")) return OpenShellFolder(L"\\::{D20EA4E1-3957-11d2-A40B-0C5020524153}");
123 else if (!_wcsicmp(lpCmdLine, L"color")) return RunControlPanel(L"desk.cpl,,2");
124 else if (!_wcsicmp(lpCmdLine, L"date/time")) return RunControlPanel(L"timedate.cpl");
125 else if (!_wcsicmp(lpCmdLine, L"desktop")) return RunControlPanel(L"desk.cpl");
126 else if (!_wcsicmp(lpCmdLine, L"folders")) return RUNDLL(L"shell32.dll,Options_RunDLL");
127 else if (!_wcsicmp(lpCmdLine, L"fonts")) return OpenShellFolder(L"\\::{D20EA4E1-3957-11d2-A40B-0C5020524152}");
128 else if (!_wcsicmp(lpCmdLine, L"infrared")) return RunControlPanel(L"irprops.cpl");
129 else if (!_wcsicmp(lpCmdLine, L"international")) return RunControlPanel(L"intl.cpl");
130 else if (!_wcsicmp(lpCmdLine, L"keyboard")) return RunControlPanel(L"main.cpl @1");
131 else if (!_wcsicmp(lpCmdLine, L"mouse")) return RunControlPanel(L"main.cpl @0");
132 else if (!_wcsicmp(lpCmdLine, L"netconnections")) return OpenShellFolder(L"\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}");
133 else if (!_wcsicmp(lpCmdLine, L"netware")) return RunControlPanel(L"nwc.cpl");
134 else if (!_wcsicmp(lpCmdLine, L"ports")) return RunControlPanel(L"sysdm.cpl,,1");
135 else if (!_wcsicmp(lpCmdLine, L"printers")) return OpenShellFolder(L"\\::{2227A280-3AEA-1069-A2DE-08002B30309D}");
136 else if (!_wcsicmp(lpCmdLine, L"scannercamera")) return OpenShellFolder(L"\\::{E211B736-43FD-11D1-9EFB-0000F8757FCD}");
137 else if (!_wcsicmp(lpCmdLine, L"schedtasks")) return OpenShellFolder(L"\\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}");
138 else if (!_wcsicmp(lpCmdLine, L"telephony")) return RunControlPanel(L"telephon.cpl");
139 else if (!_wcsicmp(lpCmdLine, L"userpasswords")) return RunControlPanel(L"nusrmgr.cpl"); /* Graphical User Account Manager */
140 else if (!_wcsicmp(lpCmdLine, L"userpasswords2")) return RUNDLL(L"netplwiz.dll,UsersRunDll"); /* Dialog based advanced User Account Manager */
141
142 /* https://learn.microsoft.com/en-us/windows/win32/shell/executing-control-panel-items#windows-vista-canonical-names */
143 argv = CommandLineToArgvW(lpCmdLine, &argc);
144 if (argv)
145 {
146 UINT argi = 0;
147 HRESULT hr = -1;
148 if (argc >= 2 && IsSwitch(L"name", argv[argi + 0]))
149 {
150 LPCWSTR pszPage = NULL;
151 if (argc >= 4 && IsSwitch(L"page", argv[argi + 2]))
152 {
153 pszPage = argv[argi + 3];
154 }
155 hr = OpenControlPanelItem(argv[argi + 1], pszPage);
156 }
158 if (hr != -1)
159 {
160 return SUCCEEDED(hr);
161 }
162 }
163
164 /* It is none of them, so look for a handler in the registry */
166 L"Software\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls",
167 0,
169 &hKey) == ERROR_SUCCESS)
170 {
171 DWORD dwIndex;
172
173 for (dwIndex = 0; ; ++dwIndex)
174 {
175 DWORD dwDataSize;
176 DWORD dwValueSize = MAX_VALUE_NAME;
177 WCHAR szValueName[MAX_VALUE_NAME];
178
179 /* Get the value name and data size */
181 dwIndex,
182 szValueName,
183 &dwValueSize,
184 0,
185 NULL,
186 NULL,
187 &dwDataSize) != ERROR_SUCCESS)
188 {
189 break;
190 }
191
192 /* Check if the parameter is the value name */
193 if (!_wcsicmp(lpCmdLine, szValueName))
194 {
195 /*
196 * Allocate memory for the data plus two more characters,
197 * so we can quote the file name if required.
198 */
199 LPWSTR pszData;
200 pszData = HeapAlloc(GetProcessHeap(),
201 0,
202 dwDataSize + 2 * sizeof(WCHAR));
203 ++pszData;
204
205 /*
206 * This value is the one we are looking for, so get the data.
207 * It is the path to a .cpl file.
208 */
210 szValueName,
211 0,
212 NULL,
213 (LPBYTE)pszData,
214 &dwDataSize) == ERROR_SUCCESS)
215 {
216 INT nReturnValue;
217
218 /* Quote the file name if required */
219 if (*pszData != L'\"')
220 {
221 *(--pszData) = L'\"';
222 pszData[dwDataSize / sizeof(WCHAR)] = L'\"';
223 pszData[(dwDataSize / sizeof(WCHAR)) + 1] = 0;
224 }
225
226 nReturnValue = RunControlPanel(pszData);
227 HeapFree(GetProcessHeap(), 0, pszData);
229
230 return nReturnValue;
231 }
232
233 HeapFree(GetProcessHeap(), 0, pszData);
234 }
235 }
236
238 }
239
240 /*
241 * It's none of the known parameters, so interpret the parameter
242 * as the file name of a control panel applet.
243 */
244 return RunControlPanel(lpCmdLine);
245}
static int argc
Definition: ServiceArgs.c:12
static BOOL IsSwitch(LPCWSTR Switch, LPCWSTR Arg)
Definition: control.c:43
static HRESULT OpenControlPanelItem(LPCWSTR Name, LPCWSTR Page)
Definition: control.c:53
static INT OpenShellFolder(LPWSTR lpFolderCLSID)
Definition: control.c:72
static INT RunControlPanel(LPCWSTR lpCmd)
Definition: control.c:93
#define MAX_VALUE_NAME
Definition: control.c:28
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:79
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185