ReactOS 0.4.15-dev-7085-g12a5971
cpanel.h File Reference
#include <cpl.h>
Include dependency graph for cpanel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  applet_info
 
struct  CPlApplet
 
struct  CPanel
 
struct  CPlItem
 

Typedefs

typedef struct CPlApplet CPlApplet
 
typedef struct CPanel CPanel
 
typedef struct CPlItem CPlItem
 

Functions

CPlAppletControl_LoadApplet (HWND hWnd, LPCWSTR cmd, CPanel *panel) DECLSPEC_HIDDEN
 
void Control_UnloadApplet (CPlApplet *applet) DECLSPEC_HIDDEN
 

Typedef Documentation

◆ CPanel

typedef struct CPanel CPanel

◆ CPlApplet

◆ CPlItem

Function Documentation

◆ Control_LoadApplet()

CPlApplet * Control_LoadApplet ( HWND  hWnd,
LPCWSTR  cmd,
CPanel panel 
)

Definition at line 59 of file control.c.

60{
61#ifdef __REACTOS__
62 ACTCTXW ActCtx = {sizeof(ACTCTX), ACTCTX_FLAG_RESOURCE_NAME_VALID};
64 BOOL bActivated;
65 WCHAR fileBuffer[MAX_PATH];
66#endif
67 CPlApplet* applet;
68 DWORD len;
69 unsigned i;
71 NEWCPLINFOW newinfo;
72
73 if (!(applet = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*applet))))
74 return applet;
75
77 if (len > 0)
78 {
79 if (!(applet->cmd = HeapAlloc(GetProcessHeap(), 0, (len+1) * sizeof(WCHAR))))
80 {
81 WARN("Cannot allocate memory for applet path\n");
82 goto theError;
83 }
85 }
86 else
87 {
88 WARN("Cannot expand applet path\n");
89 goto theError;
90 }
91
92 applet->hWnd = hWnd;
93
94#ifdef __REACTOS__
95 StringCchCopy(fileBuffer, MAX_PATH, applet->cmd);
96 if (PathIsFileSpecW(fileBuffer))
97 SearchPath(NULL, fileBuffer, NULL, MAX_PATH, fileBuffer, NULL);
98 ActCtx.lpSource = fileBuffer;
99 ActCtx.lpResourceName = (LPCWSTR)123;
100 applet->hActCtx = CreateActCtx(&ActCtx);
101 bActivated = (applet->hActCtx != INVALID_HANDLE_VALUE ? ActivateActCtx(applet->hActCtx, &cookie) : FALSE);
102#endif
103
104 if (!(applet->hModule = LoadLibraryW(applet->cmd))) {
105 WARN("Cannot load control panel applet %s\n", debugstr_w(applet->cmd));
106 goto theError;
107 }
108 if (!(applet->proc = (APPLET_PROC)GetProcAddress(applet->hModule, "CPlApplet"))) {
109 WARN("Not a valid control panel applet %s\n", debugstr_w(applet->cmd));
110 goto theError;
111 }
112 if (!applet->proc(hWnd, CPL_INIT, 0L, 0L)) {
113 WARN("Init of applet has failed\n");
114 goto theError;
115 }
116 if ((applet->count = applet->proc(hWnd, CPL_GETCOUNT, 0L, 0L)) == 0) {
117 WARN("No subprogram in applet\n");
118 applet->proc(applet->hWnd, CPL_EXIT, 0, 0);
119 goto theError;
120 }
121
122 applet = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, applet,
123 FIELD_OFFSET( CPlApplet, info[applet->count] ));
124
125 for (i = 0; i < applet->count; i++) {
126 ZeroMemory(&newinfo, sizeof(newinfo));
127 newinfo.dwSize = sizeof(NEWCPLINFOA);
128 applet->info[i].helpfile[0] = 0;
129 /* proc is supposed to return a null value upon success for
130 * CPL_INQUIRE and CPL_NEWINQUIRE
131 * However, real drivers don't seem to behave like this
132 * So, use introspection rather than return value
133 */
134 applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
135 applet->info[i].data = info.lData;
136#ifdef __REACTOS__
137 applet->info[i].idIcon = info.idIcon;
138#endif
139
140 if (info.idIcon != CPL_DYNAMIC_RES)
141 applet->info[i].icon = LoadIconW(applet->hModule, MAKEINTRESOURCEW(info.idIcon));
142 if (info.idName != CPL_DYNAMIC_RES)
143 LoadStringW(applet->hModule, info.idName,
144 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
145 if (info.idInfo != CPL_DYNAMIC_RES)
146 LoadStringW(applet->hModule, info.idInfo,
147 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
148
149 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
150 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
151 icon, see what we can get from CPL_NEWINQUIRE */
152
153 if (!applet->info[i].name[0]) info.idName = CPL_DYNAMIC_RES;
154
155 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
156 to check anyway */
157
158 if (!applet->info[i].info[0]) info.idInfo = CPL_DYNAMIC_RES;
159
160 if (applet->info[i].icon == NULL)
161 info.idIcon = CPL_DYNAMIC_RES;
162
163 if ((info.idIcon == CPL_DYNAMIC_RES) || (info.idName == CPL_DYNAMIC_RES) ||
164 (info.idInfo == CPL_DYNAMIC_RES)) {
165 applet->proc(hWnd, CPL_NEWINQUIRE, i, (LPARAM)&newinfo);
166
167 applet->info[i].data = newinfo.lData;
168 if (info.idIcon == CPL_DYNAMIC_RES) {
169 if (!newinfo.hIcon) WARN("couldn't get icon for applet %u\n", i);
170 applet->info[i].icon = newinfo.hIcon;
171 }
172 if (newinfo.dwSize == sizeof(NEWCPLINFOW)) {
173 if (info.idName == CPL_DYNAMIC_RES)
174 memcpy(applet->info[i].name, newinfo.szName, sizeof(newinfo.szName));
175 if (info.idInfo == CPL_DYNAMIC_RES)
176 memcpy(applet->info[i].info, newinfo.szInfo, sizeof(newinfo.szInfo));
177 memcpy(applet->info[i].helpfile, newinfo.szHelpFile, sizeof(newinfo.szHelpFile));
178 } else {
179 if (info.idName == CPL_DYNAMIC_RES)
181 sizeof(((LPNEWCPLINFOA)&newinfo)->szName) / sizeof(CHAR),
182 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
183 if (info.idInfo == CPL_DYNAMIC_RES)
184 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szInfo,
185 sizeof(((LPNEWCPLINFOA)&newinfo)->szInfo) / sizeof(CHAR),
186 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
188 sizeof(((LPNEWCPLINFOA)&newinfo)->szHelpFile) / sizeof(CHAR),
189 applet->info[i].helpfile,
190 sizeof(applet->info[i].helpfile) / sizeof(WCHAR));
191 }
192 }
193 }
194
195#ifdef __REACTOS__
196 if (bActivated)
198#endif
199
200#ifndef __REACTOS__
201 list_add_head( &panel->applets, &applet->entry );
202#endif
203
204 return applet;
205
206 theError:
207 FreeLibrary(applet->hModule);
208 HeapFree(GetProcessHeap(), 0, applet->cmd);
209 HeapFree(GetProcessHeap(), 0, applet);
210 return NULL;
211}
HWND hWnd
Definition: settings.c:17
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
#define WARN(fmt,...)
Definition: debug.h:112
#define CPL_INQUIRE
Definition: cpl.h:14
#define CPL_DYNAMIC_RES
Definition: cpl.h:11
LONG(APIENTRY * APPLET_PROC)(HWND, UINT, LPARAM, LPARAM)
Definition: cpl.h:23
struct tagNEWCPLINFOA NEWCPLINFOA
#define CPL_INIT
Definition: cpl.h:12
#define CPL_EXIT
Definition: cpl.h:18
#define CPL_GETCOUNT
Definition: cpl.h:13
#define CPL_NEWINQUIRE
Definition: cpl.h:19
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
#define LoadLibraryW(x)
Definition: compat.h:747
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
Definition: path.c:2133
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define debugstr_w
Definition: kernel32.h:32
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:247
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define L(x)
Definition: ntvdm.h:50
static const WCHAR szName[]
Definition: powrprof.c:45
TCHAR szHelpFile[]
Definition: scrnsave.c:31
#define StringCchCopy
Definition: strsafe.h:139
struct list applets
Definition: cpanel.h:57
HMODULE hModule
Definition: cpanel.h:50
struct applet_info info[1]
Definition: cpanel.h:52
LPWSTR cmd
Definition: cpanel.h:48
APPLET_PROC proc
Definition: cpanel.h:51
HWND hWnd
Definition: cpanel.h:47
struct list entry
Definition: cpanel.h:43
unsigned count
Definition: cpanel.h:49
Definition: ftp_var.h:139
Definition: cookie.c:34
Definition: cpl.h:24
DWORD dwSize
Definition: cpl.h:41
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ZeroMemory
Definition: winbase.h:1712
#define SearchPath
Definition: winbase.h:3835
LONG_PTR LPARAM
Definition: windef.h:208
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2044
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175

Referenced by Control_DoLaunch(), Control_DoWindow(), Control_RegisterRegistryApplets(), and CControlPanelEnum::RegisterCPanelApp().

◆ Control_UnloadApplet()

void Control_UnloadApplet ( CPlApplet applet)

Definition at line 43 of file control.c.

44{
45 unsigned i;
46
47 for (i = 0; i < applet->count; i++)
48 applet->proc(applet->hWnd, CPL_STOP, i, applet->info[i].data);
49
50 if (applet->proc) applet->proc(applet->hWnd, CPL_EXIT, 0L, 0L);
51 FreeLibrary(applet->hModule);
52#ifndef __REACTOS__
53 list_remove( &applet->entry );
54#endif
55 HeapFree(GetProcessHeap(), 0, applet->cmd);
56 HeapFree(GetProcessHeap(), 0, applet);
57}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
#define CPL_STOP
Definition: cpl.h:17

Referenced by Control_DoLaunch(), Control_WndProc(), and CControlPanelEnum::RegisterCPanelApp().