winecfg: Use the available ARRAY_SIZE() macro.
[wine.git] / programs / winecfg / winecfg.c
blobbe04ba2a77ac8e32599f45dc63bbef4d714e8732
1 /*
2 * WineCfg configuration management
4 * Copyright 2002 Jaco Greeff
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003-2004 Mike Hearn
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * TODO:
23 * - Use unicode
24 * - Icons in listviews/icons
25 * - Better add app dialog, scan c: for EXE files and add to list in background
26 * - Use [GNOME] HIG style groupboxes rather than win32 style (looks nicer, imho)
30 #define WIN32_LEAN_AND_MEAN
32 #include <assert.h>
33 #include <stdio.h>
34 #include <limits.h>
35 #include <windows.h>
36 #include <winreg.h>
37 #include <wine/unicode.h>
38 #include <wine/debug.h>
39 #include <wine/list.h>
41 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
43 #include "winecfg.h"
44 #include "resource.h"
46 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
48 HKEY config_key = NULL;
49 HMENU hPopupMenus = 0;
52 /* this is called from the WM_SHOWWINDOW handlers of each tab page.
54 * it's a nasty hack, necessary because the property sheet insists on resetting the window title
55 * to the title of the tab, which is utterly useless. dropping the property sheet is on the todo list.
57 void set_window_title(HWND dialog)
59 WCHAR newtitle[256];
61 /* update the window title */
62 if (current_app)
64 WCHAR apptitle[256];
65 LoadStringW(GetModuleHandleW(NULL), IDS_WINECFG_TITLE_APP, apptitle, ARRAY_SIZE(apptitle));
66 wsprintfW (newtitle, apptitle, current_app);
68 else
70 LoadStringW(GetModuleHandleW(NULL), IDS_WINECFG_TITLE, newtitle, ARRAY_SIZE(newtitle));
73 WINE_TRACE("setting title to %s\n", wine_dbgstr_w (newtitle));
74 SendMessageW (GetParent(dialog), PSM_SETTITLEW, 0, (LPARAM) newtitle);
78 WCHAR* load_string (UINT id)
80 WCHAR buf[1024];
81 int len;
82 WCHAR* newStr;
84 LoadStringW(GetModuleHandleW(NULL), id, buf, ARRAY_SIZE(buf));
86 len = lstrlenW (buf);
87 newStr = HeapAlloc (GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR));
88 memcpy (newStr, buf, len * sizeof (WCHAR));
89 newStr[len] = 0;
90 return newStr;
93 /**
94 * get_config_key: Retrieves a configuration value from the registry
96 * char *subkey : the name of the config section
97 * char *name : the name of the config value
98 * char *default : if the key isn't found, return this value instead
100 * Returns a buffer holding the value if successful, NULL if
101 * not. Caller is responsible for releasing the result.
104 static WCHAR *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *def)
106 LPWSTR buffer = NULL;
107 DWORD len;
108 HKEY hSubKey = NULL;
109 DWORD res;
111 WINE_TRACE("subkey=%s, name=%s, def=%s\n", wine_dbgstr_w(subkey),
112 wine_dbgstr_w(name), wine_dbgstr_w(def));
114 res = RegOpenKeyExW(root, subkey, 0, MAXIMUM_ALLOWED, &hSubKey);
115 if (res != ERROR_SUCCESS)
117 if (res == ERROR_FILE_NOT_FOUND)
119 WINE_TRACE("Section key not present - using default\n");
120 return def ? strdupW(def) : NULL;
122 else
124 WINE_ERR("RegOpenKey failed on wine config key (res=%d)\n", res);
126 goto end;
129 res = RegQueryValueExW(hSubKey, name, NULL, NULL, NULL, &len);
130 if (res == ERROR_FILE_NOT_FOUND)
132 WINE_TRACE("Value not present - using default\n");
133 buffer = def ? strdupW(def) : NULL;
134 goto end;
135 } else if (res != ERROR_SUCCESS)
137 WINE_ERR("Couldn't query value's length (res=%d)\n", res);
138 goto end;
141 buffer = HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR));
143 RegQueryValueExW(hSubKey, name, NULL, NULL, (LPBYTE) buffer, &len);
145 WINE_TRACE("buffer=%s\n", wine_dbgstr_w(buffer));
146 end:
147 RegCloseKey(hSubKey);
149 return buffer;
153 * set_config_key: convenience wrapper to set a key/value pair
155 * const char *subKey : the name of the config section
156 * const char *valueName : the name of the config value
157 * const char *value : the value to set the configuration key to
159 * Returns 0 on success, non-zero otherwise
161 * If valueName or value is NULL, an empty section will be created
163 static int set_config_key(HKEY root, const WCHAR *subkey, REGSAM access, const WCHAR *name, const void *value, DWORD type)
165 DWORD res = 1;
166 HKEY key = NULL;
168 WINE_TRACE("subkey=%s: name=%s, value=%p, type=%d\n", wine_dbgstr_w(subkey),
169 wine_dbgstr_w(name), value, type);
171 assert( subkey != NULL );
173 if (subkey[0])
175 res = RegCreateKeyExW( root, subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
176 access, NULL, &key, NULL );
177 if (res != ERROR_SUCCESS) goto end;
179 else key = root;
180 if (name == NULL || value == NULL) goto end;
182 switch (type)
184 case REG_SZ: res = RegSetValueExW(key, name, 0, REG_SZ, value, (lstrlenW(value)+1)*sizeof(WCHAR)); break;
185 case REG_DWORD: res = RegSetValueExW(key, name, 0, REG_DWORD, value, sizeof(DWORD)); break;
187 if (res != ERROR_SUCCESS) goto end;
189 res = 0;
190 end:
191 if (key && key != root) RegCloseKey(key);
192 if (res != 0)
193 WINE_ERR("Unable to set configuration key %s in section %s, res=%d\n",
194 wine_dbgstr_w(name), wine_dbgstr_w(subkey), res);
195 return res;
198 /* ========================================================================= */
200 /* This code exists for the following reasons:
202 * - It makes working with the registry easier
203 * - By storing a mini cache of the registry, we can more easily implement
204 * cancel/revert and apply. The 'settings list' is an overlay on top of
205 * the actual registry data that we can write out at will.
207 * Rather than model a tree in memory, we simply store each absolute (rooted
208 * at the config key) path.
212 struct setting
214 struct list entry;
215 HKEY root; /* the key on which path is rooted */
216 WCHAR *path; /* path in the registry rooted at root */
217 WCHAR *name; /* name of the registry value. if null, this means delete the key */
218 WCHAR *value; /* contents of the registry value. if null, this means delete the value */
219 DWORD type; /* type of registry value. REG_SZ or REG_DWORD for now */
222 static struct list settings = LIST_INIT(settings);
224 static void free_setting(struct setting *setting)
226 assert( setting != NULL );
227 assert( setting->path );
229 WINE_TRACE("destroying %p: %s\n", setting,
230 wine_dbgstr_w(setting->path));
232 HeapFree(GetProcessHeap(), 0, setting->path);
233 HeapFree(GetProcessHeap(), 0, setting->name);
234 HeapFree(GetProcessHeap(), 0, setting->value);
236 list_remove(&setting->entry);
238 HeapFree(GetProcessHeap(), 0, setting);
242 * Returns the contents of the value at path. If not in the settings
243 * list, it will be fetched from the registry - failing that, the
244 * default will be used.
246 * If already in the list, the contents as given there will be
247 * returned. You are expected to HeapFree the result.
249 WCHAR *get_reg_keyW(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *def)
251 struct list *cursor;
252 struct setting *s;
253 WCHAR *val;
255 WINE_TRACE("path=%s, name=%s, def=%s\n", wine_dbgstr_w(path),
256 wine_dbgstr_w(name), wine_dbgstr_w(def));
258 /* check if it's in the list */
259 LIST_FOR_EACH( cursor, &settings )
261 s = LIST_ENTRY(cursor, struct setting, entry);
263 if (root != s->root) continue;
264 if (lstrcmpiW(path, s->path) != 0) continue;
265 if (!s->name) continue;
266 if (lstrcmpiW(name, s->name) != 0) continue;
268 WINE_TRACE("found %s:%s in settings list, returning %s\n",
269 wine_dbgstr_w(path), wine_dbgstr_w(name),
270 wine_dbgstr_w(s->value));
271 return s->value ? strdupW(s->value) : NULL;
274 /* no, so get from the registry */
275 val = get_config_key(root, path, name, def);
277 WINE_TRACE("returning %s\n", wine_dbgstr_w(val));
279 return val;
282 char *get_reg_key(HKEY root, const char *path, const char *name, const char *def)
284 WCHAR *wpath, *wname, *wdef = NULL, *wRet = NULL;
285 char *szRet = NULL;
286 int len;
288 WINE_TRACE("path=%s, name=%s, def=%s\n", path, name, def);
290 wpath = HeapAlloc(GetProcessHeap(), 0, (strlen(path)+1)*sizeof(WCHAR));
291 wname = HeapAlloc(GetProcessHeap(), 0, (strlen(name)+1)*sizeof(WCHAR));
293 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, strlen(path)+1);
294 MultiByteToWideChar(CP_ACP, 0, name, -1, wname, strlen(name)+1);
296 if (def)
298 wdef = HeapAlloc(GetProcessHeap(), 0, (strlen(def)+1)*sizeof(WCHAR));
299 MultiByteToWideChar(CP_ACP, 0, def, -1, wdef, strlen(def)+1);
302 wRet = get_reg_keyW(root, wpath, wname, wdef);
304 len = WideCharToMultiByte(CP_ACP, 0, wRet, -1, NULL, 0, NULL, NULL);
305 if (len)
307 szRet = HeapAlloc(GetProcessHeap(), 0, len);
308 WideCharToMultiByte(CP_ACP, 0, wRet, -1, szRet, len, NULL, NULL);
311 HeapFree(GetProcessHeap(), 0, wpath);
312 HeapFree(GetProcessHeap(), 0, wname);
313 HeapFree(GetProcessHeap(), 0, wdef);
314 HeapFree(GetProcessHeap(), 0, wRet);
316 return szRet;
320 * Used to set a registry key.
322 * path is rooted at the config key, ie use "Version" or
323 * "AppDefaults\\fooapp.exe\\Version". You can use keypath()
324 * to get such a string.
326 * name is the value name, or NULL to delete the path.
328 * value is what to set the value to, or NULL to delete it.
330 * type is REG_SZ or REG_DWORD.
332 * These values will be copied when necessary.
334 static void set_reg_key_ex(HKEY root, const WCHAR *path, const WCHAR *name, const void *value, DWORD type)
336 struct list *cursor;
337 struct setting *s;
339 assert( path != NULL );
341 WINE_TRACE("path=%s, name=%s, value=%s\n", wine_dbgstr_w(path),
342 wine_dbgstr_w(name), wine_dbgstr_w(value));
344 /* firstly, see if we already set this setting */
345 LIST_FOR_EACH( cursor, &settings )
347 struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
349 if (root != s->root) continue;
350 if (lstrcmpiW(s->path, path) != 0) continue;
351 if ((s->name && name) && lstrcmpiW(s->name, name) != 0) continue;
353 /* are we attempting a double delete? */
354 if (!s->name && !name) return;
356 /* do we want to undelete this key? */
357 if (!s->name && name) s->name = strdupW(name);
359 /* yes, we have already set it, so just replace the content and return */
360 HeapFree(GetProcessHeap(), 0, s->value);
361 s->type = type;
362 switch (type)
364 case REG_SZ:
365 s->value = value ? strdupW(value) : NULL;
366 break;
367 case REG_DWORD:
368 s->value = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
369 memcpy( s->value, value, sizeof(DWORD) );
370 break;
373 /* are we deleting this key? this won't remove any of the
374 * children from the overlay so if the user adds it again in
375 * that session it will appear to undelete the settings, but
376 * in reality only the settings actually modified by the user
377 * in that session will be restored. we might want to fix this
378 * corner case in future by actually deleting all the children
379 * here so that once it's gone, it's gone.
381 if (!name) s->name = NULL;
383 return;
386 /* otherwise add a new setting for it */
387 s = HeapAlloc(GetProcessHeap(), 0, sizeof(struct setting));
388 s->root = root;
389 s->path = strdupW(path);
390 s->name = name ? strdupW(name) : NULL;
391 s->type = type;
392 switch (type)
394 case REG_SZ:
395 s->value = value ? strdupW(value) : NULL;
396 break;
397 case REG_DWORD:
398 s->value = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
399 memcpy( s->value, value, sizeof(DWORD) );
400 break;
403 list_add_tail(&settings, &s->entry);
406 void set_reg_key(HKEY root, const char *path, const char *name, const char *value)
408 WCHAR *wpath, *wname = NULL, *wvalue = NULL;
410 wpath = HeapAlloc(GetProcessHeap(), 0, (strlen(path)+1)*sizeof(WCHAR));
411 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, strlen(path)+1);
413 if (name)
415 wname = HeapAlloc(GetProcessHeap(), 0, (strlen(name)+1)*sizeof(WCHAR));
416 MultiByteToWideChar(CP_ACP, 0, name, -1, wname, strlen(name)+1);
419 if (value)
421 wvalue = HeapAlloc(GetProcessHeap(), 0, (strlen(value)+1)*sizeof(WCHAR));
422 MultiByteToWideChar(CP_ACP, 0, value, -1, wvalue, strlen(value)+1);
425 set_reg_key_ex(root, wpath, wname, wvalue, REG_SZ);
427 HeapFree(GetProcessHeap(), 0, wpath);
428 HeapFree(GetProcessHeap(), 0, wname);
429 HeapFree(GetProcessHeap(), 0, wvalue);
432 void set_reg_key_dword(HKEY root, const char *path, const char *name, DWORD value)
434 WCHAR *wpath, *wname;
436 wpath = HeapAlloc(GetProcessHeap(), 0, (strlen(path)+1)*sizeof(WCHAR));
437 wname = HeapAlloc(GetProcessHeap(), 0, (strlen(name)+1)*sizeof(WCHAR));
439 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, strlen(path)+1);
440 MultiByteToWideChar(CP_ACP, 0, name, -1, wname, strlen(name)+1);
442 set_reg_key_ex(root, wpath, wname, &value, REG_DWORD);
444 HeapFree(GetProcessHeap(), 0, wpath);
445 HeapFree(GetProcessHeap(), 0, wname);
448 void set_reg_keyW(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *value)
450 set_reg_key_ex(root, path, name, value, REG_SZ);
453 void set_reg_key_dwordW(HKEY root, const WCHAR *path, const WCHAR *name, DWORD value)
455 set_reg_key_ex(root, path, name, &value, REG_DWORD);
459 * enumerates the value names at the given path, taking into account
460 * the changes in the settings list.
462 * you are expected to HeapFree each element of the array, which is null
463 * terminated, as well as the array itself.
465 static WCHAR **enumerate_valuesW(HKEY root, WCHAR *path)
467 HKEY key;
468 DWORD res, i = 0, valueslen = 0;
469 WCHAR **values = NULL;
470 struct list *cursor;
472 res = RegOpenKeyExW(root, path, 0, MAXIMUM_ALLOWED, &key);
473 if (res == ERROR_SUCCESS)
475 while (TRUE)
477 WCHAR name[1024];
478 DWORD namesize = ARRAY_SIZE(name);
479 BOOL removed = FALSE;
481 /* find out the needed size, allocate a buffer, read the value */
482 if ((res = RegEnumValueW(key, i, name, &namesize, NULL, NULL, NULL, NULL)) != ERROR_SUCCESS)
483 break;
485 WINE_TRACE("name=%s\n", wine_dbgstr_w(name));
487 /* check if this value name has been removed in the settings list */
488 LIST_FOR_EACH( cursor, &settings )
490 struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
491 if (lstrcmpiW(s->path, path) != 0) continue;
492 if (lstrcmpiW(s->name, name) != 0) continue;
494 if (!s->value)
496 WINE_TRACE("this key has been removed, so skipping\n");
497 removed = TRUE;
498 break;
502 if (removed) /* this value was deleted by the user, so don't include it */
504 i++;
505 continue;
508 /* grow the array if necessary, add buffer to it, iterate */
509 if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(WCHAR*) * (valueslen + 1));
510 else values = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR*));
512 values[valueslen++] = strdupW(name);
513 WINE_TRACE("valueslen is now %d\n", valueslen);
514 i++;
517 else
519 WINE_WARN("failed opening registry key %s, res=0x%x\n",
520 wine_dbgstr_w(path), res);
523 WINE_TRACE("adding settings in list but not registry\n");
525 /* now we have to add the values that aren't in the registry but are in the settings list */
526 LIST_FOR_EACH( cursor, &settings )
528 struct setting *setting = LIST_ENTRY(cursor, struct setting, entry);
529 BOOL found = FALSE;
531 if (lstrcmpiW(setting->path, path) != 0) continue;
533 if (!setting->value) continue;
535 for (i = 0; i < valueslen; i++)
537 if (lstrcmpiW(setting->name, values[i]) == 0)
539 found = TRUE;
540 break;
544 if (found) continue;
546 WINE_TRACE("%s in list but not registry\n", wine_dbgstr_w(setting->name));
548 /* otherwise it's been set by the user but isn't in the registry */
549 if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(WCHAR*) * (valueslen + 1));
550 else values = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR*));
552 values[valueslen++] = strdupW(setting->name);
555 WINE_TRACE("adding null terminator\n");
556 if (values)
558 values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(WCHAR*) * (valueslen + 1));
559 values[valueslen] = NULL;
562 RegCloseKey(key);
564 return values;
567 char **enumerate_values(HKEY root, char *path)
569 WCHAR *wpath;
570 WCHAR **wret;
571 char **ret=NULL;
572 int i=0, len=0, size;
574 wpath = HeapAlloc(GetProcessHeap(), 0, (strlen(path)+1)*sizeof(WCHAR));
575 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, strlen(path)+1);
577 wret = enumerate_valuesW(root, wpath);
579 if (wret)
581 for(len=0; wret[len]; len++);
582 ret = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(char*));
584 /* convert WCHAR ** to char ** and HeapFree each WCHAR * element on our way */
585 for (i=0; i<len; i++)
587 size = WideCharToMultiByte(CP_ACP, 0, wret[i], -1, NULL, 0, NULL, NULL);
588 if(size)
590 ret[i] = HeapAlloc(GetProcessHeap(), 0, size);
591 WideCharToMultiByte(CP_ACP, 0, wret[i], -1, ret[i], size, NULL, NULL);
592 HeapFree(GetProcessHeap(), 0, wret[i]);
595 ret[len] = NULL;
598 HeapFree(GetProcessHeap(), 0, wpath);
599 HeapFree(GetProcessHeap(), 0, wret);
601 return ret;
605 * returns true if the given key/value pair exists in the registry or
606 * has been written to.
608 BOOL reg_key_exists(HKEY root, const char *path, const char *name)
610 char *val = get_reg_key(root, path, name, NULL);
612 if (val)
614 HeapFree(GetProcessHeap(), 0, val);
615 return TRUE;
618 return FALSE;
621 static void process_setting(struct setting *s)
623 static const WCHAR softwareW[] = {'S','o','f','t','w','a','r','e','\\'};
624 HKEY key;
625 BOOL needs_wow64 = (is_win64 && s->root == HKEY_LOCAL_MACHINE && s->path &&
626 !strncmpiW( s->path, softwareW, sizeof(softwareW)/sizeof(WCHAR) ));
628 if (s->value)
630 WINE_TRACE("Setting %s:%s to '%s'\n", wine_dbgstr_w(s->path),
631 wine_dbgstr_w(s->name), wine_dbgstr_w(s->value));
632 set_config_key(s->root, s->path, MAXIMUM_ALLOWED, s->name, s->value, s->type);
633 if (needs_wow64)
635 WINE_TRACE("Setting 32-bit %s:%s to '%s'\n", wine_dbgstr_w(s->path),
636 wine_dbgstr_w(s->name), wine_dbgstr_w(s->value));
637 set_config_key(s->root, s->path, MAXIMUM_ALLOWED | KEY_WOW64_32KEY, s->name, s->value, s->type);
640 else
642 WINE_TRACE("Removing %s:%s\n", wine_dbgstr_w(s->path), wine_dbgstr_w(s->name));
643 if (!RegOpenKeyExW( s->root, s->path, 0, MAXIMUM_ALLOWED, &key ))
645 /* NULL name means remove that path/section entirely */
646 if (s->name) RegDeleteValueW( key, s->name );
647 else
649 RegDeleteTreeW( key, NULL );
650 RegDeleteKeyW( s->root, s->path );
652 RegCloseKey( key );
654 if (needs_wow64)
656 WINE_TRACE("Removing 32-bit %s:%s\n", wine_dbgstr_w(s->path), wine_dbgstr_w(s->name));
657 if (!RegOpenKeyExW( s->root, s->path, 0, MAXIMUM_ALLOWED | KEY_WOW64_32KEY, &key ))
659 if (s->name) RegDeleteValueW( key, s->name );
660 else
662 RegDeleteTreeW( key, NULL );
663 RegDeleteKeyExW( s->root, s->path, KEY_WOW64_32KEY, 0 );
665 RegCloseKey( key );
671 void apply(void)
673 if (list_empty(&settings)) return; /* we will be called for each page when the user clicks OK */
675 WINE_TRACE("()\n");
677 while (!list_empty(&settings))
679 struct setting *s = (struct setting *) list_head(&settings);
680 process_setting(s);
681 free_setting(s);
685 /* ================================== utility functions ============================ */
687 WCHAR* current_app = NULL; /* the app we are currently editing, or NULL if editing global */
689 /* returns a registry key path suitable for passing to addTransaction */
690 char *keypath(const char *section)
692 static char *result = NULL;
694 HeapFree(GetProcessHeap(), 0, result);
696 if (current_app)
698 result = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + lstrlenW(current_app)*2 + 2 /* \\ */ + strlen(section) + 1 /* terminator */);
699 wsprintfA(result, "AppDefaults\\%ls", current_app);
700 if (section[0]) sprintf( result + strlen(result), "\\%s", section );
702 else
704 result = strdupA(section);
707 return result;
710 WCHAR *keypathW(const WCHAR *section)
712 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
713 static WCHAR *result = NULL;
715 HeapFree(GetProcessHeap(), 0, result);
717 if (current_app)
719 DWORD len = sizeof(appdefaultsW) + (lstrlenW(current_app) + lstrlenW(section) + 1) * sizeof(WCHAR);
720 result = HeapAlloc(GetProcessHeap(), 0, len );
721 lstrcpyW( result, appdefaultsW );
722 lstrcatW( result, current_app );
723 if (section[0])
725 len = lstrlenW(result);
726 result[len++] = '\\';
727 lstrcpyW( result + len, section );
730 else
732 result = strdupW(section);
735 return result;
738 void PRINTERROR(void)
740 LPSTR msg;
742 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
743 0, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
744 (LPSTR)&msg, 0, NULL);
746 /* eliminate trailing newline, is this a Wine bug? */
747 *(strrchr(msg, '\r')) = '\0';
749 WINE_TRACE("error: '%s'\n", msg);
752 BOOL initialize(HINSTANCE hInstance)
754 DWORD res = RegCreateKeyA(HKEY_CURRENT_USER, WINE_KEY_ROOT, &config_key);
756 if (res != ERROR_SUCCESS) {
757 WINE_ERR("RegOpenKey failed on wine config key (%d)\n", res);
758 return TRUE;
761 return FALSE;