* registry.cc (reg_key::get_int): Add alternative implementation
taking WCHAR strings. (reg_key::set_int): Ditto. (reg_key::get_string): Ditto. (reg_key::set_string): Ditto. * registry.h (struct reg_key): Add prototypes for added methods.
This commit is contained in:
		| @@ -1,3 +1,12 @@ | |||||||
|  | 2009-10-20  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* registry.cc (reg_key::get_int): Add alternative implementation | ||||||
|  | 	taking WCHAR strings. | ||||||
|  | 	(reg_key::set_int): Ditto. | ||||||
|  | 	(reg_key::get_string): Ditto. | ||||||
|  | 	(reg_key::set_string): Ditto. | ||||||
|  | 	* registry.h (struct reg_key): Add prototypes for added methods. | ||||||
|  |  | ||||||
| 2009-10-20  Corinna Vinschen  <corinna@vinschen.de> | 2009-10-20  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* smallprint.cc (__small_vsprintf): Simplify UNICODE string handling | 	* smallprint.cc (__small_vsprintf): Simplify UNICODE string handling | ||||||
|   | |||||||
| @@ -115,8 +115,25 @@ reg_key::get_int (const char *name, int def) | |||||||
|   if (key_is_invalid) |   if (key_is_invalid) | ||||||
|     return def; |     return def; | ||||||
|  |  | ||||||
|   LONG res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) &dst, |   LONG res = RegQueryValueExA (key, name, 0, &type, (LPBYTE) &dst, &size); | ||||||
| 			       &size); |  | ||||||
|  |   if (type != REG_DWORD || res != ERROR_SUCCESS) | ||||||
|  |     return def; | ||||||
|  |  | ||||||
|  |   return dst; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | reg_key::get_int (const PWCHAR name, int def) | ||||||
|  | { | ||||||
|  |   DWORD type; | ||||||
|  |   DWORD dst; | ||||||
|  |   DWORD size = sizeof (dst); | ||||||
|  |  | ||||||
|  |   if (key_is_invalid) | ||||||
|  |     return def; | ||||||
|  |  | ||||||
|  |   LONG res = RegQueryValueExW (key, name, 0, &type, (LPBYTE) &dst, &size); | ||||||
|  |  | ||||||
|   if (type != REG_DWORD || res != ERROR_SUCCESS) |   if (type != REG_DWORD || res != ERROR_SUCCESS) | ||||||
|     return def; |     return def; | ||||||
| @@ -134,14 +151,25 @@ reg_key::set_int (const char *name, int val) | |||||||
|     return key_is_invalid; |     return key_is_invalid; | ||||||
|  |  | ||||||
|   return (int) RegSetValueExA (key, name, 0, REG_DWORD, |   return (int) RegSetValueExA (key, name, 0, REG_DWORD, | ||||||
| 			       (unsigned char *) &value, sizeof (value)); | 			       (const BYTE *) &value, sizeof (value)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | reg_key::set_int (const PWCHAR name, int val) | ||||||
|  | { | ||||||
|  |   DWORD value = val; | ||||||
|  |   if (key_is_invalid) | ||||||
|  |     return key_is_invalid; | ||||||
|  |  | ||||||
|  |   return (int) RegSetValueExW (key, name, 0, REG_DWORD, | ||||||
|  | 			       (const BYTE *) &value, sizeof (value)); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Given the current registry key, return the specific string value | /* Given the current registry key, return the specific string value | ||||||
|    requested.  Return zero on success, non-zero on failure. */ |    requested.  Return zero on success, non-zero on failure. */ | ||||||
|  |  | ||||||
| int | int | ||||||
| reg_key::get_string (const char *name, char *dst, size_t max, const char * def) | reg_key::get_string (const char *name, char *dst, size_t max, const char *def) | ||||||
| { | { | ||||||
|   DWORD size = max; |   DWORD size = max; | ||||||
|   DWORD type; |   DWORD type; | ||||||
| @@ -150,13 +178,30 @@ reg_key::get_string (const char *name, char *dst, size_t max, const char * def) | |||||||
|   if (key_is_invalid) |   if (key_is_invalid) | ||||||
|     res = key_is_invalid; |     res = key_is_invalid; | ||||||
|   else |   else | ||||||
|     res = RegQueryValueExA (key, name, 0, &type, (unsigned char *) dst, &size); |     res = RegQueryValueExA (key, name, 0, &type, (LPBYTE) dst, &size); | ||||||
|  |  | ||||||
|   if ((def != 0) && ((type != REG_SZ) || (res != ERROR_SUCCESS))) |   if ((def != 0) && ((type != REG_SZ) || (res != ERROR_SUCCESS))) | ||||||
|     strcpy (dst, def); |     strcpy (dst, def); | ||||||
|   return (int) res; |   return (int) res; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | reg_key::get_string (const PWCHAR name, PWCHAR dst, size_t max, const PWCHAR def) | ||||||
|  | { | ||||||
|  |   DWORD size = max; | ||||||
|  |   DWORD type; | ||||||
|  |   LONG res; | ||||||
|  |  | ||||||
|  |   if (key_is_invalid) | ||||||
|  |     res = key_is_invalid; | ||||||
|  |   else | ||||||
|  |     res = RegQueryValueExW (key, name, 0, &type, (LPBYTE) dst, &size); | ||||||
|  |  | ||||||
|  |   if ((def != 0) && ((type != REG_SZ) || (res != ERROR_SUCCESS))) | ||||||
|  |     wcscpy (dst, def); | ||||||
|  |   return (int) res; | ||||||
|  | } | ||||||
|  |  | ||||||
| /* Given the current registry key, set a specific string value. */ | /* Given the current registry key, set a specific string value. */ | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -164,10 +209,19 @@ reg_key::set_string (const char *name, const char *src) | |||||||
| { | { | ||||||
|   if (key_is_invalid) |   if (key_is_invalid) | ||||||
|     return key_is_invalid; |     return key_is_invalid; | ||||||
|   return (int) RegSetValueExA (key, name, 0, REG_SZ, (unsigned char*) src, |   return (int) RegSetValueExA (key, name, 0, REG_SZ, (const BYTE*) src, | ||||||
| 			       strlen (src) + 1); | 			       strlen (src) + 1); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | reg_key::set_string (const PWCHAR name, const PWCHAR src) | ||||||
|  | { | ||||||
|  |   if (key_is_invalid) | ||||||
|  |     return key_is_invalid; | ||||||
|  |   return (int) RegSetValueExW (key, name, 0, REG_SZ, (const BYTE*) src, | ||||||
|  | 			       (wcslen (src) + 1) * sizeof (WCHAR)); | ||||||
|  | } | ||||||
|  |  | ||||||
| /* Return the handle to key. */ | /* Return the handle to key. */ | ||||||
|  |  | ||||||
| HKEY | HKEY | ||||||
|   | |||||||
| @@ -30,10 +30,17 @@ public: | |||||||
|   int killvalue (const char *name); |   int killvalue (const char *name); | ||||||
|  |  | ||||||
|   HKEY get_key (); |   HKEY get_key (); | ||||||
|   int get_int (const char *,int def); |  | ||||||
|   int get_string (const char *, char *buf, size_t len, const char *def); |   int get_int (const char *, int); | ||||||
|   int set_string (const char *,const char *); |   int get_int (const PWCHAR, int); | ||||||
|   int set_int (const char *, int val); |   int get_string (const char *, char *, size_t, const char *); | ||||||
|  |   int get_string (const PWCHAR, PWCHAR, size_t, const PWCHAR); | ||||||
|  |  | ||||||
|  |   int set_int (const char *, int); | ||||||
|  |   int set_int (const PWCHAR, int); | ||||||
|  |   int set_string (const char *, const char *); | ||||||
|  |   int set_string (const PWCHAR, const PWCHAR); | ||||||
|  |  | ||||||
|   bool created () const {return _disposition & REG_CREATED_NEW_KEY;} |   bool created () const {return _disposition & REG_CREATED_NEW_KEY;} | ||||||
|  |  | ||||||
|   ~reg_key (); |   ~reg_key (); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user