Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Delta Between Two Patch Sets: PC/winreg.c

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « PC/pyconfig.h ('k') | pyconfig.h.in » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 winreg.c 2 winreg.c
3 3
4 Windows Registry access module for Python. 4 Windows Registry access module for Python.
5 5
6 * Simple registry access written by Mark Hammond in win32api 6 * Simple registry access written by Mark Hammond in win32api
7 module circa 1995. 7 module circa 1995.
8 * Bill Tutt expanded the support significantly not long after. 8 * Bill Tutt expanded the support significantly not long after.
9 * Numerous other people have submitted patches since then. 9 * Numerous other people have submitted patches since then.
10 * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and 10 * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and
11 basic Unicode support added. 11 basic Unicode support added.
12 12
13 */ 13 */
14 14
15 #include "Python.h" 15 #include "Python.h"
16 #include "structmember.h" 16 #include "structmember.h"
17 #include "windows.h" 17 #include "windows.h"
18 #ifndef REG_LEGAL_CHANGE_FILTER 18
19 #define REG_LEGAL_CHANGE_FILTER \ 19 #if defined(__MINGW32__)
20 REG_NOTIFY_CHANGE_NAME | \ 20 _CRTIMP size_t __cdecl __MINGW_NOTHROW _mbstrlen(const char *s);
21 REG_NOTIFY_CHANGE_ATTRIBUTES | \ 21 #endif
22 REG_NOTIFY_CHANGE_LAST_SET | \ 22
23 REG_NOTIFY_CHANGE_SECURITY 23 #if !defined(REG_LEGAL_CHANGE_FILTER)
24 #define REG_LEGAL_CHANGE_FILTER \
25 (REG_NOTIFY_CHANGE_NAME |\
26 REG_NOTIFY_CHANGE_ATTRIBUTES |\
27 REG_NOTIFY_CHANGE_LAST_SET |\
28 REG_NOTIFY_CHANGE_SECURITY)
24 #endif 29 #endif
25 30
26 static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); 31 static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK);
27 static PyObject *PyHKEY_FromHKEY(HKEY h); 32 static PyObject *PyHKEY_FromHKEY(HKEY h);
28 static BOOL PyHKEY_Close(PyObject *obHandle); 33 static BOOL PyHKEY_Close(PyObject *obHandle);
29 34
30 static char errNotAHandle[] = "Object is not a handle"; 35 static char errNotAHandle[] = "Object is not a handle";
31 36
32 /* The win32api module reports the function name that failed, 37 /* The win32api module reports the function name that failed,
33 but this concept is not in the Python core. 38 but this concept is not in the Python core.
(...skipping 16 matching lines...) Expand all
50 " on another computer.\n" 55 " on another computer.\n"
51 "CreateKey() - Creates the specified key, or opens it if it already exists.\n" 56 "CreateKey() - Creates the specified key, or opens it if it already exists.\n"
52 "DeleteKey() - Deletes the specified key.\n" 57 "DeleteKey() - Deletes the specified key.\n"
53 "DeleteValue() - Removes a named value from the specified registry key.\n" 58 "DeleteValue() - Removes a named value from the specified registry key.\n"
54 "EnumKey() - Enumerates subkeys of the specified open registry key.\n" 59 "EnumKey() - Enumerates subkeys of the specified open registry key.\n"
55 "EnumValue() - Enumerates values of the specified open registry key.\n" 60 "EnumValue() - Enumerates values of the specified open registry key.\n"
56 "ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ string.\ n" 61 "ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ string.\ n"
57 "FlushKey() - Writes all the attributes of the specified key to the registry.\n" 62 "FlushKey() - Writes all the attributes of the specified key to the registry.\n"
58 "LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n " 63 "LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n "
59 " registration information from a specified file into that subkey.\n" 64 " registration information from a specified file into that subkey.\n"
60 "OpenKey() - Alias for <om win32api.RegOpenKeyEx>\n" 65 "OpenKey() - Opens the specified key.\n"
61 "OpenKeyEx() - Opens the specified key.\n" 66 "OpenKeyEx() - Alias of OpenKey().\n"
62 "QueryValue() - Retrieves the value associated with the unnamed value for a\n" 67 "QueryValue() - Retrieves the value associated with the unnamed value for a\n"
63 " specified key in the registry.\n" 68 " specified key in the registry.\n"
64 "QueryValueEx() - Retrieves the type and data for a specified value name\n" 69 "QueryValueEx() - Retrieves the type and data for a specified value name\n"
65 " associated with an open registry key.\n" 70 " associated with an open registry key.\n"
66 "QueryInfoKey() - Returns information about the specified key.\n" 71 "QueryInfoKey() - Returns information about the specified key.\n"
67 "SaveKey() - Saves the specified key, and all its subkeys a file.\n" 72 "SaveKey() - Saves the specified key, and all its subkeys a file.\n"
68 "SetValue() - Associates a value with a specified key.\n" 73 "SetValue() - Associates a value with a specified key.\n"
69 "SetValueEx() - Stores data in the value field of an open registry key.\n" 74 "SetValueEx() - Stores data in the value field of an open registry key.\n"
70 "\n" 75 "\n"
71 "Special objects:\n" 76 "Special objects:\n"
72 "\n" 77 "\n"
73 "HKEYType -- type object for HKEY objects\n" 78 "HKEYType -- type object for HKEY objects\n"
74 "error -- exception raised for Win32 errors\n" 79 "error -- exception raised for Win32 errors\n"
75 "\n" 80 "\n"
76 "Integer constants:\n" 81 "Integer constants:\n"
77 "Many constants are defined - see the documentation for each function\n" 82 "Many constants are defined - see the documentation for each function\n"
78 "to see what constants are used, and where."); 83 "to see what constants are used, and where.");
79 84
80 85
81 PyDoc_STRVAR(CloseKey_doc, 86 PyDoc_STRVAR(CloseKey_doc,
82 "CloseKey(hkey) - Closes a previously opened registry key.\n" 87 "CloseKey(hkey)\n"
88 "Closes a previously opened registry key.\n"
83 "\n" 89 "\n"
84 "The hkey argument specifies a previously opened key.\n" 90 "The hkey argument specifies a previously opened key.\n"
85 "\n" 91 "\n"
86 "Note that if the key is not closed using this method, it will be\n" 92 "Note that if the key is not closed using this method, it will be\n"
87 "closed when the hkey object is destroyed by Python."); 93 "closed when the hkey object is destroyed by Python.");
88 94
89 PyDoc_STRVAR(ConnectRegistry_doc, 95 PyDoc_STRVAR(ConnectRegistry_doc,
90 "key = ConnectRegistry(computer_name, key) - " 96 "ConnectRegistry(computer_name, key) -> key\n"
91 "Establishes a connection to a predefined registry handle on another computer.\n " 97 "Establishes a connection to a predefined registry handle on another computer.\n "
92 "\n" 98 "\n"
93 "computer_name is the name of the remote computer, of the form \\\\computername. \n" 99 "computer_name is the name of the remote computer, of the form \\\\computername. \n"
94 " If None, the local computer is used.\n" 100 " If None, the local computer is used.\n"
95 "key is the predefined handle to connect to.\n" 101 "key is the predefined handle to connect to.\n"
96 "\n" 102 "\n"
97 "The return value is the handle of the opened key.\n" 103 "The return value is the handle of the opened key.\n"
98 "If the function fails, a WindowsError exception is raised."); 104 "If the function fails, an OSError exception is raised.");
99 105
100 PyDoc_STRVAR(CreateKey_doc, 106 PyDoc_STRVAR(CreateKey_doc,
101 "key = CreateKey(key, sub_key) - Creates or opens the specified key.\n" 107 "CreateKey(key, sub_key) -> key\n"
108 "Creates or opens the specified key.\n"
109 "\n"
110 "key is an already open key, or one of the predefined HKEY_* constants.\n"
111 "sub_key is a string that names the key this method opens or creates.\n"
112 "\n"
113 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
114 "the handle returned is the same key handle passed in to the function.\n"
115 "\n"
116 "If the key already exists, this function opens the existing key.\n"
117 "\n"
118 "The return value is the handle of the opened key.\n"
119 "If the function fails, an OSError exception is raised.");
120
121 PyDoc_STRVAR(CreateKeyEx_doc,
122 "CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE) -> key\n"
123 "Creates or opens the specified key.\n"
102 "\n" 124 "\n"
103 "key is an already open key, or one of the predefined HKEY_* constants\n" 125 "key is an already open key, or one of the predefined HKEY_* constants\n"
104 "sub_key is a string that names the key this method opens or creates.\n" 126 "sub_key is a string that names the key this method opens or creates.\n"
105 " If key is one of the predefined keys, sub_key may be None. In that case,\n" 127 "reserved is a reserved integer, and must be zero. Default is zero.\n"
106 " the handle returned is the same key handle passed in to the function.\n" 128 "access is an integer that specifies an access mask that describes the \n"
129 " desired security access for the key. Default is KEY_WRITE.\n"
130 "\n"
131 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
132 "the handle returned is the same key handle passed in to the function.\n"
107 "\n" 133 "\n"
108 "If the key already exists, this function opens the existing key\n" 134 "If the key already exists, this function opens the existing key\n"
109 "\n" 135 "\n"
110 "The return value is the handle of the opened key.\n" 136 "The return value is the handle of the opened key.\n"
111 "If the function fails, an exception is raised."); 137 "If the function fails, an OSError exception is raised.");
112
113 PyDoc_STRVAR(CreateKeyEx_doc,
114 "key = CreateKeyEx(key, sub_key, res, sam) - Creates or opens the specified key. \n"
115 "\n"
116 "key is an already open key, or one of the predefined HKEY_* constants\n"
117 "sub_key is a string that names the key this method opens or creates.\n"
118 "res is a reserved integer, and must be zero. Default is zero.\n"
119 "sam is an integer that specifies an access mask that describes the desired\n"
120 " If key is one of the predefined keys, sub_key may be None. In that case,\n"
121 " the handle returned is the same key handle passed in to the function.\n"
122 "\n"
123 "If the key already exists, this function opens the existing key\n"
124 "\n"
125 "The return value is the handle of the opened key.\n"
126 "If the function fails, an exception is raised.");
127 138
128 PyDoc_STRVAR(DeleteKey_doc, 139 PyDoc_STRVAR(DeleteKey_doc,
129 "DeleteKey(key, sub_key) - Deletes the specified key.\n" 140 "DeleteKey(key, sub_key)\n"
141 "Deletes the specified key.\n"
130 "\n" 142 "\n"
131 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 143 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
132 "sub_key is a string that must be a subkey of the key identified by the key para meter.\n" 144 "sub_key is a string that must be a subkey of the key identified by the key\n"
133 " This value must not be None, and the key may not have subkeys.\n" 145 " parameter. This value must not be None, and the key may not have\n"
146 " subkeys.\n"
134 "\n" 147 "\n"
135 "This method can not delete keys with subkeys.\n" 148 "This method can not delete keys with subkeys.\n"
136 "\n" 149 "\n"
137 "If the method succeeds, the entire key, including all of its values,\n" 150 "If the function succeeds, the entire key, including all of its values,\n"
138 "is removed. If the method fails, a WindowsError exception is raised."); 151 "is removed. If the function fails, an OSError exception is raised.");
139 152
140 PyDoc_STRVAR(DeleteKeyEx_doc, 153 PyDoc_STRVAR(DeleteKeyEx_doc,
141 "DeleteKeyEx(key, sub_key, sam, res) - Deletes the specified key.\n" 154 "DeleteKeyEx(key, sub_key, access=KEY_WOW64_64KEY, reserved=0)\n"
155 "Deletes the specified key (64-bit OS only).\n"
142 "\n" 156 "\n"
143 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 157 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
144 "sub_key is a string that must be a subkey of the key identified by the key para meter.\n" 158 "sub_key is a string that must be a subkey of the key identified by the key\n"
145 "res is a reserved integer, and must be zero. Default is zero.\n" 159 " parameter. This value must not be None, and the key may not have\n"
146 "sam is an integer that specifies an access mask that describes the desired\n" 160 " subkeys.\n"
147 " This value must not be None, and the key may not have subkeys.\n" 161 "reserved is a reserved integer, and must be zero. Default is zero.\n"
162 "access is an integer that specifies an access mask that describes the \n"
163 " desired security access for the key. Default is KEY_WOW64_64KEY.\n"
148 "\n" 164 "\n"
149 "This method can not delete keys with subkeys.\n" 165 "This method can not delete keys with subkeys.\n"
150 "\n" 166 "\n"
151 "If the method succeeds, the entire key, including all of its values,\n" 167 "If the function succeeds, the entire key, including all of its values,\n"
152 "is removed. If the method fails, a WindowsError exception is raised.\n" 168 "is removed. If the function fails, an OSError exception is raised.\n"
153 "On unsupported Windows versions, NotImplementedError is raised."); 169 "On unsupported Windows versions, NotImplementedError is raised.");
154 170
155 PyDoc_STRVAR(DeleteValue_doc, 171 PyDoc_STRVAR(DeleteValue_doc,
156 "DeleteValue(key, value) - Removes a named value from a registry key.\n" 172 "DeleteValue(key, value)\n"
173 "Removes a named value from a registry key.\n"
157 "\n" 174 "\n"
158 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 175 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
159 "value is a string that identifies the value to remove."); 176 "value is a string that identifies the value to remove.");
160 177
161 PyDoc_STRVAR(EnumKey_doc, 178 PyDoc_STRVAR(EnumKey_doc,
162 "string = EnumKey(key, index) - Enumerates subkeys of an open registry key.\n" 179 "EnumKey(key, index) -> string\n"
180 "Enumerates subkeys of an open registry key.\n"
163 "\n" 181 "\n"
164 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 182 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
165 "index is an integer that identifies the index of the key to retrieve.\n" 183 "index is an integer that identifies the index of the key to retrieve.\n"
166 "\n" 184 "\n"
167 "The function retrieves the name of one subkey each time it is called.\n" 185 "The function retrieves the name of one subkey each time it is called.\n"
168 "It is typically called repeatedly until a WindowsError exception is\n" 186 "It is typically called repeatedly until an OSError exception is\n"
169 "raised, indicating no more values are available."); 187 "raised, indicating no more values are available.");
170 188
171 PyDoc_STRVAR(EnumValue_doc, 189 PyDoc_STRVAR(EnumValue_doc,
172 "tuple = EnumValue(key, index) - Enumerates values of an open registry key.\n" 190 "EnumValue(key, index) -> tuple\n"
191 "Enumerates values of an open registry key.\n"
173 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 192 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
174 "index is an integer that identifies the index of the value to retrieve.\n" 193 "index is an integer that identifies the index of the value to retrieve.\n"
175 "\n" 194 "\n"
176 "The function retrieves the name of one subkey each time it is called.\n" 195 "The function retrieves the name of one subkey each time it is called.\n"
177 "It is typically called repeatedly, until a WindowsError exception\n" 196 "It is typically called repeatedly, until an OSError exception\n"
178 "is raised, indicating no more values.\n" 197 "is raised, indicating no more values.\n"
179 "\n" 198 "\n"
180 "The result is a tuple of 3 items:\n" 199 "The result is a tuple of 3 items:\n"
181 "value_name is a string that identifies the value.\n" 200 "value_name is a string that identifies the value.\n"
182 "value_data is an object that holds the value data, and whose type depends\n" 201 "value_data is an object that holds the value data, and whose type depends\n"
183 " on the underlying registry type.\n" 202 " on the underlying registry type.\n"
184 "data_type is an integer that identifies the type of the value data."); 203 "data_type is an integer that identifies the type of the value data.");
185 204
186 PyDoc_STRVAR(ExpandEnvironmentStrings_doc, 205 PyDoc_STRVAR(ExpandEnvironmentStrings_doc,
187 "string = ExpandEnvironmentStrings(string) - Expand environment vars.\n"); 206 "ExpandEnvironmentStrings(string) -> string\n"
207 "Expand environment vars.\n");
188 208
189 PyDoc_STRVAR(FlushKey_doc, 209 PyDoc_STRVAR(FlushKey_doc,
190 "FlushKey(key) - Writes all the attributes of a key to the registry.\n" 210 "FlushKey(key)\n"
211 "Writes all the attributes of a key to the registry.\n"
191 "\n" 212 "\n"
192 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 213 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
193 "\n" 214 "\n"
194 "It is not necessary to call RegFlushKey to change a key.\n" 215 "It is not necessary to call FlushKey to change a key. Registry changes are\n"
195 "Registry changes are flushed to disk by the registry using its lazy flusher.\n" 216 "flushed to disk by the registry using its lazy flusher. Registry changes are\n "
196 "Registry changes are also flushed to disk at system shutdown.\n" 217 "also flushed to disk at system shutdown. Unlike CloseKey(), the FlushKey()\n"
197 "Unlike CloseKey(), the FlushKey() method returns only when all the data has\n" 218 "method returns only when all the data has been written to the registry.\n"
198 "been written to the registry.\n" 219 "\n"
199 "An application should only call FlushKey() if it requires absolute certainty th at registry changes are on disk.\n" 220 "An application should only call FlushKey() if it requires absolute certainty\n"
200 "If you don't know whether a FlushKey() call is required, it probably isn't."); 221 "that registry changes are on disk. If you don't know whether a FlushKey()\n"
222 "call is required, it probably isn't.");
201 223
202 PyDoc_STRVAR(LoadKey_doc, 224 PyDoc_STRVAR(LoadKey_doc,
203 "LoadKey(key, sub_key, file_name) - Creates a subkey under the specified key\n" 225 "LoadKey(key, sub_key, file_name)\n"
204 "and stores registration information from a specified file into that subkey.\n" 226 "Creates a subkey under the specified key and stores registration information\n"
227 "from a specified file into that subkey.\n"
205 "\n" 228 "\n"
206 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 229 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
207 "sub_key is a string that identifies the sub_key to load\n" 230 "sub_key is a string that identifies the sub_key to load.\n"
208 "file_name is the name of the file to load registry data from.\n" 231 "file_name is the name of the file to load registry data from. This file must\n "
209 " This file must have been created with the SaveKey() function.\n" 232 " have been created with the SaveKey() function. Under the file\n"
210 " Under the file allocation table (FAT) file system, the filename may not\n" 233 " allocation table (FAT) file system, the filename may not have an\n"
211 "have an extension.\n" 234 " extension.\n"
212 "\n" 235 "\n"
213 "A call to LoadKey() fails if the calling process does not have the\n" 236 "A call to LoadKey() fails if the calling process does not have the\n"
214 "SE_RESTORE_PRIVILEGE privilege.\n" 237 "SE_RESTORE_PRIVILEGE privilege.\n"
215 "\n" 238 "\n"
216 "If key is a handle returned by ConnectRegistry(), then the path specified\n" 239 "If key is a handle returned by ConnectRegistry(), then the path specified\n"
217 "in fileName is relative to the remote computer.\n" 240 "in fileName is relative to the remote computer.\n"
218 "\n" 241 "\n"
219 "The docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE tree"); 242 "The docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE tree");
220 243
221 PyDoc_STRVAR(OpenKey_doc, 244 PyDoc_STRVAR(OpenKey_doc,
222 "key = OpenKey(key, sub_key, res = 0, sam = KEY_READ) - Opens the specified key. \n" 245 "OpenKey(key, sub_key, reserved=0, access=KEY_READ) -> key\n"
246 "Opens the specified key.\n"
223 "\n" 247 "\n"
224 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 248 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
225 "sub_key is a string that identifies the sub_key to open\n" 249 "sub_key is a string that identifies the sub_key to open.\n"
226 "res is a reserved integer, and must be zero. Default is zero.\n" 250 "reserved is a reserved integer, and must be zero. Default is zero.\n"
227 "sam is an integer that specifies an access mask that describes the desired\n" 251 "access is an integer that specifies an access mask that describes the desired\n "
228 " security access for the key. Default is KEY_READ\n" 252 " security access for the key. Default is KEY_READ\n"
229 "\n" 253 "\n"
230 "The result is a new handle to the specified key\n" 254 "The result is a new handle to the specified key\n"
231 "If the function fails, a WindowsError exception is raised."); 255 "If the function fails, an OSError exception is raised.");
232 256
233 PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()"); 257 PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()");
234 258
235 PyDoc_STRVAR(QueryInfoKey_doc, 259 PyDoc_STRVAR(QueryInfoKey_doc,
236 "tuple = QueryInfoKey(key) - Returns information about a key.\n" 260 "QueryInfoKey(key) -> tuple\n"
261 "Returns information about a key.\n"
237 "\n" 262 "\n"
238 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 263 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
239 "\n" 264 "\n"
240 "The result is a tuple of 3 items:" 265 "The result is a tuple of 3 items:"
241 "An integer that identifies the number of sub keys this key has.\n" 266 "An integer that identifies the number of sub keys this key has.\n"
242 "An integer that identifies the number of values this key has.\n" 267 "An integer that identifies the number of values this key has.\n"
243 "A long integer that identifies when the key was last modified (if available)\n" 268 "A long integer that identifies when the key was last modified (if available)\n"
244 " as 100's of nanoseconds since Jan 1, 1600."); 269 " as 100's of nanoseconds since Jan 1, 1600.");
245 270
246 PyDoc_STRVAR(QueryValue_doc, 271 PyDoc_STRVAR(QueryValue_doc,
247 "string = QueryValue(key, sub_key) - retrieves the unnamed value for a key.\n" 272 "QueryValue(key, sub_key) -> string\n"
273 "Retrieves the unnamed value for a key.\n"
248 "\n" 274 "\n"
249 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 275 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
250 "sub_key is a string that holds the name of the subkey with which the value\n" 276 "sub_key is a string that holds the name of the subkey with which the value\n"
251 " is associated. If this parameter is None or empty, the function retrieves\n" 277 " is associated. If this parameter is None or empty, the function\n"
252 " the value set by the SetValue() method for the key identified by key." 278 " retrieves the value set by the SetValue() method for the key\n"
279 " identified by key."
253 "\n" 280 "\n"
254 "Values in the registry have name, type, and data components. This method\n" 281 "Values in the registry have name, type, and data components. This method\n"
255 "retrieves the data for a key's first value that has a NULL name.\n" 282 "retrieves the data for a key's first value that has a NULL name.\n"
256 "But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE T HIS!!!"); 283 "But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE T HIS!!!");
257 284
258 PyDoc_STRVAR(QueryValueEx_doc, 285 PyDoc_STRVAR(QueryValueEx_doc,
259 "value,type_id = QueryValueEx(key, value_name) - Retrieves the type and data for a specified value name associated with an open registry key.\n" 286 "QueryValueEx(key, value_name) -> (value, type_id)\n"
287 "Retrieves the type and data for a specified value name associated with an\n"
288 "open registry key.\n"
260 "\n" 289 "\n"
261 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 290 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
262 "value_name is a string indicating the value to query"); 291 "value_name is a string indicating the value to query");
263 292
264 PyDoc_STRVAR(SaveKey_doc, 293 PyDoc_STRVAR(SaveKey_doc,
265 "SaveKey(key, file_name) - Saves the specified key, and all its subkeys to the s pecified file.\n" 294 "SaveKey(key, file_name)\n"
295 "Saves the specified key, and all its subkeys to the specified file.\n"
266 "\n" 296 "\n"
267 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 297 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
268 "file_name is the name of the file to save registry data to.\n" 298 "file_name is the name of the file to save registry data to. This file cannot\n "
269 " This file cannot already exist. If this filename includes an extension,\n" 299 " already exist. If this filename includes an extension, it cannot be\n "
270 " it cannot be used on file allocation table (FAT) file systems by the\n" 300 " used on file allocation table (FAT) file systems by the LoadKey(),\n"
271 " LoadKey(), ReplaceKey() or RestoreKey() methods.\n" 301 " ReplaceKey() or RestoreKey() methods.\n"
272 "\n" 302 "\n"
273 "If key represents a key on a remote computer, the path described by\n" 303 "If key represents a key on a remote computer, the path described by file_name\n "
274 "file_name is relative to the remote computer.\n" 304 "is relative to the remote computer.\n"
275 "The caller of this method must possess the SeBackupPrivilege security privilege .\n" 305 "\n"
276 "This function passes NULL for security_attributes to the API."); 306 "The caller of this method must possess the SeBackupPrivilege security\n"
307 "privilege. This function passes NULL for security_attributes to the API.");
277 308
278 PyDoc_STRVAR(SetValue_doc, 309 PyDoc_STRVAR(SetValue_doc,
279 "SetValue(key, sub_key, type, value) - Associates a value with a specified key.\ n" 310 "SetValue(key, sub_key, type, value)\n"
311 "Associates a value with a specified key.\n"
280 "\n" 312 "\n"
281 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 313 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
282 "sub_key is a string that names the subkey with which the value is associated.\n " 314 "sub_key is a string that names the subkey with which the value is associated.\n "
283 "type is an integer that specifies the type of the data. Currently this\n" 315 "type is an integer that specifies the type of the data. Currently this must\n"
284 " must be REG_SZ, meaning only strings are supported.\n" 316 " be REG_SZ, meaning only strings are supported.\n"
285 "value is a string that specifies the new value.\n" 317 "value is a string that specifies the new value.\n"
286 "\n" 318 "\n"
287 "If the key specified by the sub_key parameter does not exist, the SetValue\n" 319 "If the key specified by the sub_key parameter does not exist, the SetValue\n"
288 "function creates it.\n" 320 "function creates it.\n"
289 "\n" 321 "\n"
290 "Value lengths are limited by available memory. Long values (more than\n" 322 "Value lengths are limited by available memory. Long values (more than\n"
291 "2048 bytes) should be stored as files with the filenames stored in \n" 323 "2048 bytes) should be stored as files with the filenames stored in \n"
292 "the configuration registry. This helps the registry perform efficiently.\n" 324 "the configuration registry. This helps the registry perform efficiently.\n"
293 "\n" 325 "\n"
294 "The key identified by the key parameter must have been opened with\n" 326 "The key identified by the key parameter must have been opened with\n"
295 "KEY_SET_VALUE access."); 327 "KEY_SET_VALUE access.");
296 328
297 PyDoc_STRVAR(SetValueEx_doc, 329 PyDoc_STRVAR(SetValueEx_doc,
298 "SetValueEx(key, value_name, reserved, type, value) - Stores data in the value f ield of an open registry key.\n" 330 "SetValueEx(key, value_name, reserved, type, value)\n"
331 "Stores data in the value field of an open registry key.\n"
299 "\n" 332 "\n"
300 "key is an already open key, or any one of the predefined HKEY_* constants.\n" 333 "key is an already open key, or any one of the predefined HKEY_* constants.\n"
301 "value_name is a string containing the name of the value to set, or None\n" 334 "value_name is a string containing the name of the value to set, or None.\n"
335 "reserved can be anything - zero is always passed to the API.\n"
302 "type is an integer that specifies the type of the data. This should be one of: \n" 336 "type is an integer that specifies the type of the data. This should be one of: \n"
303 " REG_BINARY -- Binary data in any form.\n" 337 " REG_BINARY -- Binary data in any form.\n"
304 " REG_DWORD -- A 32-bit number.\n" 338 " REG_DWORD -- A 32-bit number.\n"
305 " REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n" 339 " REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n"
306 " REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n" 340 " REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
307 " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references \n" 341 " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references \n"
308 " to environment variables (for example, %PATH%).\n" 342 " to environment variables (for example, %PATH%).\n"
309 " REG_LINK -- A Unicode symbolic link.\n" 343 " REG_LINK -- A Unicode symbolic link.\n"
310 " REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n" 344 " REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n"
311 " two null characters. Note that Python handles this\n" 345 " two null characters. Note that Python handles this\n"
312 " termination automatically.\n" 346 " termination automatically.\n"
313 " REG_NONE -- No defined value type.\n" 347 " REG_NONE -- No defined value type.\n"
314 " REG_RESOURCE_LIST -- A device-driver resource list.\n" 348 " REG_RESOURCE_LIST -- A device-driver resource list.\n"
315 " REG_SZ -- A null-terminated string.\n" 349 " REG_SZ -- A null-terminated string.\n"
316 "reserved can be anything - zero is always passed to the API.\n"
317 "value is a string that specifies the new value.\n" 350 "value is a string that specifies the new value.\n"
318 "\n" 351 "\n"
319 "This method can also set additional value and type information for the\n" 352 "This method can also set additional value and type information for the\n"
320 "specified key. The key identified by the key parameter must have been\n" 353 "specified key. The key identified by the key parameter must have been\n"
321 "opened with KEY_SET_VALUE access.\n" 354 "opened with KEY_SET_VALUE access.\n"
322 "\n" 355 "\n"
323 "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n" 356 "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
324 "\n" 357 "\n"
325 "Value lengths are limited by available memory. Long values (more than\n" 358 "Value lengths are limited by available memory. Long values (more than\n"
326 "2048 bytes) should be stored as files with the filenames stored in \n" 359 "2048 bytes) should be stored as files with the filenames stored in \n"
327 "the configuration registry. This helps the registry perform efficiently."); 360 "the configuration registry. This helps the registry perform efficiently.");
328 361
329 PyDoc_STRVAR(DisableReflectionKey_doc, 362 PyDoc_STRVAR(DisableReflectionKey_doc,
330 "Disables registry reflection for 32-bit processes running on a 64-bit\n" 363 "Disables registry reflection for 32-bit processes running on a 64-bit\n"
331 "Operating System. Will generally raise NotImplemented if executed on\n" 364 "Operating System. Will generally raise NotImplemented if executed on\n"
332 "a 32-bit Operating System.\n" 365 "a 32-bit Operating System.\n"
366 "\n"
333 "If the key is not on the reflection list, the function succeeds but has no effe ct.\n" 367 "If the key is not on the reflection list, the function succeeds but has no effe ct.\n"
334 "Disabling reflection for a key does not affect reflection of any subkeys."); 368 "Disabling reflection for a key does not affect reflection of any subkeys.");
335 369
336 PyDoc_STRVAR(EnableReflectionKey_doc, 370 PyDoc_STRVAR(EnableReflectionKey_doc,
337 "Restores registry reflection for the specified disabled key.\n" 371 "Restores registry reflection for the specified disabled key.\n"
338 "Will generally raise NotImplemented if executed on a 32-bit Operating System.\n " 372 "Will generally raise NotImplemented if executed on a 32-bit Operating System.\n "
339 "Restoring reflection for a key does not affect reflection of any subkeys."); 373 "Restoring reflection for a key does not affect reflection of any subkeys.");
340 374
341 PyDoc_STRVAR(QueryReflectionKey_doc, 375 PyDoc_STRVAR(QueryReflectionKey_doc,
342 "bool = QueryReflectionKey(hkey) - Determines the reflection state for the speci fied key.\n" 376 "QueryReflectionKey(hkey) -> bool\n"
377 "Determines the reflection state for the specified key.\n"
343 "Will generally raise NotImplemented if executed on a 32-bit Operating System.\n "); 378 "Will generally raise NotImplemented if executed on a 32-bit Operating System.\n ");
344 379
345 /* PyHKEY docstrings */ 380 /* PyHKEY docstrings */
346 PyDoc_STRVAR(PyHKEY_doc, 381 PyDoc_STRVAR(PyHKEY_doc,
347 "PyHKEY Object - A Python object, representing a win32 registry key.\n" 382 "PyHKEY Object - A Python object, representing a win32 registry key.\n"
348 "\n" 383 "\n"
349 "This object wraps a Windows HKEY object, automatically closing it when\n" 384 "This object wraps a Windows HKEY object, automatically closing it when\n"
350 "the object is destroyed. To guarantee cleanup, you can call either\n" 385 "the object is destroyed. To guarantee cleanup, you can call either\n"
351 "the Close() method on the PyHKEY, or the CloseKey() method.\n" 386 "the Close() method on the PyHKEY, or the CloseKey() method.\n"
352 "\n" 387 "\n"
353 "All functions which accept a handle object also accept an integer - \n" 388 "All functions which accept a handle object also accept an integer - \n"
354 "however, use of the handle object is encouraged.\n" 389 "however, use of the handle object is encouraged.\n"
355 "\n" 390 "\n"
356 "Functions:\n" 391 "Functions:\n"
357 "Close() - Closes the underlying handle.\n" 392 "Close() - Closes the underlying handle.\n"
358 "Detach() - Returns the integer Win32 handle, detaching it from the object\n" 393 "Detach() - Returns the integer Win32 handle, detaching it from the object\n"
359 "\n" 394 "\n"
360 "Properties:\n" 395 "Properties:\n"
361 "handle - The integer Win32 handle.\n" 396 "handle - The integer Win32 handle.\n"
362 "\n" 397 "\n"
363 "Operations:\n" 398 "Operations:\n"
364 "__bool__ - Handles with an open object return true, otherwise false.\n" 399 "__bool__ - Handles with an open object return true, otherwise false.\n"
365 "__int__ - Converting a handle to an integer returns the Win32 handle.\n" 400 "__int__ - Converting a handle to an integer returns the Win32 handle.\n"
366 "rich comparison - Handle objects are compared using the handle value."); 401 "rich comparison - Handle objects are compared using the handle value.");
367 402
368 403
369 PyDoc_STRVAR(PyHKEY_Close_doc, 404 PyDoc_STRVAR(PyHKEY_Close_doc,
370 "key.Close() - Closes the underlying Windows handle.\n" 405 "key.Close()\n"
406 "Closes the underlying Windows handle.\n"
371 "\n" 407 "\n"
372 "If the handle is already closed, no error is raised."); 408 "If the handle is already closed, no error is raised.");
373 409
374 PyDoc_STRVAR(PyHKEY_Detach_doc, 410 PyDoc_STRVAR(PyHKEY_Detach_doc,
375 "int = key.Detach() - Detaches the Windows handle from the handle object.\n" 411 "key.Detach() -> int\n"
412 "Detaches the Windows handle from the handle object.\n"
376 "\n" 413 "\n"
377 "The result is the value of the handle before it is detached. If the\n" 414 "The result is the value of the handle before it is detached. If the\n"
378 "handle is already detached, this will return zero.\n" 415 "handle is already detached, this will return zero.\n"
379 "\n" 416 "\n"
380 "After calling this function, the handle is effectively invalidated,\n" 417 "After calling this function, the handle is effectively invalidated,\n"
381 "but the handle is not closed. You would call this function when you\n" 418 "but the handle is not closed. You would call this function when you\n"
382 "need the underlying win32 handle to exist beyond the lifetime of the\n" 419 "need the underlying win32 handle to exist beyond the lifetime of the\n"
383 "handle object.\n" 420 "handle object.\n"
384 "On 64 bit windows, the result of this function is a long integer"); 421 "On 64 bit windows, the result of this function is a long integer");
385 422
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 489
453 static int 490 static int
454 PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2) 491 PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2)
455 { 492 {
456 PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1; 493 PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
457 PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2; 494 PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
458 return pyhkey1 == pyhkey2 ? 0 : 495 return pyhkey1 == pyhkey2 ? 0 :
459 (pyhkey1 < pyhkey2 ? -1 : 1); 496 (pyhkey1 < pyhkey2 ? -1 : 1);
460 } 497 }
461 498
462 static long 499 static Py_hash_t
463 PyHKEY_hashFunc(PyObject *ob) 500 PyHKEY_hashFunc(PyObject *ob)
464 { 501 {
465 /* Just use the address. 502 /* Just use the address.
466 XXX - should we use the handle value? 503 XXX - should we use the handle value?
467 */ 504 */
468 return _Py_HashPointer(ob); 505 return _Py_HashPointer(ob);
469 } 506 }
470 507
471 508
472 static PyNumberMethods PyHKEY_NumberMethods = 509 static PyNumberMethods PyHKEY_NumberMethods =
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (*retDataBuf==NULL){ 790 if (*retDataBuf==NULL){
754 PyErr_NoMemory(); 791 PyErr_NoMemory();
755 return FALSE; 792 return FALSE;
756 } 793 }
757 *retDataSize = sizeof(DWORD); 794 *retDataSize = sizeof(DWORD);
758 if (value == Py_None) { 795 if (value == Py_None) {
759 DWORD zero = 0; 796 DWORD zero = 0;
760 memcpy(*retDataBuf, &zero, sizeof(DWORD)); 797 memcpy(*retDataBuf, &zero, sizeof(DWORD));
761 } 798 }
762 else { 799 else {
763 DWORD d = PyLong_AsLong(value); 800 DWORD d = PyLong_AsUnsignedLong(value);
764 memcpy(*retDataBuf, &d, sizeof(DWORD)); 801 memcpy(*retDataBuf, &d, sizeof(DWORD));
765 } 802 }
766 break; 803 break;
767 case REG_SZ: 804 case REG_SZ:
768 case REG_EXPAND_SZ: 805 case REG_EXPAND_SZ:
769 { 806 {
770 if (value == Py_None) 807 if (value != Py_None) {
771 *retDataSize = 1; 808 Py_ssize_t len;
772 else { 809 if (!PyUnicode_Check(value))
773 if (!PyUnicode_Check(value)) 810 return FALSE;
774 return FALSE; 811 *retDataBuf = (BYTE*)PyUnicode_AsWideCharString(value, &len) ;
775 812 if (*retDataBuf == NULL)
776 *retDataSize = 2 + PyUnicode_GET_DATA_SIZE(value); 813 return FALSE;
777 } 814 *retDataSize = Py_SAFE_DOWNCAST(
778 *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize); 815 (len + 1) * sizeof(wchar_t),
779 if (*retDataBuf==NULL){ 816 Py_ssize_t, DWORD);
780 PyErr_NoMemory(); 817 }
781 return FALSE; 818 else {
782 } 819 *retDataBuf = (BYTE *)PyMem_NEW(wchar_t, 1);
783 if (value == Py_None) 820 if (*retDataBuf == NULL) {
784 wcscpy((wchar_t *)*retDataBuf, L""); 821 PyErr_NoMemory();
785 else 822 return FALSE;
786 wcscpy((wchar_t *)*retDataBuf, 823 }
787 PyUnicode_AS_UNICODE(value)); 824 ((wchar_t *)*retDataBuf)[0] = L'\0';
788 break; 825 *retDataSize = 1 * sizeof(wchar_t);
826 }
827 break;
789 } 828 }
790 case REG_MULTI_SZ: 829 case REG_MULTI_SZ:
791 { 830 {
792 DWORD size = 0; 831 DWORD size = 0;
793 wchar_t *P; 832 wchar_t *P;
794 833
795 if (value == Py_None) 834 if (value == Py_None)
796 i = 0; 835 i = 0;
797 else { 836 else {
798 if (!PyList_Check(value)) 837 if (!PyList_Check(value))
799 return FALSE; 838 return FALSE;
800 i = PyList_Size(value); 839 i = PyList_Size(value);
801 } 840 }
802 for (j = 0; j < i; j++) 841 for (j = 0; j < i; j++)
803 { 842 {
804 PyObject *t; 843 PyObject *t;
844 wchar_t *wstr;
845 Py_ssize_t len;
846
805 t = PyList_GET_ITEM(value, j); 847 t = PyList_GET_ITEM(value, j);
806 if (!PyUnicode_Check(t)) 848 if (!PyUnicode_Check(t))
807 return FALSE; 849 return FALSE;
808 size += 2 + PyUnicode_GET_DATA_SIZE(t); 850 wstr = PyUnicode_AsUnicodeAndSize(t, &len);
851 if (wstr == NULL)
852 return FALSE;
853 size += Py_SAFE_DOWNCAST((len + 1) * sizeof(wchar_t),
854 size_t, DWORD);
809 } 855 }
810 856
811 *retDataSize = size + 2; 857 *retDataSize = size + 2;
812 *retDataBuf = (BYTE *)PyMem_NEW(char, 858 *retDataBuf = (BYTE *)PyMem_NEW(char,
813 *retDataSize); 859 *retDataSize);
814 if (*retDataBuf==NULL){ 860 if (*retDataBuf==NULL){
815 PyErr_NoMemory(); 861 PyErr_NoMemory();
816 return FALSE; 862 return FALSE;
817 } 863 }
818 P = (wchar_t *)*retDataBuf; 864 P = (wchar_t *)*retDataBuf;
819 865
820 for (j = 0; j < i; j++) 866 for (j = 0; j < i; j++)
821 { 867 {
822 PyObject *t; 868 PyObject *t;
869 wchar_t *wstr;
870 Py_ssize_t len;
871
823 t = PyList_GET_ITEM(value, j); 872 t = PyList_GET_ITEM(value, j);
824 wcscpy(P, PyUnicode_AS_UNICODE(t)); 873 wstr = PyUnicode_AsUnicodeAndSize(t, &len);
825 P += 1 + wcslen( 874 if (wstr == NULL)
826 PyUnicode_AS_UNICODE(t)); 875 return FALSE;
876 wcscpy(P, wstr);
877 P += (len + 1);
827 } 878 }
828 /* And doubly-terminate the list... */ 879 /* And doubly-terminate the list... */
829 *P = '\0'; 880 *P = '\0';
830 break; 881 break;
831 } 882 }
832 case REG_BINARY: 883 case REG_BINARY:
833 /* ALSO handle ALL unknown data types here. Even if we can't 884 /* ALSO handle ALL unknown data types here. Even if we can't
834 support it natively, we should handle the bits. */ 885 support it natively, we should handle the bits. */
835 default: 886 default:
836 if (value == Py_None) 887 if (value == Py_None)
(...skipping 11 matching lines...) Expand all
848 899
849 if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0) 900 if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
850 return FALSE; 901 return FALSE;
851 902
852 *retDataBuf = (BYTE *)PyMem_NEW(char, view.len); 903 *retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
853 if (*retDataBuf==NULL){ 904 if (*retDataBuf==NULL){
854 PyBuffer_Release(&view); 905 PyBuffer_Release(&view);
855 PyErr_NoMemory(); 906 PyErr_NoMemory();
856 return FALSE; 907 return FALSE;
857 } 908 }
858 *retDataSize = view.len; 909 *retDataSize = Py_SAFE_DOWNCAST(view.len, Py_ssize_t, DWORD);
859 memcpy(*retDataBuf, view.buf, view.len); 910 memcpy(*retDataBuf, view.buf, view.len);
860 PyBuffer_Release(&view); 911 PyBuffer_Release(&view);
861 } 912 }
862 break; 913 break;
863 } 914 }
864 return TRUE; 915 return TRUE;
865 } 916 }
866 917
867 /* Convert Registry data into PyObject*/ 918 /* Convert Registry data into PyObject*/
868 static PyObject * 919 static PyObject *
869 Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ) 920 Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
870 { 921 {
871 PyObject *obData; 922 PyObject *obData;
872 923
873 switch (typ) { 924 switch (typ) {
874 case REG_DWORD: 925 case REG_DWORD:
875 if (retDataSize == 0) 926 if (retDataSize == 0)
876 obData = PyLong_FromLong(0); 927 obData = PyLong_FromUnsignedLong(0);
877 else 928 else
878 obData = PyLong_FromLong(*(int *)retDataBuf); 929 obData = PyLong_FromUnsignedLong(*(int *)retDataBuf);
879 break; 930 break;
880 case REG_SZ: 931 case REG_SZ:
881 case REG_EXPAND_SZ: 932 case REG_EXPAND_SZ:
882 { 933 {
883 /* the buffer may or may not have a trailing NULL */ 934 /* the buffer may or may not have a trailing NULL */
884 wchar_t *data = (wchar_t *)retDataBuf; 935 wchar_t *data = (wchar_t *)retDataBuf;
885 int len = retDataSize / 2; 936 int len = retDataSize / 2;
886 if (retDataSize && data[len-1] == '\0') 937 if (retDataSize && data[len-1] == '\0')
887 retDataSize -= 2; 938 retDataSize -= 2;
888 if (retDataSize <= 0) 939 if (retDataSize <= 0)
889 data = L""; 940 data = L"";
890 obData = PyUnicode_FromUnicode(data, retDataSize/2); 941 obData = PyUnicode_FromWideChar(data, retDataSize/2);
891 break; 942 break;
892 } 943 }
893 case REG_MULTI_SZ: 944 case REG_MULTI_SZ:
894 if (retDataSize == 0) 945 if (retDataSize == 0)
895 obData = PyList_New(0); 946 obData = PyList_New(0);
896 else 947 else
897 { 948 {
898 int index = 0; 949 int index = 0;
899 wchar_t *data = (wchar_t *)retDataBuf; 950 wchar_t *data = (wchar_t *)retDataBuf;
900 int len = retDataSize / 2; 951 int len = retDataSize / 2;
(...skipping 10 matching lines...) Expand all
911 { 962 {
912 size_t len = wcslen(str[index]); 963 size_t len = wcslen(str[index]);
913 if (len > INT_MAX) { 964 if (len > INT_MAX) {
914 PyErr_SetString(PyExc_OverflowError, 965 PyErr_SetString(PyExc_OverflowError,
915 "registry string is too long for a Python string"); 966 "registry string is too long for a Python string");
916 Py_DECREF(obData); 967 Py_DECREF(obData);
917 return NULL; 968 return NULL;
918 } 969 }
919 PyList_SetItem(obData, 970 PyList_SetItem(obData,
920 index, 971 index,
921 PyUnicode_FromUnicode(str[index], len)); 972 PyUnicode_FromWideChar(str[index], len));
922 } 973 }
923 free(str); 974 free(str);
924 975
925 break; 976 break;
926 } 977 }
927 case REG_BINARY: 978 case REG_BINARY:
928 /* ALSO handle ALL unknown data types here. Even if we can't 979 /* ALSO handle ALL unknown data types here. Even if we can't
929 support it natively, we should handle the bits. */ 980 support it natively, we should handle the bits. */
930 default: 981 default:
931 if (retDataSize == 0) { 982 if (retDataSize == 0) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 return NULL; 1038 return NULL;
988 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1039 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
989 return NULL; 1040 return NULL;
990 rc = RegCreateKeyW(hKey, subKey, &retKey); 1041 rc = RegCreateKeyW(hKey, subKey, &retKey);
991 if (rc != ERROR_SUCCESS) 1042 if (rc != ERROR_SUCCESS)
992 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); 1043 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
993 return PyHKEY_FromHKEY(retKey); 1044 return PyHKEY_FromHKEY(retKey);
994 } 1045 }
995 1046
996 static PyObject * 1047 static PyObject *
997 PyCreateKeyEx(PyObject *self, PyObject *args) 1048 PyCreateKeyEx(PyObject *self, PyObject *args, PyObject *kwargs)
998 { 1049 {
999 HKEY hKey; 1050 HKEY hKey;
1000 PyObject *obKey; 1051 PyObject *key;
1001 wchar_t *subKey; 1052 wchar_t *sub_key;
1002 HKEY retKey; 1053 HKEY retKey;
1003 int res = 0; 1054 int reserved = 0;
1004 REGSAM sam = KEY_WRITE; 1055 REGSAM access = KEY_WRITE;
1005 long rc; 1056 long rc;
1006 if (!PyArg_ParseTuple(args, "OZ|ii:CreateKeyEx", &obKey, &subKey, 1057
1007 &res, &sam)) 1058 char *kwlist[] = {"key", "sub_key", "reserved", "access", NULL};
1008 return NULL; 1059
1009 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1060 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OZ|ii:CreateKeyEx", kwlist,
1010 return NULL; 1061 &key, &sub_key, &reserved, &access))
1011 1062 return NULL;
1012 rc = RegCreateKeyExW(hKey, subKey, res, NULL, (DWORD)NULL, 1063 if (!PyHKEY_AsHKEY(key, &hKey, FALSE))
1013 sam, NULL, &retKey, NULL); 1064 return NULL;
1065
1066 rc = RegCreateKeyExW(hKey, sub_key, reserved, NULL, (DWORD)NULL,
1067 access, NULL, &retKey, NULL);
1014 if (rc != ERROR_SUCCESS) 1068 if (rc != ERROR_SUCCESS)
1015 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx"); 1069 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
1016 return PyHKEY_FromHKEY(retKey); 1070 return PyHKEY_FromHKEY(retKey);
1017 } 1071 }
1018 1072
1019 static PyObject * 1073 static PyObject *
1020 PyDeleteKey(PyObject *self, PyObject *args) 1074 PyDeleteKey(PyObject *self, PyObject *args)
1021 { 1075 {
1022 HKEY hKey; 1076 HKEY hKey;
1023 PyObject *obKey; 1077 PyObject *obKey;
1024 wchar_t *subKey; 1078 wchar_t *subKey;
1025 long rc; 1079 long rc;
1026 if (!PyArg_ParseTuple(args, "Ou:DeleteKey", &obKey, &subKey)) 1080 if (!PyArg_ParseTuple(args, "Ou:DeleteKey", &obKey, &subKey))
1027 return NULL; 1081 return NULL;
1028 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1082 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1029 return NULL; 1083 return NULL;
1030 rc = RegDeleteKeyW(hKey, subKey ); 1084 rc = RegDeleteKeyW(hKey, subKey );
1031 if (rc != ERROR_SUCCESS) 1085 if (rc != ERROR_SUCCESS)
1032 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); 1086 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
1033 Py_INCREF(Py_None); 1087 Py_INCREF(Py_None);
1034 return Py_None; 1088 return Py_None;
1035 } 1089 }
1036 1090
1037 static PyObject * 1091 static PyObject *
1038 PyDeleteKeyEx(PyObject *self, PyObject *args) 1092 PyDeleteKeyEx(PyObject *self, PyObject *args, PyObject *kwargs)
1039 { 1093 {
1094 #ifndef KEY_WOW64_64KEY
1095 /* KEY_WOW64_64KEY is defined for _WIN32_WINNT >= 0x0502,
1096 i.e. Windows Server 2003 with SP1, Windows XP with SP2
1097 and not supported on w2k
1098 */
1099 PyErr_SetString(PyExc_NotImplementedError,
1100 "not implemented on this platform");
1101 return NULL;
1102 #else /*def KEY_WOW64_64KEY*/
1040 HKEY hKey; 1103 HKEY hKey;
1041 PyObject *obKey; 1104 PyObject *key;
1042 HMODULE hMod; 1105 HMODULE hMod;
1043 typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int); 1106 typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int);
1044 RDKEFunc pfn = NULL; 1107 RDKEFunc pfn = NULL;
1045 wchar_t *subKey; 1108 wchar_t *sub_key;
1046 long rc; 1109 long rc;
1047 int res = 0; 1110 int reserved = 0;
1048 REGSAM sam = KEY_WOW64_64KEY; 1111 REGSAM access = KEY_WOW64_64KEY;
1049 1112
1050 if (!PyArg_ParseTuple(args, "Ou|ii:DeleteKeyEx", 1113 char *kwlist[] = {"key", "sub_key", "access", "reserved", NULL};
1051 &obKey, &subKey, &sam, &res)) 1114 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ou|ii:DeleteKeyEx", kwlist,
1052 return NULL; 1115 &key, &sub_key, &access, &reserved))
1053 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1116 return NULL;
1117 if (!PyHKEY_AsHKEY(key, &hKey, FALSE))
1054 return NULL; 1118 return NULL;
1055 1119
1056 /* Only available on 64bit platforms, so we must load it 1120 /* Only available on 64bit platforms, so we must load it
1057 dynamically. */ 1121 dynamically. */
1058 hMod = GetModuleHandle("advapi32.dll"); 1122 hMod = GetModuleHandleW(L"advapi32.dll");
1059 if (hMod) 1123 if (hMod)
1060 pfn = (RDKEFunc)GetProcAddress(hMod, 1124 pfn = (RDKEFunc)GetProcAddress(hMod,
1061 "RegDeleteKey ExW"); 1125 "RegDeleteKey ExW");
1062 if (!pfn) { 1126 if (!pfn) {
1063 PyErr_SetString(PyExc_NotImplementedError, 1127 PyErr_SetString(PyExc_NotImplementedError,
1064 "not implemented on this platform"); 1128 "not implemented on this platform");
1065 return NULL; 1129 return NULL;
1066 } 1130 }
1067 Py_BEGIN_ALLOW_THREADS 1131 Py_BEGIN_ALLOW_THREADS
1068 rc = (*pfn)(hKey, subKey, sam, res); 1132 rc = (*pfn)(hKey, sub_key, access, reserved);
1069 Py_END_ALLOW_THREADS 1133 Py_END_ALLOW_THREADS
1070 1134
1071 if (rc != ERROR_SUCCESS) 1135 if (rc != ERROR_SUCCESS)
1072 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx"); 1136 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
1073 Py_INCREF(Py_None); 1137 Py_INCREF(Py_None);
1074 return Py_None; 1138 return Py_None;
1139 #endif
1075 } 1140 }
1076 1141
1077 static PyObject * 1142 static PyObject *
1078 PyDeleteValue(PyObject *self, PyObject *args) 1143 PyDeleteValue(PyObject *self, PyObject *args)
1079 { 1144 {
1080 HKEY hKey; 1145 HKEY hKey;
1081 PyObject *obKey; 1146 PyObject *obKey;
1082 wchar_t *subKey; 1147 wchar_t *subKey;
1083 long rc; 1148 long rc;
1084 if (!PyArg_ParseTuple(args, "OZ:DeleteValue", &obKey, &subKey)) 1149 if (!PyArg_ParseTuple(args, "OZ:DeleteValue", &obKey, &subKey))
(...skipping 19 matching lines...) Expand all
1104 long rc; 1169 long rc;
1105 PyObject *retStr; 1170 PyObject *retStr;
1106 1171
1107 /* The Windows docs claim that the max key name length is 255 1172 /* The Windows docs claim that the max key name length is 255
1108 * characters, plus a terminating nul character. However, 1173 * characters, plus a terminating nul character. However,
1109 * empirical testing demonstrates that it is possible to 1174 * empirical testing demonstrates that it is possible to
1110 * create a 256 character key that is missing the terminating 1175 * create a 256 character key that is missing the terminating
1111 * nul. RegEnumKeyEx requires a 257 character buffer to 1176 * nul. RegEnumKeyEx requires a 257 character buffer to
1112 * retrieve such a key name. */ 1177 * retrieve such a key name. */
1113 wchar_t tmpbuf[257]; 1178 wchar_t tmpbuf[257];
1114 DWORD len = sizeof(tmpbuf); /* includes NULL terminator */ 1179 DWORD len = sizeof(tmpbuf)/sizeof(wchar_t); /* includes NULL terminator */
1115 1180
1116 if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) 1181 if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
1117 return NULL; 1182 return NULL;
1118 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1183 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1119 return NULL; 1184 return NULL;
1120 1185
1121 Py_BEGIN_ALLOW_THREADS 1186 Py_BEGIN_ALLOW_THREADS
1122 rc = RegEnumKeyExW(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL); 1187 rc = RegEnumKeyExW(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
1123 Py_END_ALLOW_THREADS 1188 Py_END_ALLOW_THREADS
1124 if (rc != ERROR_SUCCESS) 1189 if (rc != ERROR_SUCCESS)
1125 return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx"); 1190 return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
1126 1191
1127 retStr = PyUnicode_FromUnicode(tmpbuf, len); 1192 retStr = PyUnicode_FromWideChar(tmpbuf, len);
1128 return retStr; /* can be NULL */ 1193 return retStr; /* can be NULL */
1129 } 1194 }
1130 1195
1131 static PyObject * 1196 static PyObject *
1132 PyEnumValue(PyObject *self, PyObject *args) 1197 PyEnumValue(PyObject *self, PyObject *args)
1133 { 1198 {
1134 HKEY hKey; 1199 HKEY hKey;
1135 PyObject *obKey; 1200 PyObject *obKey;
1136 int index; 1201 int index;
1137 long rc; 1202 long rc;
1138 wchar_t *retValueBuf; 1203 wchar_t *retValueBuf;
1139 wchar_t *tmpBuf; 1204 BYTE *tmpBuf;
1140 BYTE *retDataBuf; 1205 BYTE *retDataBuf;
1141 DWORD retValueSize, bufValueSize; 1206 DWORD retValueSize, bufValueSize;
1142 DWORD retDataSize, bufDataSize; 1207 DWORD retDataSize, bufDataSize;
1143 DWORD typ; 1208 DWORD typ;
1144 PyObject *obData; 1209 PyObject *obData;
1145 PyObject *retVal; 1210 PyObject *retVal;
1146 1211
1147 if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) 1212 if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index))
1148 return NULL; 1213 return NULL;
1149 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1214 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
(...skipping 27 matching lines...) Expand all
1177 NULL, 1242 NULL,
1178 &typ, 1243 &typ,
1179 (BYTE *)retDataBuf, 1244 (BYTE *)retDataBuf,
1180 &retDataSize); 1245 &retDataSize);
1181 Py_END_ALLOW_THREADS 1246 Py_END_ALLOW_THREADS
1182 1247
1183 if (rc != ERROR_MORE_DATA) 1248 if (rc != ERROR_MORE_DATA)
1184 break; 1249 break;
1185 1250
1186 bufDataSize *= 2; 1251 bufDataSize *= 2;
1187 tmpBuf = (wchar_t *)PyMem_Realloc(retDataBuf, bufDataSize); 1252 tmpBuf = (BYTE *)PyMem_Realloc(retDataBuf, bufDataSize);
1188 if (tmpBuf == NULL) { 1253 if (tmpBuf == NULL) {
1189 PyErr_NoMemory(); 1254 PyErr_NoMemory();
1190 retVal = NULL; 1255 retVal = NULL;
1191 goto fail; 1256 goto fail;
1192 } 1257 }
1193 retDataBuf = tmpBuf; 1258 retDataBuf = tmpBuf;
1194 retDataSize = bufDataSize; 1259 retDataSize = bufDataSize;
1195 retValueSize = bufValueSize; 1260 retValueSize = bufValueSize;
1196 } 1261 }
1197 1262
(...skipping 11 matching lines...) Expand all
1209 Py_DECREF(obData); 1274 Py_DECREF(obData);
1210 fail: 1275 fail:
1211 PyMem_Free(retValueBuf); 1276 PyMem_Free(retValueBuf);
1212 PyMem_Free(retDataBuf); 1277 PyMem_Free(retDataBuf);
1213 return retVal; 1278 return retVal;
1214 } 1279 }
1215 1280
1216 static PyObject * 1281 static PyObject *
1217 PyExpandEnvironmentStrings(PyObject *self, PyObject *args) 1282 PyExpandEnvironmentStrings(PyObject *self, PyObject *args)
1218 { 1283 {
1219 Py_UNICODE *retValue = NULL; 1284 wchar_t *retValue = NULL;
1220 Py_UNICODE *src; 1285 wchar_t *src;
1221 DWORD retValueSize; 1286 DWORD retValueSize;
1222 DWORD rc; 1287 DWORD rc;
1223 PyObject *o; 1288 PyObject *o;
1224 1289
1225 if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src)) 1290 if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src))
1226 return NULL; 1291 return NULL;
1227 1292
1228 retValueSize = ExpandEnvironmentStringsW(src, retValue, 0); 1293 retValueSize = ExpandEnvironmentStringsW(src, retValue, 0);
1229 if (retValueSize == 0) { 1294 if (retValueSize == 0) {
1230 return PyErr_SetFromWindowsErrWithFunction(retValueSize, 1295 return PyErr_SetFromWindowsErrWithFunction(retValueSize,
1231 "ExpandEnvironmentStrings"); 1296 "ExpandEnvironmentStrings");
1232 } 1297 }
1233 retValue = (Py_UNICODE *)PyMem_Malloc(retValueSize * sizeof(Py_UNICODE)); 1298 retValue = (wchar_t *)PyMem_Malloc(retValueSize * sizeof(wchar_t));
1234 if (retValue == NULL) { 1299 if (retValue == NULL) {
1235 return PyErr_NoMemory(); 1300 return PyErr_NoMemory();
1236 } 1301 }
1237 1302
1238 rc = ExpandEnvironmentStringsW(src, retValue, retValueSize); 1303 rc = ExpandEnvironmentStringsW(src, retValue, retValueSize);
1239 if (rc == 0) { 1304 if (rc == 0) {
1240 PyMem_Free(retValue); 1305 PyMem_Free(retValue);
1241 return PyErr_SetFromWindowsErrWithFunction(retValueSize, 1306 return PyErr_SetFromWindowsErrWithFunction(retValueSize,
1242 "ExpandEnvironmentStrings"); 1307 "ExpandEnvironmentStrings");
1243 } 1308 }
1244 o = PyUnicode_FromUnicode(retValue, wcslen(retValue)); 1309 o = PyUnicode_FromWideChar(retValue, wcslen(retValue));
1245 PyMem_Free(retValue); 1310 PyMem_Free(retValue);
1246 return o; 1311 return o;
1247 } 1312 }
1248 1313
1249 static PyObject * 1314 static PyObject *
1250 PyFlushKey(PyObject *self, PyObject *args) 1315 PyFlushKey(PyObject *self, PyObject *args)
1251 { 1316 {
1252 HKEY hKey; 1317 HKEY hKey;
1253 PyObject *obKey; 1318 PyObject *obKey;
1254 long rc; 1319 long rc;
(...skipping 25 matching lines...) Expand all
1280 Py_BEGIN_ALLOW_THREADS 1345 Py_BEGIN_ALLOW_THREADS
1281 rc = RegLoadKeyW(hKey, subKey, fileName ); 1346 rc = RegLoadKeyW(hKey, subKey, fileName );
1282 Py_END_ALLOW_THREADS 1347 Py_END_ALLOW_THREADS
1283 if (rc != ERROR_SUCCESS) 1348 if (rc != ERROR_SUCCESS)
1284 return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); 1349 return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey");
1285 Py_INCREF(Py_None); 1350 Py_INCREF(Py_None);
1286 return Py_None; 1351 return Py_None;
1287 } 1352 }
1288 1353
1289 static PyObject * 1354 static PyObject *
1290 PyOpenKey(PyObject *self, PyObject *args) 1355 PyOpenKey(PyObject *self, PyObject *args, PyObject *kwargs)
1291 { 1356 {
1292 HKEY hKey; 1357 HKEY hKey;
1293 PyObject *obKey; 1358 PyObject *key;
1294 1359 wchar_t *sub_key;
1295 wchar_t *subKey; 1360 int reserved = 0;
1296 int res = 0;
1297 HKEY retKey; 1361 HKEY retKey;
1298 long rc; 1362 long rc;
1299 REGSAM sam = KEY_READ; 1363 REGSAM access = KEY_READ;
1300 if (!PyArg_ParseTuple(args, "OZ|ii:OpenKey", &obKey, &subKey, 1364
1301 &res, &sam)) 1365 char *kwlist[] = {"key", "sub_key", "reserved", "access", NULL};
1302 return NULL; 1366
1303 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1367 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OZ|ii:OpenKey", kwlist,
1368 &key, &sub_key, &reserved, &access))
1369 return NULL;
1370 if (!PyHKEY_AsHKEY(key, &hKey, FALSE))
1304 return NULL; 1371 return NULL;
1305 1372
1306 Py_BEGIN_ALLOW_THREADS 1373 Py_BEGIN_ALLOW_THREADS
1307 rc = RegOpenKeyExW(hKey, subKey, res, sam, &retKey); 1374 rc = RegOpenKeyExW(hKey, sub_key, reserved, access, &retKey);
1308 Py_END_ALLOW_THREADS 1375 Py_END_ALLOW_THREADS
1309 if (rc != ERROR_SUCCESS) 1376 if (rc != ERROR_SUCCESS)
1310 return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); 1377 return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
1311 return PyHKEY_FromHKEY(retKey); 1378 return PyHKEY_FromHKEY(retKey);
1312 } 1379 }
1313 1380
1314 1381
1315 static PyObject * 1382 static PyObject *
1316 PyQueryInfoKey(PyObject *self, PyObject *args) 1383 PyQueryInfoKey(PyObject *self, PyObject *args)
1317 { 1384 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 } 1453 }
1387 retBuf = tmp; 1454 retBuf = tmp;
1388 } 1455 }
1389 1456
1390 if (rc != ERROR_SUCCESS) { 1457 if (rc != ERROR_SUCCESS) {
1391 PyMem_Free(retBuf); 1458 PyMem_Free(retBuf);
1392 return PyErr_SetFromWindowsErrWithFunction(rc, 1459 return PyErr_SetFromWindowsErrWithFunction(rc,
1393 "RegQueryValue"); 1460 "RegQueryValue");
1394 } 1461 }
1395 1462
1396 retStr = PyUnicode_FromUnicode(retBuf, wcslen(retBuf)); 1463 retStr = PyUnicode_FromWideChar(retBuf, wcslen(retBuf));
1397 PyMem_Free(retBuf); 1464 PyMem_Free(retBuf);
1398 return retStr; 1465 return retStr;
1399 } 1466 }
1400 1467
1401 static PyObject * 1468 static PyObject *
1402 PyQueryValueEx(PyObject *self, PyObject *args) 1469 PyQueryValueEx(PyObject *self, PyObject *args)
1403 { 1470 {
1404 HKEY hKey; 1471 HKEY hKey;
1405 PyObject *obKey; 1472 PyObject *obKey;
1406 wchar_t *valueName; 1473 wchar_t *valueName;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); 1584 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue");
1518 Py_INCREF(Py_None); 1585 Py_INCREF(Py_None);
1519 return Py_None; 1586 return Py_None;
1520 } 1587 }
1521 1588
1522 static PyObject * 1589 static PyObject *
1523 PySetValueEx(PyObject *self, PyObject *args) 1590 PySetValueEx(PyObject *self, PyObject *args)
1524 { 1591 {
1525 HKEY hKey; 1592 HKEY hKey;
1526 PyObject *obKey; 1593 PyObject *obKey;
1527 Py_UNICODE *valueName; 1594 wchar_t *valueName;
1528 PyObject *obRes; 1595 PyObject *obRes;
1529 PyObject *value; 1596 PyObject *value;
1530 BYTE *data; 1597 BYTE *data;
1531 DWORD len; 1598 DWORD len;
1532 DWORD typ; 1599 DWORD typ;
1533 1600
1534 LONG rc; 1601 LONG rc;
1535 1602
1536 if (!PyArg_ParseTuple(args, "OZOiO:SetValueEx", 1603 if (!PyArg_ParseTuple(args, "OZOiO:SetValueEx",
1537 &obKey, 1604 &obKey,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 RDRKFunc pfn = NULL; 1637 RDRKFunc pfn = NULL;
1571 LONG rc; 1638 LONG rc;
1572 1639
1573 if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey)) 1640 if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey))
1574 return NULL; 1641 return NULL;
1575 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1642 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1576 return NULL; 1643 return NULL;
1577 1644
1578 /* Only available on 64bit platforms, so we must load it 1645 /* Only available on 64bit platforms, so we must load it
1579 dynamically.*/ 1646 dynamically.*/
1580 hMod = GetModuleHandle("advapi32.dll"); 1647 hMod = GetModuleHandleW(L"advapi32.dll");
1581 if (hMod) 1648 if (hMod)
1582 pfn = (RDRKFunc)GetProcAddress(hMod, 1649 pfn = (RDRKFunc)GetProcAddress(hMod,
1583 "RegDisableReflectionKey"); 1650 "RegDisableReflectionKey");
1584 if (!pfn) { 1651 if (!pfn) {
1585 PyErr_SetString(PyExc_NotImplementedError, 1652 PyErr_SetString(PyExc_NotImplementedError,
1586 "not implemented on this platform"); 1653 "not implemented on this platform");
1587 return NULL; 1654 return NULL;
1588 } 1655 }
1589 Py_BEGIN_ALLOW_THREADS 1656 Py_BEGIN_ALLOW_THREADS
1590 rc = (*pfn)(hKey); 1657 rc = (*pfn)(hKey);
(...skipping 15 matching lines...) Expand all
1606 RERKFunc pfn = NULL; 1673 RERKFunc pfn = NULL;
1607 LONG rc; 1674 LONG rc;
1608 1675
1609 if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey)) 1676 if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey))
1610 return NULL; 1677 return NULL;
1611 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1678 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1612 return NULL; 1679 return NULL;
1613 1680
1614 /* Only available on 64bit platforms, so we must load it 1681 /* Only available on 64bit platforms, so we must load it
1615 dynamically.*/ 1682 dynamically.*/
1616 hMod = GetModuleHandle("advapi32.dll"); 1683 hMod = GetModuleHandleW(L"advapi32.dll");
1617 if (hMod) 1684 if (hMod)
1618 pfn = (RERKFunc)GetProcAddress(hMod, 1685 pfn = (RERKFunc)GetProcAddress(hMod,
1619 "RegEnableReflectionKey"); 1686 "RegEnableReflectionKey");
1620 if (!pfn) { 1687 if (!pfn) {
1621 PyErr_SetString(PyExc_NotImplementedError, 1688 PyErr_SetString(PyExc_NotImplementedError,
1622 "not implemented on this platform"); 1689 "not implemented on this platform");
1623 return NULL; 1690 return NULL;
1624 } 1691 }
1625 Py_BEGIN_ALLOW_THREADS 1692 Py_BEGIN_ALLOW_THREADS
1626 rc = (*pfn)(hKey); 1693 rc = (*pfn)(hKey);
(...skipping 16 matching lines...) Expand all
1643 BOOL result; 1710 BOOL result;
1644 LONG rc; 1711 LONG rc;
1645 1712
1646 if (!PyArg_ParseTuple(args, "O:QueryReflectionKey", &obKey)) 1713 if (!PyArg_ParseTuple(args, "O:QueryReflectionKey", &obKey))
1647 return NULL; 1714 return NULL;
1648 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) 1715 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1649 return NULL; 1716 return NULL;
1650 1717
1651 /* Only available on 64bit platforms, so we must load it 1718 /* Only available on 64bit platforms, so we must load it
1652 dynamically.*/ 1719 dynamically.*/
1653 hMod = GetModuleHandle("advapi32.dll"); 1720 hMod = GetModuleHandleW(L"advapi32.dll");
1654 if (hMod) 1721 if (hMod)
1655 pfn = (RQRKFunc)GetProcAddress(hMod, 1722 pfn = (RQRKFunc)GetProcAddress(hMod,
1656 "RegQueryReflectionKey"); 1723 "RegQueryReflectionKey");
1657 if (!pfn) { 1724 if (!pfn) {
1658 PyErr_SetString(PyExc_NotImplementedError, 1725 PyErr_SetString(PyExc_NotImplementedError,
1659 "not implemented on this platform"); 1726 "not implemented on this platform");
1660 return NULL; 1727 return NULL;
1661 } 1728 }
1662 Py_BEGIN_ALLOW_THREADS 1729 Py_BEGIN_ALLOW_THREADS
1663 rc = (*pfn)(hKey, &result); 1730 rc = (*pfn)(hKey, &result);
1664 Py_END_ALLOW_THREADS 1731 Py_END_ALLOW_THREADS
1665 if (rc != ERROR_SUCCESS) 1732 if (rc != ERROR_SUCCESS)
1666 return PyErr_SetFromWindowsErrWithFunction(rc, 1733 return PyErr_SetFromWindowsErrWithFunction(rc,
1667 "RegQueryReflectionKey"); 1734 "RegQueryReflectionKey");
1668 return PyBool_FromLong(result); 1735 return PyBool_FromLong(result);
1669 } 1736 }
1670 1737
1671 static struct PyMethodDef winreg_methods[] = { 1738 static struct PyMethodDef winreg_methods[] = {
1672 {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, 1739 {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc},
1673 {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, 1740 {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc},
1674 {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, 1741 {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc},
1675 {"CreateKeyEx", PyCreateKeyEx, METH_VARARGS, CreateKeyEx_doc}, 1742 {"CreateKeyEx", (PyCFunction)PyCreateKeyEx,
1743 METH_VARARGS | METH_KEYWORDS, CreateKeyEx_doc},
1676 {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, 1744 {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc},
1677 {"DeleteKeyEx", PyDeleteKeyEx, METH_VARARGS, DeleteKeyEx_doc}, 1745 {"DeleteKeyEx", (PyCFunction)PyDeleteKeyEx,
1746 METH_VARARGS | METH_KEYWORDS, DeleteKeyEx_doc},
1678 {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, 1747 {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc},
1679 {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflec tionKey_doc}, 1748 {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflec tionKey_doc},
1680 {"EnableReflectionKey", PyEnableReflectionKey, METH_VARARGS, EnableReflect ionKey_doc}, 1749 {"EnableReflectionKey", PyEnableReflectionKey, METH_VARARGS, EnableReflect ionKey_doc},
1681 {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, 1750 {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc},
1682 {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, 1751 {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc},
1683 {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS, 1752 {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS,
1684 ExpandEnvironmentStrings_doc }, 1753 ExpandEnvironmentStrings_doc },
1685 {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc}, 1754 {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc},
1686 {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc}, 1755 {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc},
1687 {"OpenKey", PyOpenKey, METH_VARARGS, OpenKey_doc}, 1756 {"OpenKey", (PyCFunction)PyOpenKey, METH_VARARGS | METH_KEYWORDS,
1688 {"OpenKeyEx", PyOpenKey, METH_VARARGS, OpenKeyEx_doc}, 1757 OpenKey_doc},
1758 {"OpenKeyEx", (PyCFunction)PyOpenKey, METH_VARARGS | METH_KEYWORDS,
1759 OpenKeyEx_doc},
1689 {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc}, 1760 {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc},
1690 {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc}, 1761 {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc},
1691 {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc}, 1762 {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc},
1692 {"QueryReflectionKey",PyQueryReflectionKey,METH_VARARGS, QueryReflectionKey_ doc}, 1763 {"QueryReflectionKey",PyQueryReflectionKey,METH_VARARGS, QueryReflectionKey_ doc},
1693 {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc}, 1764 {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc},
1694 {"SetValue", PySetValue, METH_VARARGS, SetValue_doc}, 1765 {"SetValue", PySetValue, METH_VARARGS, SetValue_doc},
1695 {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc}, 1766 {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc},
1696 NULL, 1767 NULL,
1697 }; 1768 };
1698 1769
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 ADD_INT(REG_DWORD_BIG_ENDIAN); 1875 ADD_INT(REG_DWORD_BIG_ENDIAN);
1805 ADD_INT(REG_LINK); 1876 ADD_INT(REG_LINK);
1806 ADD_INT(REG_MULTI_SZ); 1877 ADD_INT(REG_MULTI_SZ);
1807 ADD_INT(REG_RESOURCE_LIST); 1878 ADD_INT(REG_RESOURCE_LIST);
1808 ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR); 1879 ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
1809 ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); 1880 ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
1810 return m; 1881 return m;
1811 } 1882 }
1812 1883
1813 1884
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+