ReactOS 0.4.15-dev-7788-g1ad9096
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 61 of file control.c.

62{
63#ifdef __REACTOS__
64 ACTCTXW ActCtx = {sizeof(ACTCTX), ACTCTX_FLAG_RESOURCE_NAME_VALID};
66 BOOL bActivated;
67 WCHAR fileBuffer[MAX_PATH];
68#endif
69 CPlApplet* applet;
70 DWORD len;
71 unsigned i;
73 NEWCPLINFOW newinfo;
74
75 if (!(applet = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*applet))))
76 return applet;
77
79 if (len > 0)
80 {
81 if (!(applet->cmd = HeapAlloc(GetProcessHeap(), 0, (len+1) * sizeof(WCHAR))))
82 {
83 WARN("Cannot allocate memory for applet path\n");
84 goto theError;
85 }
87 }
88 else
89 {
90 WARN("Cannot expand applet path\n");
91 goto theError;
92 }
93
94 applet->hWnd = hWnd;
95
96#ifdef __REACTOS__
97 StringCchCopy(fileBuffer, MAX_PATH, applet->cmd);
98 if (PathIsFileSpecW(fileBuffer))
99 SearchPath(NULL, fileBuffer, NULL, MAX_PATH, fileBuffer, NULL);
100 ActCtx.lpSource = fileBuffer;
101 ActCtx.lpResourceName = (LPCWSTR)123;
102 applet->hActCtx = CreateActCtx(&ActCtx);
103 bActivated = (applet->hActCtx != INVALID_HANDLE_VALUE ? ActivateActCtx(applet->hActCtx, &cookie) : FALSE);
104#endif
105
106 if (!(applet->hModule = LoadLibraryW(applet->cmd))) {
107 WARN("Cannot load control panel applet %s\n", debugstr_w(applet->cmd));
108 goto theError;
109 }
110 if (!(applet->proc = (APPLET_PROC)GetProcAddress(applet->hModule, "CPlApplet"))) {
111 WARN("Not a valid control panel applet %s\n", debugstr_w(applet->cmd));
112 goto theError;
113 }
114 if (!applet->proc(hWnd, CPL_INIT, 0L, 0L)) {
115 WARN("Init of applet has failed\n");
116 goto theError;
117 }
118 if ((applet->count = applet->proc(hWnd, CPL_GETCOUNT, 0L, 0L)) == 0) {
119 WARN("No subprogram in applet\n");
120 applet->proc(applet->hWnd, CPL_EXIT, 0, 0);
121 goto theError;
122 }
123
124 applet = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, applet,
125 FIELD_OFFSET( CPlApplet, info[applet->count] ));
126
127 for (i = 0; i < applet->count; i++) {
128 ZeroMemory(&newinfo, sizeof(newinfo));
129 newinfo.dwSize = sizeof(NEWCPLINFOA);
130 applet->info[i].helpfile[0] = 0;
131 /* proc is supposed to return a null value upon success for
132 * CPL_INQUIRE and CPL_NEWINQUIRE
133 * However, real drivers don't seem to behave like this
134 * So, use introspection rather than return value
135 */
136 applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
137 applet->info[i].data = info.lData;
138#ifdef __REACTOS__
139 applet->info[i].idIcon = info.idIcon;
140#endif
141
142 if (info.idIcon != CPL_DYNAMIC_RES)
143 applet->info[i].icon = LoadIconW(applet->hModule, MAKEINTRESOURCEW(info.idIcon));
144 if (info.idName != CPL_DYNAMIC_RES)
145 LoadStringW(applet->hModule, info.idName,
146 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
147 if (info.idInfo != CPL_DYNAMIC_RES)
148 LoadStringW(applet->hModule, info.idInfo,
149 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
150
151 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
152 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
153 icon, see what we can get from CPL_NEWINQUIRE */
154
155 if (!applet->info[i].name[0]) info.idName = CPL_DYNAMIC_RES;
156
157 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
158 to check anyway */
159
160 if (!applet->info[i].info[0]) info.idInfo = CPL_DYNAMIC_RES;
161
162 if (applet->info[i].icon == NULL)
163 info.idIcon = CPL_DYNAMIC_RES;
164
165 if ((info.idIcon == CPL_DYNAMIC_RES) || (info.idName == CPL_DYNAMIC_RES) ||
166 (info.idInfo == CPL_DYNAMIC_RES)) {
167 applet->proc(hWnd, CPL_NEWINQUIRE, i, (LPARAM)&newinfo);
168
169 applet->info[i].data = newinfo.lData;
170 if (info.idIcon == CPL_DYNAMIC_RES) {
171 if (!newinfo.hIcon) WARN("couldn't get icon for applet %u\n", i);
172 applet->info[i].icon = newinfo.hIcon;
173 }
174 if (newinfo.dwSize == sizeof(NEWCPLINFOW)) {
175 if (info.idName == CPL_DYNAMIC_RES)
176 memcpy(applet->info[i].name, newinfo.szName, sizeof(newinfo.szName));
177 if (info.idInfo == CPL_DYNAMIC_RES)
178 memcpy(applet->info[i].info, newinfo.szInfo, sizeof(newinfo.szInfo));
179 memcpy(applet->info[i].helpfile, newinfo.szHelpFile, sizeof(newinfo.szHelpFile));
180 } else {
181 if (info.idName == CPL_DYNAMIC_RES)
183 sizeof(((LPNEWCPLINFOA)&newinfo)->szName) / sizeof(CHAR),
184 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
185 if (info.idInfo == CPL_DYNAMIC_RES)
186 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szInfo,
187 sizeof(((LPNEWCPLINFOA)&newinfo)->szInfo) / sizeof(CHAR),
188 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
190 sizeof(((LPNEWCPLINFOA)&newinfo)->szHelpFile) / sizeof(CHAR),
191 applet->info[i].helpfile,
192 sizeof(applet->info[i].helpfile) / sizeof(WCHAR));
193 }
194 }
195 }
196
197#ifdef __REACTOS__
198 if (bActivated)
200#endif
201
202#ifndef __REACTOS__
203 list_add_head( &panel->applets, &applet->entry );
204#endif
205
206 return applet;
207
208 theError:
209 FreeLibrary(applet->hModule);
210 HeapFree(GetProcessHeap(), 0, applet->cmd);
211 HeapFree(GetProcessHeap(), 0, applet);
212 return NULL;
213}
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:2075
__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 45 of file control.c.

46{
47 unsigned i;
48
49 for (i = 0; i < applet->count; i++)
50 applet->proc(applet->hWnd, CPL_STOP, i, applet->info[i].data);
51
52 if (applet->proc) applet->proc(applet->hWnd, CPL_EXIT, 0L, 0L);
53 FreeLibrary(applet->hModule);
54#ifndef __REACTOS__
55 list_remove( &applet->entry );
56#endif
57 HeapFree(GetProcessHeap(), 0, applet->cmd);
58 HeapFree(GetProcessHeap(), 0, applet);
59}
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().