ReactOS 0.4.15-dev-6068-g8061a6f
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 "resource.h"
Include dependency graph for control.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#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 INT OpenShellFolder (LPWSTR lpFolderCLSID)
 
static INT RunControlPanel (LPCWSTR lpCmd)
 
INT WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
 

Macro Definition Documentation

◆ MAX_VALUE_NAME

#define MAX_VALUE_NAME   16383

Definition at line 23 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 30 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 1035 of file control.c.

1036{
1037 CPanel panel;
1038
1039 TRACE("(%p, %p, %s, 0x%08x)\n",
1040 hWnd, hInst, debugstr_w(cmd), nCmdShow);
1041
1042#ifndef __REACTOS__
1043 memset(&panel, 0, sizeof(panel));
1044 list_init( &panel.applets );
1045#endif
1046
1047 if (!cmd || !*cmd) {
1048 Control_DoWindow(&panel, hWnd, hInst);
1049 } else {
1050 Control_DoLaunch(&panel, hWnd, cmd);
1051 }
1052}
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:701
static void Control_DoLaunch(CPanel *panel, HWND hWnd, LPCWSTR wszCmd)
Definition: control.c:858
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().

◆ OpenShellFolder()

static INT OpenShellFolder ( LPWSTR  lpFolderCLSID)
static

Definition at line 38 of file control.c.

39{
40 WCHAR szParameters[MAX_PATH];
41
42 /*
43 * Open a shell folder using "explorer.exe". The passed CLSIDs
44 * are all subfolders of the "Control Panel" shell folder.
45 */
46 StringCbCopyW(szParameters, sizeof(szParameters), L"/n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}");
47 StringCbCatW(szParameters, sizeof(szParameters), lpFolderCLSID);
48
50 L"open",
51 L"explorer.exe",
52 szParameters,
53 NULL,
54 SW_SHOWDEFAULT) > 32;
55}
#define NULL
Definition: types.h:112
#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:2346
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
#define SW_SHOWDEFAULT
Definition: winuser.h:774
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wWinMain().

◆ RunControlPanel()

static INT RunControlPanel ( LPCWSTR  lpCmd)
static

Definition at line 58 of file control.c.

59{
60 WCHAR szParameters[MAX_PATH];
61 StringCchCopyW(szParameters, ARRAYSIZE(szParameters), L"shell32.dll,Control_RunDLL ");
62 if (FAILED(StringCchCatW(szParameters, ARRAYSIZE(szParameters), lpCmd)))
63 return 0;
64
65 return RUNDLL(szParameters);
66}
#define RUNDLL(param)
Definition: control.c:30
#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 70 of file control.c.

