Initial revision
[bpt/emacs.git] / src / w32reg.c
CommitLineData
ee78dc32
GV
1/* Emulate the X Resource Manager through the registry.
2 Copyright (C) 1990, 1993, 1994 Free Software Foundation.
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2, or (at your option)
7any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; see the file COPYING. If not, write to
16the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18/* Written by Kevin Gallo */
19
20#include <config.h>
21#include "lisp.h"
22#include "w32term.h"
23#include "blockinput.h"
24
25#include <stdio.h>
26#include <string.h>
27
28#define REG_ROOT "SOFTWARE\\GNU\\Emacs\\"
29
30LPBYTE
31win32_get_string_resource (name, class, dwexptype)
32 char *name, *class;
33 DWORD dwexptype;
34{
35 LPBYTE lpvalue = NULL;
36 HKEY hrootkey = NULL;
37 DWORD dwType;
38 DWORD cbData;
39 BOOL ok = FALSE;
40
41 BLOCK_INPUT;
42
43 /* Check both the current user and the local machine to see if we have any resources */
44
45 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS
46 || RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
47 {
48 char *keyname;
49
50 if (RegQueryValueEx (hrootkey, name, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
51 && dwType == dwexptype)
52 {
53 keyname = name;
54 }
55 else if (RegQueryValueEx (hrootkey, class, NULL, &dwType, NULL, &cbData) == ERROR_SUCCESS
56 && dwType == dwexptype)
57 {
58 keyname = class;
59 }
60 else
61 {
62 keyname = NULL;
63 }
64
65 ok = (keyname
66 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
67 && RegQueryValueEx (hrootkey, keyname, NULL, NULL, lpvalue, &cbData) == ERROR_SUCCESS);
68
69 RegCloseKey (hrootkey);
70 }
71
72 UNBLOCK_INPUT;
73
74 if (!ok)
75 {
76 if (lpvalue) xfree (lpvalue);
77 return (NULL);
78 }
79 else
80 {
81 return (lpvalue);
82 }
83}
84
85/* Retrieve the string resource specified by NAME with CLASS from
86 database RDB. */
87
88char *
89x_get_string_resource (rdb, name, class)
90 int rdb;
91 char *name, *class;
92{
93 return (win32_get_string_resource (name, class, REG_SZ));
94}