74{
75 HKEY hKey;
76
77 /* Show the control panel window if no argument or "panel" was passed */
78 if (*lpCmdLine == 0 || !_wcsicmp(lpCmdLine, L"panel"))
79 return OpenShellFolder(L"");
80
81 /* Check one of the built-in control panel handlers */
82 if (!_wcsicmp(lpCmdLine, L"admintools")) return OpenShellFolder(L"\\::{D20EA4E1-3957-11d2-A40B-0C5020524153}");
83 else if (!_wcsicmp(lpCmdLine, L"color")) return RunControlPanel(L"desk.cpl,,2");
84 else if (!_wcsicmp(lpCmdLine, L"date/time")) return RunControlPanel(L"timedate.cpl");
85 else if (!_wcsicmp(lpCmdLine, L"desktop")) return RunControlPanel(L"desk.cpl");
86 else if (!_wcsicmp(lpCmdLine, L"folders")) return RUNDLL(L"shell32.dll,Options_RunDLL");
87 else if (!_wcsicmp(lpCmdLine, L"fonts")) return OpenShellFolder(L"\\::{D20EA4E1-3957-11d2-A40B-0C5020524152}");
88 else if (!_wcsicmp(lpCmdLine, L"infrared")) return RunControlPanel(L"irprops.cpl");
89 else if (!_wcsicmp(lpCmdLine, L"international")) return RunControlPanel(L"intl.cpl");
90 else if (!_wcsicmp(lpCmdLine, L"keyboard")) return RunControlPanel(L"main.cpl @1");
91 else if (!_wcsicmp(lpCmdLine, L"mouse")) return RunControlPanel(L"main.cpl @0");
92 else if (!_wcsicmp(lpCmdLine, L"netconnections")) return OpenShellFolder(L"\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}");
93 else if (!_wcsicmp(lpCmdLine, L"netware")) return RunControlPanel(L"nwc.cpl");
94 else if (!_wcsicmp(lpCmdLine, L"ports")) return RunControlPanel(L"sysdm.cpl,,1");
95 else if (!_wcsicmp(lpCmdLine, L"printers")) return OpenShellFolder(L"\\::{2227A280-3AEA-1069-A2DE-08002B30309D}");
96 else if (!_wcsicmp(lpCmdLine, L"scannercamera")) return OpenShellFolder(L"\\::{E211B736-43FD-11D1-9EFB-0000F8757FCD}");
97 else if (!_wcsicmp(lpCmdLine, L"schedtasks")) return OpenShellFolder(L"\\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}");
98 else if (!_wcsicmp(lpCmdLine, L"telephony")) return RunControlPanel(L"telephon.cpl");
99 else if (!_wcsicmp(lpCmdLine, L"userpasswords")) return RunControlPanel(L"nusrmgr.cpl"); /* Graphical User Account Manager */
100 else if (!_wcsicmp(lpCmdLine, L"userpasswords2")) return RUNDLL(L"netplwiz.dll,UsersRunDll"); /* Dialog based advanced User Account Manager */
101
102 /* It is none of them, so look for a handler in the registry */
104 L"Software\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls",
105 0,
107 &hKey) == ERROR_SUCCESS)
108 {
109 DWORD dwIndex;
110
111 for (dwIndex = 0; ; ++dwIndex)
112 {
113 DWORD dwDataSize;
114 DWORD dwValueSize = MAX_VALUE_NAME;
115 WCHAR szValueName[MAX_VALUE_NAME];
116
117 /* Get the value name and data size */
119 dwIndex,
120 szValueName,
121 &dwValueSize,
122 0,
123 NULL,
124 NULL,
125 &dwDataSize) != ERROR_SUCCESS)
126 {
127 break;
128 }
129
130 /* Check if the parameter is the value name */
131 if (!_wcsicmp(lpCmdLine, szValueName))
132 {
133 /*
134 * Allocate memory for the data plus two more characters,
135 * so we can quote the file name if required.
136 */
137 LPWSTR pszData;
138 pszData = HeapAlloc(GetProcessHeap(),
139 0,
140 dwDataSize + 2 * sizeof(WCHAR));
141 ++pszData;
142
143 /*
144 * This value is the one we are looking for, so get the data.
145 * It is the path to a .cpl file.
146 */
148 szValueName,
149 0,
150 NULL,
151 (LPBYTE)pszData,
152 &dwDataSize) == ERROR_SUCCESS)
153 {
154 INT nReturnValue;
155
156 /* Quote the file name if required */
157 if (*pszData != L'\"')
158 {
159 *(--pszData) = L'\"';
160 pszData[dwDataSize / sizeof(WCHAR)] = L'\"';
161 pszData[(dwDataSize / sizeof(WCHAR)) + 1] = 0;
162 }
163
164 nReturnValue = RunControlPanel(pszData);
165 HeapFree(GetProcessHeap(), 0, pszData);
167
168 return nReturnValue;
169 }
170
171 HeapFree(GetProcessHeap(), 0, pszData);
172 }
173 }
174
176 }
177
178 /*
179 * It's none of the known parameters, so interpret the parameter
180 * as the file name of a control panel applet.
181 */
182 return RunControlPanel(lpCmdLine);
183}
static INT OpenShellFolder(LPWSTR lpFolderCLSID)
Definition: control.c:38
static INT RunControlPanel(LPCWSTR lpCmd)
Definition: control.c:58
#define MAX_VALUE_NAME
Definition: control.c:23
#define RegCloseKey(hKey)
Definition: registry.h:47
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3353
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:2850
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4118
#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
#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)
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